[llvm] r297540 - [unittest] Explicitly specify alignment when using BumpPtrAllocator.

Jordan Rose via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 10 17:24:56 PST 2017


Author: jrose
Date: Fri Mar 10 19:24:56 2017
New Revision: 297540

URL: http://llvm.org/viewvc/llvm-project?rev=297540&view=rev
Log:
[unittest] Explicitly specify alignment when using BumpPtrAllocator.

r297310 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.
Reviewed by Duncan Exon Smith.

rdar://problem/30980047

Modified:
    llvm/trunk/unittests/Support/AllocatorTest.cpp
    llvm/trunk/unittests/Support/BinaryStreamTest.cpp

Modified: llvm/trunk/unittests/Support/AllocatorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/AllocatorTest.cpp?rev=297540&r1=297539&r2=297540&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/AllocatorTest.cpp (original)
+++ llvm/trunk/unittests/Support/AllocatorTest.cpp Fri Mar 10 19:24:56 2017
@@ -17,9 +17,9 @@ namespace {
 
 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;

Modified: llvm/trunk/unittests/Support/BinaryStreamTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/BinaryStreamTest.cpp?rev=297540&r1=297539&r2=297540&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/BinaryStreamTest.cpp (original)
+++ llvm/trunk/unittests/Support/BinaryStreamTest.cpp Fri Mar 10 19:24:56 2017
@@ -686,7 +686,8 @@ TEST_F(BinaryStreamTest, BinaryItemStrea
   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);




More information about the llvm-commits mailing list