From 5e276f9dbc7f298b8d182b44687e32fa36bbf148 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 26 Jun 2013 09:49:52 +0000 Subject: [PATCH] [asan] workaround for PR16277: don't instrument AllocaInstr with alignment more than the redzone size llvm-svn: 184928 --- .../Transforms/Instrumentation/AddressSanitizer.cpp | 3 ++- llvm/test/Instrumentation/AddressSanitizer/basic.ll | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 67a8325..417fd76 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -451,7 +451,7 @@ struct FunctionStackPoisoner : public InstVisitor { StackAlignment = std::max(StackAlignment, AI.getAlignment()); AllocaVec.push_back(&AI); - uint64_t AlignedSize = getAlignedAllocaSize(&AI); + uint64_t AlignedSize = getAlignedAllocaSize(&AI); TotalStackSize += AlignedSize; } @@ -488,6 +488,7 @@ struct FunctionStackPoisoner : public InstVisitor { bool isInterestingAlloca(AllocaInst &AI) { return (!AI.isArrayAllocation() && AI.isStaticAlloca() && + AI.getAlignment() <= RedzoneSize() && AI.getAllocatedType()->isSized()); } diff --git a/llvm/test/Instrumentation/AddressSanitizer/basic.ll b/llvm/test/Instrumentation/AddressSanitizer/basic.ll index fb32e70..6002b9e 100644 --- a/llvm/test/Instrumentation/AddressSanitizer/basic.ll +++ b/llvm/test/Instrumentation/AddressSanitizer/basic.ll @@ -89,6 +89,25 @@ entry: ; CHECK-NOT: = alloca ; CHECK: ret void +; Check that asan does not touch allocas with alignment > 32. +define void @alloca_alignment_test() sanitize_address { +entry: + %x = alloca [10 x i8], align 64 + %y = alloca [10 x i8], align 128 + %z = alloca [10 x i8], align 256 + call void @alloca_test_use([10 x i8]* %x) + call void @alloca_test_use([10 x i8]* %y) + call void @alloca_test_use([10 x i8]* %z) + ret void +} + +; CHECK: define void @alloca_alignment_test() +; CHECK: = alloca{{.*}} align 64 +; CHECK: = alloca{{.*}} align 128 +; CHECK: = alloca{{.*}} align 256 +; CHECK: ret void + + define void @LongDoubleTest(x86_fp80* nocapture %a) nounwind uwtable sanitize_address { entry: store x86_fp80 0xK3FFF8000000000000000, x86_fp80* %a, align 16 -- 2.7.4