xref: /aosp_15_r20/external/llvm/test/Instrumentation/SanitizerCoverage/coverage.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=0 -S | FileCheck %s --check-prefix=CHECK0
2*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -S | FileCheck %s --check-prefix=CHECK1
3*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -S | FileCheck %s --check-prefix=CHECK2
4*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=10 -S | FileCheck %s --check-prefix=CHECK2
5*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=0  -S | FileCheck %s --check-prefix=CHECK_WITH_CHECK
6*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=1  -S | FileCheck %s --check-prefix=CHECK_WITH_CHECK
7*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-block-threshold=10 -S | FileCheck %s --check-prefix=CHECK3
8*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=4 -S | FileCheck %s --check-prefix=CHECK4
9*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=4 -sanitizer-coverage-trace-pc  -S | FileCheck %s --check-prefix=CHECK_TRACE_PC
10*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-8bit-counters=1  -S | FileCheck %s --check-prefix=CHECK-8BIT
11*9880d681SAndroid Build Coastguard Worker
12*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=10 \
13*9880d681SAndroid Build Coastguard Worker; RUN:      -S | FileCheck %s --check-prefix=CHECK2
14*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=1 \
15*9880d681SAndroid Build Coastguard Worker; RUN:      -S | FileCheck %s --check-prefix=CHECK_WITH_CHECK
16*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-prune-blocks=1 -S | FileCheck %s --check-prefix=CHECKPRUNE
17*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard Workertarget 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"
19*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-unknown-linux-gnu"
20*9880d681SAndroid Build Coastguard Workerdefine void @foo(i32* %a) sanitize_address {
21*9880d681SAndroid Build Coastguard Workerentry:
22*9880d681SAndroid Build Coastguard Worker  %tobool = icmp eq i32* %a, null
23*9880d681SAndroid Build Coastguard Worker  br i1 %tobool, label %if.end, label %if.then
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker  if.then:                                          ; preds = %entry
26*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* %a, align 4
27*9880d681SAndroid Build Coastguard Worker  br label %if.end
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Worker  if.end:                                           ; preds = %entry, %if.then
30*9880d681SAndroid Build Coastguard Worker  ret void
31*9880d681SAndroid Build Coastguard Worker}
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Worker; CHECK0-NOT: @llvm.global_ctors = {{.*}}{ i32 2, void ()* @sancov.module_ctor }
34*9880d681SAndroid Build Coastguard Worker; CHECK1: @llvm.global_ctors = {{.*}}{ i32 2, void ()* @sancov.module_ctor, i8* null }
35*9880d681SAndroid Build Coastguard Worker; CHECK2: @llvm.global_ctors = {{.*}}{ i32 2, void ()* @sancov.module_ctor, i8* null }
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Worker; CHECK0-NOT: call void @__sanitizer_cov(
38*9880d681SAndroid Build Coastguard Worker; CHECK0-NOT: call void @__sanitizer_cov_module_init(
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard Worker; CHECK1-LABEL: define void @foo
41*9880d681SAndroid Build Coastguard Worker; CHECK1: %0 = load atomic i32, i32* {{.*}} monotonic, align 4, !nosanitize
42*9880d681SAndroid Build Coastguard Worker; CHECK1: %1 = icmp sge i32 0, %0
43*9880d681SAndroid Build Coastguard Worker; CHECK1: br i1 %1, label %2, label %3
44*9880d681SAndroid Build Coastguard Worker; CHECK1: call void @__sanitizer_cov(i32*{{.*}})
45*9880d681SAndroid Build Coastguard Worker; CHECK1: call void asm sideeffect "", ""()
46*9880d681SAndroid Build Coastguard Worker; CHECK1-NOT: call void @__sanitizer_cov
47*9880d681SAndroid Build Coastguard Worker; CHECK1: ret void
48*9880d681SAndroid Build Coastguard Worker
49*9880d681SAndroid Build Coastguard Worker; CHECK1-LABEL: define internal void @sancov.module_ctor
50*9880d681SAndroid Build Coastguard Worker; CHECK1-NOT: ret
51*9880d681SAndroid Build Coastguard Worker; CHECK1: call void @__sanitizer_cov_module_init({{.*}}, i64 2,
52*9880d681SAndroid Build Coastguard Worker; CHECK1: ret
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard Worker; CHECK_WITH_CHECK-LABEL: define void @foo
55*9880d681SAndroid Build Coastguard Worker; CHECK_WITH_CHECK: __sanitizer_cov_with_check
56*9880d681SAndroid Build Coastguard Worker; CHECK_WITH_CHECK: ret void
57*9880d681SAndroid Build Coastguard Worker; CHECK_WITH_CHECK-LABEL: define internal void @sancov.module_ctor
58*9880d681SAndroid Build Coastguard Worker; CHECK_WITH_CHECK-NOT: ret
59*9880d681SAndroid Build Coastguard Worker; CHECK_WITH_CHECK: call void @__sanitizer_cov_module_init({{.*}}, i64 3,
60*9880d681SAndroid Build Coastguard Worker; CHECK_WITH_CHECK: ret
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Worker; CHECK2-LABEL: define void @foo
63*9880d681SAndroid Build Coastguard Worker; CHECK2: call void @__sanitizer_cov
64*9880d681SAndroid Build Coastguard Worker; CHECK2: call void asm sideeffect "", ""()
65*9880d681SAndroid Build Coastguard Worker; CHECK2: call void @__sanitizer_cov
66*9880d681SAndroid Build Coastguard Worker; CHECK2: call void asm sideeffect "", ""()
67*9880d681SAndroid Build Coastguard Worker; CHECK2: call void asm sideeffect "", ""()
68*9880d681SAndroid Build Coastguard Worker; CHECK2-NOT: call void @__sanitizer_cov
69*9880d681SAndroid Build Coastguard Worker; CHECK2: ret void
70*9880d681SAndroid Build Coastguard Worker
71*9880d681SAndroid Build Coastguard Worker; CHECK2-LABEL: define internal void @sancov.module_ctor
72*9880d681SAndroid Build Coastguard Worker; CHECK2-NOT: ret
73*9880d681SAndroid Build Coastguard Worker; CHECK2: call void @__sanitizer_cov_module_init({{.*}}, i64 3,
74*9880d681SAndroid Build Coastguard Worker; CHECK2: ret
75*9880d681SAndroid Build Coastguard Worker
76*9880d681SAndroid Build Coastguard Worker; CHECK3-LABEL: define void @foo
77*9880d681SAndroid Build Coastguard Worker; CHECK3: call void @__sanitizer_cov
78*9880d681SAndroid Build Coastguard Worker; CHECK3: call void @__sanitizer_cov
79*9880d681SAndroid Build Coastguard Worker; CHECK3-NOT: ret void
80*9880d681SAndroid Build Coastguard Worker; CHECK3: call void @__sanitizer_cov
81*9880d681SAndroid Build Coastguard Worker; CHECK3-NOT: call void @__sanitizer_cov
82*9880d681SAndroid Build Coastguard Worker; CHECK3: ret void
83*9880d681SAndroid Build Coastguard Worker
84*9880d681SAndroid Build Coastguard Worker; test -sanitizer-coverage-8bit-counters=1
85*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT-LABEL: define void @foo
86*9880d681SAndroid Build Coastguard Worker
87*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: [[V11:%[0-9]*]] = load i8{{.*}}!nosanitize
88*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: [[V12:%[0-9]*]] = add i8 [[V11]], 1
89*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: store i8 [[V12]]{{.*}}!nosanitize
90*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: [[V21:%[0-9]*]] = load i8{{.*}}!nosanitize
91*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: [[V22:%[0-9]*]] = add i8 [[V21]], 1
92*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: store i8 [[V22]]{{.*}}!nosanitize
93*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: [[V31:%[0-9]*]] = load i8{{.*}}!nosanitize
94*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: [[V32:%[0-9]*]] = add i8 [[V31]], 1
95*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: store i8 [[V32]]{{.*}}!nosanitize
96*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: [[V41:%[0-9]*]] = load i8{{.*}}!nosanitize
97*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: [[V42:%[0-9]*]] = add i8 [[V41]], 1
98*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: store i8 [[V42]]{{.*}}!nosanitize
99*9880d681SAndroid Build Coastguard Worker
100*9880d681SAndroid Build Coastguard Worker; CHECK-8BIT: ret void
101*9880d681SAndroid Build Coastguard Worker
102*9880d681SAndroid Build Coastguard Worker
103*9880d681SAndroid Build Coastguard Worker%struct.StructWithVptr = type { i32 (...)** }
104*9880d681SAndroid Build Coastguard Worker
105*9880d681SAndroid Build Coastguard Workerdefine void @CallViaVptr(%struct.StructWithVptr* %foo) uwtable sanitize_address {
106*9880d681SAndroid Build Coastguard Workerentry:
107*9880d681SAndroid Build Coastguard Worker  %0 = bitcast %struct.StructWithVptr* %foo to void (%struct.StructWithVptr*)***
108*9880d681SAndroid Build Coastguard Worker  %vtable = load void (%struct.StructWithVptr*)**, void (%struct.StructWithVptr*)*** %0, align 8
109*9880d681SAndroid Build Coastguard Worker  %1 = load void (%struct.StructWithVptr*)*, void (%struct.StructWithVptr*)** %vtable, align 8
110*9880d681SAndroid Build Coastguard Worker  tail call void %1(%struct.StructWithVptr* %foo)
111*9880d681SAndroid Build Coastguard Worker  tail call void %1(%struct.StructWithVptr* %foo)
112*9880d681SAndroid Build Coastguard Worker  tail call void asm sideeffect "", ""()
113*9880d681SAndroid Build Coastguard Worker  ret void
114*9880d681SAndroid Build Coastguard Worker}
115*9880d681SAndroid Build Coastguard Worker
116*9880d681SAndroid Build Coastguard Worker; We expect to see two calls to __sanitizer_cov_indir_call16
117*9880d681SAndroid Build Coastguard Worker; with different values of second argument.
118*9880d681SAndroid Build Coastguard Worker; CHECK4-LABEL: define void @CallViaVptr
119*9880d681SAndroid Build Coastguard Worker; CHECK4: call void @__sanitizer_cov_indir_call16({{.*}},[[CACHE:.*]])
120*9880d681SAndroid Build Coastguard Worker; CHECK4-NOT: call void @__sanitizer_cov_indir_call16({{.*}},[[CACHE]])
121*9880d681SAndroid Build Coastguard Worker; CHECK4: ret void
122*9880d681SAndroid Build Coastguard Worker
123*9880d681SAndroid Build Coastguard Worker; CHECK_TRACE_PC-LABEL: define void @foo
124*9880d681SAndroid Build Coastguard Worker; CHECK_TRACE_PC: call void @__sanitizer_cov_trace_pc
125*9880d681SAndroid Build Coastguard Worker; CHECK_TRACE_PC: call void asm sideeffect "", ""()
126*9880d681SAndroid Build Coastguard Worker; CHECK_TRACE_PC: ret void
127*9880d681SAndroid Build Coastguard Worker
128*9880d681SAndroid Build Coastguard Worker; CHECK_TRACE_PC-LABEL: define void @CallViaVptr
129*9880d681SAndroid Build Coastguard Worker; CHECK_TRACE_PC: call void @__sanitizer_cov_trace_pc_indir
130*9880d681SAndroid Build Coastguard Worker; CHECK_TRACE_PC: call void @__sanitizer_cov_trace_pc_indir
131*9880d681SAndroid Build Coastguard Worker; CHECK_TRACE_PC: ret void
132*9880d681SAndroid Build Coastguard Worker
133*9880d681SAndroid Build Coastguard Workerdefine void @call_unreachable() uwtable sanitize_address {
134*9880d681SAndroid Build Coastguard Workerentry:
135*9880d681SAndroid Build Coastguard Worker  unreachable
136*9880d681SAndroid Build Coastguard Worker}
137*9880d681SAndroid Build Coastguard Worker
138*9880d681SAndroid Build Coastguard Worker; CHECK4-LABEL: define void @call_unreachable
139*9880d681SAndroid Build Coastguard Worker; CHECK4-NOT: __sanitizer_cov
140*9880d681SAndroid Build Coastguard Worker; CHECK4: unreachable
141*9880d681SAndroid Build Coastguard Worker
142*9880d681SAndroid Build Coastguard Worker; CHECKPRUNE-LABEL: define void @foo
143*9880d681SAndroid Build Coastguard Worker; CHECKPRUNE: call void @__sanitizer_cov
144*9880d681SAndroid Build Coastguard Worker; CHECKPRUNE: call void @__sanitizer_cov
145*9880d681SAndroid Build Coastguard Worker; CHECKPRUNE: call void @__sanitizer_cov
146*9880d681SAndroid Build Coastguard Worker; CHECKPRUNE-NOT: call void @__sanitizer_cov
147*9880d681SAndroid Build Coastguard Worker; CHECKPRUNE: ret void
148