1; RUN: opt < %s -asan -asan-module -enable-new-pm=0 -asan-use-after-return -S | FileCheck --check-prefix=CHECK-UAR %s
2; RUN: opt < %s -passes='asan-pipeline' -asan-use-after-return -S | FileCheck --check-prefix=CHECK-UAR %s
3; RUN: opt < %s -asan -asan-module -enable-new-pm=0 -asan-use-after-return=0 -S | FileCheck --check-prefix=CHECK-PLAIN %s
4; RUN: opt < %s -passes='asan-pipeline' -asan-use-after-return=0 -S | FileCheck --check-prefix=CHECK-PLAIN %s
5target datalayout = "e-i64:64-f80:128-s:64-n8:16:32:64-S128"
6target triple = "x86_64-unknown-linux-gnu"
7
8declare void @Foo(i8*)
9
10define void @Bar() uwtable sanitize_address {
11entry:
12; CHECK-PLAIN-LABEL: Bar
13; CHECK-PLAIN-NOT: label
14; CHECK-PLAIN: ret void
15
16; CHECK-UAR-LABEL: Bar
17; CHECK-UAR: load i32, i32* @__asan_option_detect_stack_use_after_return
18; CHECK-UAR: label
19; CHECK-UAR: call i64 @__asan_stack_malloc_4
20; CHECK-UAR: label
21; Poison red zones.
22; CHECK-UAR: store i64 -1007680412564983311
23; CHECK-UAR: store i64 72057598113936114
24; CHECK-UAR: store i32 -218959118
25; CHECK-UAR: store i64 -868082074056920316
26; CHECK-UAR: store i16 -3085
27; CHECK-UAR: call void @Foo
28; CHECK-UAR: call void @Foo
29; CHECK-UAR: call void @Foo
30; If LocalStackBase != OrigStackBase
31; CHECK-UAR: label
32; Then Block: poison the entire frame.
33  ; CHECK-UAR: call void @__asan_set_shadow_f5(i64 %{{[0-9]+}}, i64 128)
34  ; CHECK-UAR-NOT: store i64
35  ; CHECK-UAR: label
36; Else Block: no UAR frame. Only unpoison the redzones.
37  ; CHECK-UAR: store i64 0
38  ; CHECK-UAR: store i64 0
39  ; CHECK-UAR: store i32 0
40  ; CHECK-UAR: store i64 0
41  ; CHECK-UAR: store i16 0
42  ; CHECK-UAR-NOT: store
43  ; CHECK-UAR: label
44; Done, no more stores.
45; CHECK-UAR-NOT: store
46; CHECK-UAR: ret void
47
48  %x = alloca [20 x i8], align 16
49  %y = alloca [25 x i8], align 1
50  %z = alloca [500 x i8], align 1
51  %xx = getelementptr inbounds [20 x i8], [20 x i8]* %x, i64 0, i64 0
52  call void @Foo(i8* %xx)
53  %yy = getelementptr inbounds [25 x i8], [25 x i8]* %y, i64 0, i64 0
54  call void @Foo(i8* %yy)
55  %zz = getelementptr inbounds [500 x i8], [500 x i8]* %z, i64 0, i64 0
56  call void @Foo(i8* %zz)
57  ret void
58}
59
60
61