-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Support] Recycler: Match dealloc size and enforce min size #121889
Merged
optimisan
merged 1 commit into
main
from
users/Akshat-Oke/01-07-_support_recycler_match_dealloc_size_and_enforce_min_size
Jan 9, 2025
Merged
[Support] Recycler: Match dealloc size and enforce min size #121889
optimisan
merged 1 commit into
main
from
users/Akshat-Oke/01-07-_support_recycler_match_dealloc_size_and_enforce_min_size
Jan 9, 2025
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Jan 7, 2025
This stack of pull requests is managed by Graphite. Learn more about stacking. |
arsenm
approved these changes
Jan 7, 2025
@llvm/pr-subscribers-llvm-support Author: Akshat Oke (optimisan) ChangesAddress sanitizer found mismatching deallocation size in Recycler. Full diff: https://github.com/llvm/llvm-project/pull/121889.diff 2 Files Affected:
diff --git a/llvm/include/llvm/Support/Recycler.h b/llvm/include/llvm/Support/Recycler.h
index 693c6559ff2fdc3..e531e235ee78f87 100644
--- a/llvm/include/llvm/Support/Recycler.h
+++ b/llvm/include/llvm/Support/Recycler.h
@@ -72,7 +72,7 @@ class Recycler {
void clear(AllocatorType &Allocator) {
while (FreeList) {
T *t = reinterpret_cast<T *>(pop_val());
- Allocator.Deallocate(t);
+ Allocator.Deallocate(t, Size, Align);
}
}
@@ -89,6 +89,8 @@ class Recycler {
"Recycler allocation alignment is less than object align!");
static_assert(sizeof(SubClass) <= Size,
"Recycler allocation size is less than object size!");
+ static_assert(Size >= sizeof(FreeNode) &&
+ "Recycler allocation size must be at least sizeof(FreeNode)");
return FreeList ? reinterpret_cast<SubClass *>(pop_val())
: static_cast<SubClass *>(Allocator.Allocate(Size, Align));
}
diff --git a/llvm/unittests/Support/RecyclerTest.cpp b/llvm/unittests/Support/RecyclerTest.cpp
index a33506b47ebeae3..696e397d3f10edd 100644
--- a/llvm/unittests/Support/RecyclerTest.cpp
+++ b/llvm/unittests/Support/RecyclerTest.cpp
@@ -14,6 +14,10 @@ using namespace llvm;
namespace {
+struct Object1 {
+ char Data[1];
+};
+
struct Object8 {
char Data[8];
};
@@ -22,12 +26,32 @@ class DecoratedMallocAllocator : public MallocAllocator {
public:
int DeallocCount = 0;
+ void Deallocate(const void *Ptr, size_t Size, size_t Alignment) {
+ DeallocCount++;
+ MallocAllocator::Deallocate(Ptr, Size, Alignment);
+ }
+
template <typename T> void Deallocate(T *Ptr) {
DeallocCount++;
MallocAllocator::Deallocate(Ptr);
}
};
+TEST(RecyclerTest, RecycleAllocation) {
+ DecoratedMallocAllocator Allocator;
+ // Recycler needs size to be atleast 8 bytes.
+ Recycler<Object1, 8, 8> R;
+ Object1 *A1 = R.Allocate(Allocator);
+ Object1 *A2 = R.Allocate(Allocator);
+ R.Deallocate(Allocator, A2);
+ Object1 *A3 = R.Allocate(Allocator);
+ EXPECT_EQ(A2, A3); // reuse the deallocated object.
+ R.Deallocate(Allocator, A1);
+ R.Deallocate(Allocator, A3);
+ R.clear(Allocator); // Should deallocate A1 and A3.
+ EXPECT_EQ(Allocator.DeallocCount, 2);
+}
+
TEST(RecyclerTest, MoveConstructor) {
DecoratedMallocAllocator Allocator;
Recycler<Object8> R;
|
Base automatically changed from
users/Akshat-Oke/12-19-_support_recycler_implement_move_constructor
to
main
January 7, 2025 10:17
optimisan
force-pushed
the
users/Akshat-Oke/01-07-_support_recycler_match_dealloc_size_and_enforce_min_size
branch
from
January 7, 2025 10:22
0f46720
to
03ca3f5
Compare
optimisan
force-pushed
the
users/Akshat-Oke/01-07-_support_recycler_match_dealloc_size_and_enforce_min_size
branch
from
January 8, 2025 05:09
03ca3f5
to
e31e945
Compare
optimisan
deleted the
users/Akshat-Oke/01-07-_support_recycler_match_dealloc_size_and_enforce_min_size
branch
January 9, 2025 08:52
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Address sanitizer found mismatching deallocation size in Recycler.