1 ; RUN: opt < %s -passes=asan -asan-stack-dynamic-alloca \
2 ; RUN: -asan-use-after-return=runtime -S | FileCheck %s \
3 ; RUN: --check-prefixes=CHECK,CHECK-RUNTIME
4 ; RUN: opt < %s -passes=asan -asan-stack-dynamic-alloca -asan-mapping-scale=5 \
5 ; RUN: -asan-use-after-return=runtime -S | FileCheck %s \
6 ; RUN: --check-prefixes=CHECK,CHECK-RUNTIME
7 ; RUN: opt < %s -passes=asan -asan-stack-dynamic-alloca \
8 ; RUN: -asan-use-after-return=always -S | FileCheck %s \
9 ; RUN: --check-prefixes=CHECK,CHECK-ALWAYS \
10 ; RUN: --implicit-check-not=__asan_option_detect_stack_use_after_return
11 ; RUN: opt < %s -passes=asan -asan-stack-dynamic-alloca \
12 ; RUN: -asan-use-after-return=always -S | FileCheck %s \
13 ; RUN: --check-prefixes=CHECK,CHECK-ALWAYS \
14 ; RUN: --implicit-check-not=__asan_option_detect_stack_use_after_return
15 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"
16 target triple = "x86_64-unknown-linux-gnu"
18 define void @Func1() sanitize_address {
23 ; CHECK-RUNTIME: load i32, ptr @__asan_option_detect_stack_use_after_return
24 ; COM: CHECK-NORUNTIME-NOT: load i32, ptr @__asan_option_detect_stack_use_after_return
26 ; CHECK-RUNTIME: [[UAR_ENABLED_BB:^[0-9]+]]:
27 ; CHECK-RUNTIME: [[FAKE_STACK_RT:%[0-9]+]] = call i64 @__asan_stack_malloc_
28 ; CHECK-ALWAYS: [[FAKE_STACK_RT:%[0-9]+]] = call i64 @__asan_stack_malloc_always_
30 ; CHECK-RUNTIME: [[FAKE_STACK_BB:^[0-9]+]]:
31 ; CHECK-RUNTIME: [[FAKE_STACK:%[0-9]+]] = phi i64 [ 0, %entry ], [ [[FAKE_STACK_RT]], %[[UAR_ENABLED_BB]] ]
32 ; CHECK-RUNTIME: icmp eq i64 [[FAKE_STACK]], 0
33 ; CHECK-ALWAYS: icmp eq i64 [[FAKE_STACK_RT]], 0
35 ; CHECK: [[NO_FAKE_STACK_BB:^[0-9]+]]:
36 ; CHECK: %MyAlloca = alloca i8, i64
37 ; CHECK: [[ALLOCA:%[0-9]+]] = ptrtoint ptr %MyAlloca
39 ; CHECK-RUNTIME: phi i64 [ [[FAKE_STACK]], %[[FAKE_STACK_BB]] ], [ [[ALLOCA]], %[[NO_FAKE_STACK_BB]] ]
40 ; CHECK-ALWAYS: phi i64 [ [[FAKE_STACK_RT]], %entry ], [ [[ALLOCA]], %[[NO_FAKE_STACK_BB]] ]
44 %XXX = alloca [20 x i8], align 1
45 store volatile i8 0, ptr %XXX
49 ; Test that dynamic alloca is not used for functions with inline assembly.
50 define void @Func2() sanitize_address {
53 ; CHECK: alloca [96 x i8]
56 %XXX = alloca [20 x i8], align 1
57 store volatile i8 0, ptr %XXX
58 call void asm sideeffect "mov %%rbx, %%rcx", "~{dirflag},~{fpsr},~{flags}"() nounwind
62 ; Test that dynamic alloca is not used when setjmp is present.
63 %struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
64 %struct.__sigset_t = type { [16 x i64] }
65 @_ZL3buf = internal global [1 x %struct.__jmp_buf_tag] zeroinitializer, align 16
67 define void @Func3() uwtable sanitize_address {
68 ; CHECK-LABEL: define void @Func3
69 ; CHECK-NOT: __asan_option_detect_stack_use_after_return
70 ; CHECK-NOT: __asan_stack_malloc
71 ; CHECK: call void @__asan_handle_no_return
72 ; CHECK: call void @longjmp
75 %a = alloca i32, align 4
76 %call = call i32 @_setjmp(ptr @_ZL3buf) nounwind returns_twice
77 %cmp = icmp eq i32 0, %call
78 br i1 %cmp, label %if.then, label %if.end
80 if.then: ; preds = %entry
81 call void @longjmp(ptr @_ZL3buf, i32 1) noreturn nounwind
84 if.end: ; preds = %entry
85 call void @_Z10escape_ptrPi(ptr %a)
89 declare i32 @_setjmp(ptr) nounwind returns_twice
90 declare void @longjmp(ptr, i32) noreturn nounwind
91 declare void @_Z10escape_ptrPi(ptr)