[llvm] r276374 - Fix detection of stack-use-after scope for char arrays.

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 21 17:56:18 PDT 2016


Author: vitalybuka
Date: Thu Jul 21 19:56:17 2016
New Revision: 276374

URL: http://llvm.org/viewvc/llvm-project?rev=276374&view=rev
Log:
Fix detection of stack-use-after scope for char arrays.

Summary:
Clang inserts GetElementPtrInst so findAllocaForValue was not
able to find allocas.

PR27453

Reviewers: kcc, eugenis

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

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=276374&r1=276373&r2=276374&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Thu Jul 21 19:56:17 2016
@@ -2286,6 +2286,10 @@ AllocaInst *FunctionStackPoisoner::findA
         return nullptr;
       Res = IncValueAI;
     }
+  } else if (GetElementPtrInst *EP = dyn_cast<GetElementPtrInst>(V)) {
+    Res = findAllocaForValue(EP->getPointerOperand());
+  } else {
+    DEBUG(dbgs() << "Alloca search canceled on unknown instruction: " << *V << "\n");
   }
   if (Res) AllocaForValue[V] = Res;
   return Res;

Modified: llvm/trunk/test/Instrumentation/AddressSanitizer/lifetime.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/lifetime.ll?rev=276374&r1=276373&r2=276374&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/AddressSanitizer/lifetime.ll (original)
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/lifetime.ll Thu Jul 21 19:56:17 2016
@@ -91,6 +91,26 @@ bb1:
   ret void
 }
 
+; Check that arguments of lifetime may come from getelementptr nodes.
+define void @getelementptr_args() sanitize_address{
+  ; CHECK-LABEL: define void @getelementptr_args
+entry:
+  %x = alloca [1024 x i8], align 16
+  %d = alloca i8*, align 8
+
+  %0 = getelementptr inbounds [1024 x i8], [1024 x i8]* %x, i64 0, i64 0
+  call void @llvm.lifetime.start(i64 1024, i8* %0)
+  ; CHECK: __asan_unpoison_stack_memory
+
+  store i8* %0, i8** %d, align 8
+
+  call void @llvm.lifetime.end(i64 1024, i8* %0)
+  ; CHECK: __asan_poison_stack_memory
+
+  ret void
+  ; CHECK: __asan_unpoison_stack_memory
+}
+
 define void @zero_sized(i64 %a) #0 {
 ; CHECK-LABEL: define void @zero_sized(i64 %a)
 




More information about the llvm-commits mailing list