From: Jordan Rose Date: Sat, 11 Mar 2017 01:24:56 +0000 (+0000) Subject: [unittest] Explicitly specify alignment when using BumpPtrAllocator. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=621f2c2cdd5bac6647f1c423f74f8baeea796cdc;p=llvm [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297540 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/unittests/Support/AllocatorTest.cpp b/unittests/Support/AllocatorTest.cpp index 4b544641e9b..4897c47eb28 100644 --- a/unittests/Support/AllocatorTest.cpp +++ b/unittests/Support/AllocatorTest.cpp @@ -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; diff --git a/unittests/Support/BinaryStreamTest.cpp b/unittests/Support/BinaryStreamTest.cpp index dfac3038c71..1e646a6cf90 100644 --- a/unittests/Support/BinaryStreamTest.cpp +++ b/unittests/Support/BinaryStreamTest.cpp @@ -686,7 +686,8 @@ TEST_F(BinaryStreamTest, BinaryItemStream) { std::vector Foos = {{1, 1.0}, {2, 2.0}, {3, 3.0}}; BumpPtrAllocator Allocator; for (const auto &F : Foos) { - uint8_t *Ptr = Allocator.Allocate(sizeof(Foo)); + uint8_t *Ptr = static_cast(Allocator.Allocate(sizeof(Foo), + alignof(Foo))); MutableArrayRef Buffer(Ptr, sizeof(Foo)); MutableBinaryByteStream Stream(Buffer, llvm::support::big); BinaryStreamWriter Writer(Stream);