[PATCH] D11179: [asan] Invalid debug info for promotable allocas
Kuba Brecka
kuba.brecka at gmail.com
Wed Jul 15 03:05:46 PDT 2015
kubabrecka updated this revision to Diff 29760.
kubabrecka added a comment.
Added test. Addressed style comments.
http://reviews.llvm.org/D11179
Files:
lib/Transforms/Instrumentation/AddressSanitizer.cpp
test/Instrumentation/AddressSanitizer/debug_info_noninstrumented_alloca.ll
Index: test/Instrumentation/AddressSanitizer/debug_info_noninstrumented_alloca.ll
===================================================================
--- test/Instrumentation/AddressSanitizer/debug_info_noninstrumented_alloca.ll
+++ test/Instrumentation/AddressSanitizer/debug_info_noninstrumented_alloca.ll
@@ -0,0 +1,22 @@
+; This test checks that non-instrumented allocas stay in the first basic block.
+; Only first-basic-block allocas are considered stack slots, and moving them
+; breaks debug info.
+
+; RUN: opt < %s -asan -asan-module -S | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.10.0"
+
+define i32 @foo() sanitize_address {
+entry:
+ %instrumented = alloca i32, align 4
+ %non_instrumented = alloca i32, align 4
+ store i32 0, i32* %non_instrumented, align 4
+ %value = load i32, i32* %non_instrumented, align 4
+ %ptr = ptrtoint i32* %instrumented to i64
+ ret i32 %value
+}
+
+; CHECK: entry:
+; CHECK: %non_instrumented = alloca i32, align 4
+; CHECK: load i32, i32* @__asan_option_detect_stack_use_after_return
Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -525,6 +525,7 @@
ShadowMapping Mapping;
SmallVector<AllocaInst *, 16> AllocaVec;
+ SmallVector<AllocaInst *, 16> NonInstrumentedStaticAllocaVec;
SmallVector<Instruction *, 8> RetVec;
unsigned StackAlignment;
@@ -625,7 +626,10 @@
/// \brief Collect Alloca instructions we want (and can) handle.
void visitAllocaInst(AllocaInst &AI) {
- if (!ASan.isInterestingAlloca(AI)) return;
+ if (!ASan.isInterestingAlloca(AI)) {
+ if (AI.isStaticAlloca()) NonInstrumentedStaticAllocaVec.push_back(&AI);
+ return;
+ }
StackAlignment = std::max(StackAlignment, AI.getAlignment());
if (ASan.isDynamicAlloca(AI))
@@ -1734,6 +1738,8 @@
IRBuilder<> IRB(InsBefore);
IRB.SetCurrentDebugLocation(EntryDebugLocation);
+ for (auto *AI : NonInstrumentedStaticAllocaVec) AI->moveBefore(AllocaVec[0]);
+
SmallVector<ASanStackVariableDescription, 16> SVD;
SVD.reserve(AllocaVec.size());
for (AllocaInst *AI : AllocaVec) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11179.29760.patch
Type: text/x-patch
Size: 2319 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150715/ca8c315c/attachment.bin>
More information about the llvm-commits
mailing list