xref: /llvm-project/llvm/test/Instrumentation/AddressSanitizer/asan-stack-safety.ll (revision 7740565f56ce888f5c60d986476185477c911b25)
1; REQUIRES: x86-registered-target
2
3; RUN: opt < %s -S -asan-instrumentation-with-call-threshold=0 -passes=asan -asan-use-stack-safety=0 -o - | FileCheck %s --implicit-check-not="call {{.*}} @__asan_{{load|store|stack}}" --check-prefixes=CHECK,NOSAFETY
4; RUN: opt < %s -S -asan-instrumentation-with-call-threshold=0 -passes=asan | FileCheck %s --implicit-check-not="call {{.*}} @__asan_{{load|store|stack}}"
5
6; CHECK-LABEL: define i32 @load
7define i32 @load() sanitize_address {
8  %buf = alloca [10 x i8], align 1
9  ; NOSAFETY: call i64 @__asan_stack_malloc
10  %1 = load i8, ptr %buf, align 1
11  ; NOSAFETY: call void @__asan_load1
12  ret i32 0
13}
14
15; CHECK-LABEL: define i32 @store
16define i32 @store() sanitize_address {
17  %buf = alloca [10 x i8], align 1
18  ; NOSAFETY: call i64 @__asan_stack_malloc
19  store i8 0, ptr %buf
20  ; NOSAFETY: call void @__asan_store1
21  ret i32 0
22}
23
24; CHECK-LABEL: define i32 @unsafe_alloca
25define i32 @unsafe_alloca(i32 %i) sanitize_address {
26  %buf.sroa.0 = alloca [10 x i8], align 4
27  ; CHECK: call i64 @__asan_stack_malloc
28  %ptr = getelementptr [10 x i8], ptr %buf.sroa.0, i32 %i, i32 0
29  store volatile i8 0, ptr %ptr, align 4
30  ; CHECK: call void @__asan_store1
31  store volatile i8 0, ptr %buf.sroa.0, align 4
32  ; NOSAFETY: call void @__asan_store1
33  ret i32 0
34}
35
36; CHECK-LABEL: define void @atomicrmw
37define void @atomicrmw() sanitize_address {
38  %buf = alloca [10 x i8], align 1
39  ; NOSAFETY: call i64 @__asan_stack_malloc
40  %1 = atomicrmw add ptr %buf, i8 1 seq_cst
41  ; NOSAFETY: call void @__asan_store1
42  ret void
43}
44
45; CHECK-LABEL: define void @cmpxchg
46define void @cmpxchg(i8 %compare_to, i8 %new_value) sanitize_address {
47  %buf = alloca [10 x i8], align 1
48  ; NOSAFETY: call i64 @__asan_stack_malloc
49  %1 = cmpxchg ptr %buf, i8 %compare_to, i8 %new_value seq_cst seq_cst
50  ; NOSAFETY: call void @__asan_store1
51  ret void
52}
53
54%struct.S = type { i32, i32 }
55
56; CHECK-LABEL: define %struct.S @exchange(
57; NOSAFETY: call i64 @__asan_stack_malloc
58; CHECK:    call ptr @__asan_memcpy(
59; CHECK:    call ptr @__asan_memcpy(
60; NOSAFETY: call void @__asan_loadN(
61define %struct.S @exchange(ptr %a, ptr %b) sanitize_address {
62entry:
63  %tmp = alloca %struct.S, align 4
64  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %tmp, ptr align 4 %a, i64 8, i1 false)
65  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %a, ptr align 4 %b, i64 8, i1 false)
66  %ret = load %struct.S, ptr %tmp
67  ret %struct.S %ret
68}
69
70declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture readonly, i64, i1) nounwind
71