Skip to content

Commit

Permalink
[ASan] Disable instrumentation for inalloca variables.
Browse files Browse the repository at this point in the history
inalloca variables were not treated as static allocas, therefore didn't
participate in regular stack instrumentation. We don't want them to
participate in dynamic alloca instrumentation as well.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252213 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
vonosmas committed Nov 5, 2015
1 parent f3e49f5 commit f17835b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Transforms/Instrumentation/AddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,10 @@ bool AddressSanitizer::isInterestingAlloca(AllocaInst &AI) {
getAllocaSizeInBytes(&AI) > 0 &&
// We are only interested in allocas not promotable to registers.
// Promotable allocas are common under -O0.
(!ClSkipPromotableAllocas || !isAllocaPromotable(&AI)));
(!ClSkipPromotableAllocas || !isAllocaPromotable(&AI)) &&
// inalloca allocas are not treated as static, and we don't want
// dynamic alloca instrumentation for them as well.
!AI.isUsedWithInAlloca());

ProcessedAllocas[&AI] = IsInteresting;
return IsInteresting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ target triple = "x86_64-unknown-linux-gnu"

define void @foo(i32 %len) sanitize_address {
entry:
; CHECK-ALLOCA-LABEL: define void @foo
; CHECK-ALLOCA: __asan_alloca_poison
; CHECK-ALLOCA: __asan_allocas_unpoison
; CHECK-ALLOCA: ret void
%0 = alloca i32, align 4
%1 = alloca i8*
store volatile i32 %len, i32* %0, align 4
Expand All @@ -19,3 +21,17 @@ entry:
ret void
}

; Test that dynamic alloca is not used for inalloca variables.
define void @has_inalloca() uwtable sanitize_address {
; CHECK-ALLOCA-LABEL: define void @has_inalloca
; CHECK-ALLOCA-NOT: __asan_alloca_poison
; CHECK-ALLOCA-NOT: __asan_alloca_unpoison
; CHECK-ALLOCA: ret void
entry:
%t = alloca inalloca i32
store i32 42, i32* %t
call void @pass_inalloca(i32* inalloca %t)
ret void
}

declare void @pass_inalloca(i32* inalloca)

0 comments on commit f17835b

Please sign in to comment.