Skip to content

Commit 53054a7

Browse files
committedJul 22, 2016
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 llvm-svn: 276374
1 parent aae623f commit 53054a7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
 

‎llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,10 @@ AllocaInst *FunctionStackPoisoner::findAllocaForValue(Value *V) {
22862286
return nullptr;
22872287
Res = IncValueAI;
22882288
}
2289+
} else if (GetElementPtrInst *EP = dyn_cast<GetElementPtrInst>(V)) {
2290+
Res = findAllocaForValue(EP->getPointerOperand());
2291+
} else {
2292+
DEBUG(dbgs() << "Alloca search canceled on unknown instruction: " << *V << "\n");
22892293
}
22902294
if (Res) AllocaForValue[V] = Res;
22912295
return Res;

‎llvm/test/Instrumentation/AddressSanitizer/lifetime.ll

+20
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ bb1:
9191
ret void
9292
}
9393

94+
; Check that arguments of lifetime may come from getelementptr nodes.
95+
define void @getelementptr_args() sanitize_address{
96+
; CHECK-LABEL: define void @getelementptr_args
97+
entry:
98+
%x = alloca [1024 x i8], align 16
99+
%d = alloca i8*, align 8
100+
101+
%0 = getelementptr inbounds [1024 x i8], [1024 x i8]* %x, i64 0, i64 0
102+
call void @llvm.lifetime.start(i64 1024, i8* %0)
103+
; CHECK: __asan_unpoison_stack_memory
104+
105+
store i8* %0, i8** %d, align 8
106+
107+
call void @llvm.lifetime.end(i64 1024, i8* %0)
108+
; CHECK: __asan_poison_stack_memory
109+
110+
ret void
111+
; CHECK: __asan_unpoison_stack_memory
112+
}
113+
94114
define void @zero_sized(i64 %a) #0 {
95115
; CHECK-LABEL: define void @zero_sized(i64 %a)
96116

0 commit comments

Comments
 (0)
Please sign in to comment.