[PATCH] D30855: [unittest] Explicitly specify alignment when using BumpPtrAllocator.
Jordan Rose via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 10 17:03:42 PST 2017
jordan_rose created this revision.
https://reviews.llvm.org/rL297310 began inserting red zones around allocations under ASan, which perturbs the alignment of subsequent allocations. Deliberately specify this in two places where it matters.
Fixes failures when these tests are run under ASan and UBSan together.
rdar://problem/30980047
Repository:
rL LLVM
https://reviews.llvm.org/D30855
Files:
unittests/Support/AllocatorTest.cpp
unittests/Support/BinaryStreamTest.cpp
Index: unittests/Support/BinaryStreamTest.cpp
===================================================================
--- unittests/Support/BinaryStreamTest.cpp
+++ unittests/Support/BinaryStreamTest.cpp
@@ -686,7 +686,8 @@
std::vector<Foo> Foos = {{1, 1.0}, {2, 2.0}, {3, 3.0}};
BumpPtrAllocator Allocator;
for (const auto &F : Foos) {
- uint8_t *Ptr = Allocator.Allocate<uint8_t>(sizeof(Foo));
+ uint8_t *Ptr = static_cast<uint8_t *>(Allocator.Allocate(sizeof(Foo),
+ alignof(Foo)));
MutableArrayRef<uint8_t> Buffer(Ptr, sizeof(Foo));
MutableBinaryByteStream Stream(Buffer, llvm::support::big);
BinaryStreamWriter Writer(Stream);
Index: unittests/Support/AllocatorTest.cpp
===================================================================
--- unittests/Support/AllocatorTest.cpp
+++ unittests/Support/AllocatorTest.cpp
@@ -17,9 +17,9 @@
TEST(AllocatorTest, Basics) {
BumpPtrAllocator Alloc;
- int *a = (int*)Alloc.Allocate(sizeof(int), 1);
- int *b = (int*)Alloc.Allocate(sizeof(int) * 10, 1);
- int *c = (int*)Alloc.Allocate(sizeof(int), 1);
+ int *a = (int*)Alloc.Allocate(sizeof(int), alignof(int));
+ int *b = (int*)Alloc.Allocate(sizeof(int) * 10, alignof(int));
+ int *c = (int*)Alloc.Allocate(sizeof(int), alignof(int));
*a = 1;
b[0] = 2;
b[9] = 2;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30855.91438.patch
Type: text/x-patch
Size: 1368 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170311/667a1dba/attachment.bin>
More information about the llvm-commits
mailing list