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