From 1ce73ef11c7a00e20f8c46ac66fa6cf272c28682 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Tue, 16 Aug 2016 16:24:10 +0000 Subject: [PATCH] [Asan] Unpoison red zones even if use-after-scope was disabled with runtime flag Summary: PR27453 Reviewers: eugenis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D23481 llvm-svn: 278818 --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | 5 +++-- llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll | 6 +++--- llvm/test/Instrumentation/AddressSanitizer/lifetime.ll | 6 +++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 5a1cf10..58e5527 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -2186,12 +2186,13 @@ void FunctionStackPoisoner::poisonStack() { poisonRedZones(L.ShadowBytes, IRB, ShadowBase, true); auto UnpoisonStack = [&](IRBuilder<> &IRB) { + // Do this always as poisonAlloca can be disabled with + // detect_stack_use_after_scope=0. + poisonRedZones(L.ShadowBytes, IRB, ShadowBase, false); if (HavePoisonedStaticAllocas) { // If we poisoned some allocas in llvm.lifetime analysis, // unpoison whole stack frame now. poisonAlloca(LocalStackBase, LocalStackSize, IRB, false); - } else { - poisonRedZones(L.ShadowBytes, IRB, ShadowBase, false); } }; diff --git a/llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll b/llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll index d41dea1..e447136 100644 --- a/llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll +++ b/llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll @@ -28,9 +28,9 @@ entry: ; CHECK-UAS: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 1) ; Unpoison memory at function exit in UAS mode. - ; CHECK-UAS: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 64) - ; CHECK-UAS: ret void - + ; CHECK-UAS: store i64 0 + ; CHECK-UAS-NEXT: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 64) + ; CHECK-UAS: ret i32 0 ret i32 0 } diff --git a/llvm/test/Instrumentation/AddressSanitizer/lifetime.ll b/llvm/test/Instrumentation/AddressSanitizer/lifetime.ll index dc87d50..cf75197 100644 --- a/llvm/test/Instrumentation/AddressSanitizer/lifetime.ll +++ b/llvm/test/Instrumentation/AddressSanitizer/lifetime.ll @@ -108,7 +108,11 @@ entry: ; CHECK: __asan_poison_stack_memory ret void - ; CHECK: __asan_unpoison_stack_memory + ; CHECK: store i64 0 + ; CHECK: store i64 0 + ; CHECK: store i64 0 + ; CHECK: store i32 0 + ; CHECK-NEXT: __asan_unpoison_stack_memory } define void @zero_sized(i64 %a) #0 { -- 2.7.4