[llvm] r281126 - [asan] Add flag to allow lifetime analysis of problematic allocas

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 9 18:06:11 PDT 2016


Author: vitalybuka
Date: Fri Sep  9 20:06:11 2016
New Revision: 281126

URL: http://llvm.org/viewvc/llvm-project?rev=281126&view=rev
Log:
[asan] Add flag to allow lifetime analysis of problematic allocas

Summary:
Could be useful for comparison when we suspect that alloca was skipped
because of this.

Reviewers: eugenis

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D24437

Modified:
    llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
    llvm/trunk/test/Instrumentation/AddressSanitizer/lifetime.ll

Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=281126&r1=281125&r2=281126&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Fri Sep  9 20:06:11 2016
@@ -183,6 +183,10 @@ static cl::opt<bool> ClExperimentalPoiso
     "asan-experimental-poisoning",
     cl::desc("Enable experimental red zones and scope poisoning"), cl::Hidden,
     cl::init(true));
+static cl::opt<bool> ClSkipAmbiguousLifetimeAllocas(
+    "asan-skip-ambiguous-lifetime-allocas",
+    cl::desc("Disabled lifetime check for allocas with ambiguous lifetime"),
+    cl::Hidden, cl::init(true));
 // This flag may need to be replaced with -f[no]asan-globals.
 static cl::opt<bool> ClGlobals("asan-globals",
                                cl::desc("Handle global objects"), cl::Hidden,
@@ -890,6 +894,8 @@ public:
 // This is workaround for PR28267.
 void removeAllocasWithAmbiguousLifetime(
     SmallVectorImpl<FunctionStackPoisoner::AllocaPoisonCall> &PoisonCallVec) {
+  if (!ClSkipAmbiguousLifetimeAllocas)
+    return;
   DenseMap<const AllocaInst *, AllocaLifetimeChecker> Checkers;
   for (const auto &APC : PoisonCallVec)
     Checkers[APC.AI].AddMarker(APC.InsBefore->getParent(), !APC.DoPoison);

Modified: llvm/trunk/test/Instrumentation/AddressSanitizer/lifetime.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/lifetime.ll?rev=281126&r1=281125&r2=281126&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/AddressSanitizer/lifetime.ll (original)
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/lifetime.ll Fri Sep  9 20:06:11 2016
@@ -1,6 +1,7 @@
 ; Test handling of llvm.lifetime intrinsics.
-; RUN: opt < %s -asan -asan-module -asan-use-after-scope -asan-use-after-return=0 -S | FileCheck %s
-; RUN: opt < %s -asan -asan-module -asan-use-after-scope -asan-use-after-return=0 -asan-instrument-dynamic-allocas=0 -S | FileCheck %s --check-prefix=CHECK-NO-DYNAMIC
+; RUN: opt < %s -asan -asan-module -asan-use-after-scope -asan-use-after-return=0 -S | FileCheck %s --check-prefixes=CHECK,CHECK-DEFAULT
+; RUN: opt < %s -asan -asan-module -asan-use-after-scope -asan-use-after-return=0 -asan-instrument-dynamic-allocas=0 -S | FileCheck %s --check-prefixes=CHECK,CHECK-NO-DYNAMIC
+; RUN: opt < %s -asan -asan-module -asan-use-after-scope -asan-use-after-return=0 -asan-skip-ambiguous-lifetime-allocas=0 -S | FileCheck %s --check-prefixes=CHECK,CHECK-AMBIGUOUS
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
@@ -69,14 +70,14 @@ define void @lifetime() sanitize_address
   %arr.ptr = bitcast [10 x i32]* %arr to i8*
 
   call void @llvm.lifetime.start(i64 40, i8* %arr.ptr)
-  ; CHECK: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 40)
+  ; CHECK-DEFAULT: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 40)
   ; CHECK-NO-DYNAMIC-NOT: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 40)
 
   store volatile i8 0, i8* %arr.ptr
   ; CHECK: store volatile
 
   call void @llvm.lifetime.end(i64 40, i8* %arr.ptr)
-  ; CHECK: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 40)
+  ; CHECK-DEFAULT: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 40)
   ; CHECK-NO-DYNAMIC-NOT: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 40)
 
   ; One more lifetime start/end for the same variable %i.
@@ -116,7 +117,8 @@ bb0:
   ; CHECK-LABEL: bb0:
 
   call void @llvm.lifetime.start(i64 1, i8* %j)
-  ; CHECK-NOT: store i8 1, i8* %{{[0-9]+}}
+  ; CHECK-DEFAULT-NOT: store i8 1, i8* %{{[0-9]+}}
+  ; CHECK-AMBIGUOUS: store i8 1, i8* %{{[0-9]+}}
   ; CHECK-NEXT: call void @llvm.lifetime.start
 
   br label %bb1
@@ -132,7 +134,8 @@ bb1:
   ; CHECK-NEXT: call void @llvm.lifetime.end
 
   call void @llvm.lifetime.end(i64 1, i8* %j)
-  ; CHECK-NOT: store i8 -8, i8* %{{[0-9]+}}
+  ; CHECK-DEFAULT-NOT: store i8 -8, i8* %{{[0-9]+}}
+  ; CHECK-AMBIGUOUS: store i8 -8, i8* %{{[0-9]+}}
   ; CHECK-NEXT: call void @llvm.lifetime.end
 
   ret void




More information about the llvm-commits mailing list