2 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=4 -sanitizer-coverage-trace-pc -S | FileCheck %s --check-prefix=CHECK_TRACE_PC
3 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-prune-blocks=1 -S | FileCheck %s --check-prefix=CHECKPRUNE
5 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"
6 target triple = "x86_64-unknown-linux-gnu"
7 define void @foo(ptr %a) sanitize_address {
9 %tobool = icmp eq ptr %a, null
10 br i1 %tobool, label %if.end, label %if.then
12 if.then: ; preds = %entry
13 store i32 0, ptr %a, align 4
16 if.end: ; preds = %entry, %if.then
20 ; CHECK0-NOT: @llvm.global_ctors = {{.*}}{ i32 2, ptr @sancov.module_ctor }
21 ; CHECK1: @llvm.global_ctors = {{.*}}{ i32 2, ptr @sancov.module_ctor, ptr null }
22 ; CHECK2: @llvm.global_ctors = {{.*}}{ i32 2, ptr @sancov.module_ctor, ptr null }
24 ; CHECK0-NOT: call void @__sanitizer_cov(
25 ; CHECK0-NOT: call void @__sanitizer_cov_module_init(
27 ; CHECK1-LABEL: define void @foo
28 ; CHECK1: %0 = load atomic i32, ptr {{.*}} monotonic, align 4, !nosanitize
29 ; CHECK1: %1 = icmp sge i32 0, %0
30 ; CHECK1: br i1 %1, label %2, label %3
31 ; CHECK1: call void @__sanitizer_cov(ptr{{.*}})
32 ; CHECK1: call void asm sideeffect "", ""()
33 ; CHECK1-NOT: call void @__sanitizer_cov
36 ; CHECK1-LABEL: define internal void @sancov.module_ctor
38 ; CHECK1: call void @__sanitizer_cov_module_init({{.*}}, i64 2, {{.*}}@__sancov_gen_modname
41 ; CHECK_WITH_CHECK-LABEL: define void @foo
42 ; CHECK_WITH_CHECK: __sanitizer_cov_with_check
43 ; CHECK_WITH_CHECK: ret void
44 ; CHECK_WITH_CHECK-LABEL: define internal void @sancov.module_ctor
45 ; CHECK_WITH_CHECK-NOT: ret
46 ; CHECK_WITH_CHECK: call void @__sanitizer_cov_module_init({{.*}}, i64 3,
47 ; CHECK_WITH_CHECK: ret
49 ; CHECK2-LABEL: define void @foo
50 ; CHECK2: call void @__sanitizer_cov
51 ; CHECK2: call void asm sideeffect "", ""()
52 ; CHECK2: call void @__sanitizer_cov
53 ; CHECK2: call void asm sideeffect "", ""()
54 ; CHECK2: call void asm sideeffect "", ""()
55 ; CHECK2-NOT: call void @__sanitizer_cov
58 ; CHECK2-LABEL: define internal void @sancov.module_ctor
60 ; CHECK2: call void @__sanitizer_cov_module_init({{.*}}, i64 3,
63 ; CHECK3-LABEL: define void @foo
64 ; CHECK3: call void @__sanitizer_cov
65 ; CHECK3: call void @__sanitizer_cov
66 ; CHECK3-NOT: ret void
67 ; CHECK3: call void @__sanitizer_cov
68 ; CHECK3-NOT: call void @__sanitizer_cov
71 %struct.StructWithVptr = type { ptr }
73 define void @CallViaVptr(ptr %foo) uwtable sanitize_address {
75 %vtable = load ptr, ptr %foo, align 8
76 %0 = load ptr, ptr %vtable, align 8
77 tail call void %0(ptr %foo)
78 tail call void %0(ptr %foo)
79 tail call void asm sideeffect "", ""()
83 ; CHECK_TRACE_PC-LABEL: define void @foo
84 ; CHECK_TRACE_PC: call void @__sanitizer_cov_trace_pc
85 ; CHECK_TRACE_PC: ret void
87 ; CHECK_TRACE_PC-LABEL: define void @CallViaVptr
88 ; CHECK_TRACE_PC: call void @__sanitizer_cov_trace_pc_indir
89 ; CHECK_TRACE_PC: call void @__sanitizer_cov_trace_pc_indir
90 ; CHECK_TRACE_PC: ret void
92 define void @call_unreachable() uwtable sanitize_address {
97 ; CHECKPRUNE-LABEL: define void @foo
98 ; CHECKPRUNE: call void @__sanitizer_cov
99 ; CHECKPRUNE: call void @__sanitizer_cov
100 ; CHECKPRUNE: call void @__sanitizer_cov
101 ; CHECKPRUNE-NOT: call void @__sanitizer_cov
102 ; CHECKPRUNE: ret void