]> granicus.if.org Git - llvm/commitdiff
[unittest] Explicitly specify alignment when using BumpPtrAllocator.
authorJordan Rose <jordan_rose@apple.com>
Sat, 11 Mar 2017 01:24:56 +0000 (01:24 +0000)
committerJordan Rose <jordan_rose@apple.com>
Sat, 11 Mar 2017 01:24:56 +0000 (01:24 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297540 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/Support/AllocatorTest.cpp
unittests/Support/BinaryStreamTest.cpp

index 4b544641e9bffa2fa4035701bb4dbe149f5e1026..4897c47eb28bacec0375d7ef5ed74c8f221a4210 100644 (file)
@@ -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;
index dfac3038c71a4a5d82042a68736c698a5f766ca2..1e646a6cf90013050e0cc47f3b29cd97c2c13316 100644 (file)
@@ -686,7 +686,8 @@ TEST_F(BinaryStreamTest, BinaryItemStream) {
   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);