1; RUN: opt < %s -sancov -sanitizer-coverage-level=4 -sanitizer-coverage-trace-pc -S | FileCheck %s --check-prefix=CHECK_TRACE_PC 2 3; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-prune-blocks=1 -S | FileCheck %s --check-prefix=CHECKPRUNE 4 5target 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" 6target triple = "x86_64-unknown-linux-gnu" 7define void @foo(i32* %a) sanitize_address { 8entry: 9 %tobool = icmp eq i32* %a, null 10 br i1 %tobool, label %if.end, label %if.then 11 12 if.then: ; preds = %entry 13 store i32 0, i32* %a, align 4 14 br label %if.end 15 16 if.end: ; preds = %entry, %if.then 17 ret void 18} 19 20; CHECK0-NOT: @llvm.global_ctors = {{.*}}{ i32 2, void ()* @sancov.module_ctor } 21; CHECK1: @llvm.global_ctors = {{.*}}{ i32 2, void ()* @sancov.module_ctor, i8* null } 22; CHECK2: @llvm.global_ctors = {{.*}}{ i32 2, void ()* @sancov.module_ctor, i8* null } 23 24; CHECK0-NOT: call void @__sanitizer_cov( 25; CHECK0-NOT: call void @__sanitizer_cov_module_init( 26 27; CHECK1-LABEL: define void @foo 28; CHECK1: %0 = load atomic i32, i32* {{.*}} 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(i32*{{.*}}) 32; CHECK1: call void asm sideeffect "", ""() 33; CHECK1-NOT: call void @__sanitizer_cov 34; CHECK1: ret void 35 36; CHECK1-LABEL: define internal void @sancov.module_ctor 37; CHECK1-NOT: ret 38; CHECK1: call void @__sanitizer_cov_module_init({{.*}}, i64 2, {{.*}}@__sancov_gen_modname 39; CHECK1: ret 40 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 48 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 56; CHECK2: ret void 57 58; CHECK2-LABEL: define internal void @sancov.module_ctor 59; CHECK2-NOT: ret 60; CHECK2: call void @__sanitizer_cov_module_init({{.*}}, i64 3, 61; CHECK2: ret 62 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 69; CHECK3: ret void 70 71%struct.StructWithVptr = type { i32 (...)** } 72 73define void @CallViaVptr(%struct.StructWithVptr* %foo) uwtable sanitize_address { 74entry: 75 %0 = bitcast %struct.StructWithVptr* %foo to void (%struct.StructWithVptr*)*** 76 %vtable = load void (%struct.StructWithVptr*)**, void (%struct.StructWithVptr*)*** %0, align 8 77 %1 = load void (%struct.StructWithVptr*)*, void (%struct.StructWithVptr*)** %vtable, align 8 78 tail call void %1(%struct.StructWithVptr* %foo) 79 tail call void %1(%struct.StructWithVptr* %foo) 80 tail call void asm sideeffect "", ""() 81 ret void 82} 83 84; CHECK_TRACE_PC-LABEL: define void @foo 85; CHECK_TRACE_PC: call void @__sanitizer_cov_trace_pc 86; CHECK_TRACE_PC: call void asm sideeffect "", ""() 87; CHECK_TRACE_PC: ret void 88 89; CHECK_TRACE_PC-LABEL: define void @CallViaVptr 90; CHECK_TRACE_PC: call void @__sanitizer_cov_trace_pc_indir 91; CHECK_TRACE_PC: call void @__sanitizer_cov_trace_pc_indir 92; CHECK_TRACE_PC: ret void 93 94define void @call_unreachable() uwtable sanitize_address { 95entry: 96 unreachable 97} 98 99; CHECKPRUNE-LABEL: define void @foo 100; CHECKPRUNE: call void @__sanitizer_cov 101; CHECKPRUNE: call void @__sanitizer_cov 102; CHECKPRUNE: call void @__sanitizer_cov 103; CHECKPRUNE-NOT: call void @__sanitizer_cov 104; CHECKPRUNE: ret void 105