Home | History | Annotate | Download | only in SanitizerCoverage
      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=3 -sanitizer-coverage-8bit-counters=1  -S | FileCheck %s --check-prefix=CHECK-8BIT
     10 
     11 ; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=10 \
     12 ; RUN:      -S | FileCheck %s --check-prefix=CHECK2
     13 ; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=1 \
     14 ; RUN:      -S | FileCheck %s --check-prefix=CHECK_WITH_CHECK
     15 
     16 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"
     17 target triple = "x86_64-unknown-linux-gnu"
     18 define void @foo(i32* %a) sanitize_address {
     19 entry:
     20   %tobool = icmp eq i32* %a, null
     21   br i1 %tobool, label %if.end, label %if.then
     22 
     23   if.then:                                          ; preds = %entry
     24   store i32 0, i32* %a, align 4
     25   br label %if.end
     26 
     27   if.end:                                           ; preds = %entry, %if.then
     28   ret void
     29 }
     30 
     31 ; CHECK0-NOT: @llvm.global_ctors = {{.*}}{ i32 2, void ()* @sancov.module_ctor }
     32 ; CHECK1: @llvm.global_ctors = {{.*}}{ i32 2, void ()* @sancov.module_ctor, i8* null }
     33 ; CHECK2: @llvm.global_ctors = {{.*}}{ i32 2, void ()* @sancov.module_ctor, i8* null }
     34 
     35 ; CHECK0-NOT: call void @__sanitizer_cov(
     36 ; CHECK0-NOT: call void @__sanitizer_cov_module_init(
     37 
     38 ; CHECK1-LABEL: define void @foo
     39 ; CHECK1: %0 = load atomic i32, i32* {{.*}} monotonic, align 4, !nosanitize
     40 ; CHECK1: %1 = icmp sge i32 0, %0
     41 ; CHECK1: br i1 %1, label %2, label %3
     42 ; CHECK1: call void @__sanitizer_cov(i32*{{.*}})
     43 ; CHECK1: call void asm sideeffect "", ""()
     44 ; CHECK1-NOT: call void @__sanitizer_cov
     45 ; CHECK1: ret void
     46 
     47 ; CHECK1-LABEL: define internal void @sancov.module_ctor
     48 ; CHECK1-NOT: ret
     49 ; CHECK1: call void @__sanitizer_cov_module_init({{.*}}, i64 2,
     50 ; CHECK1: ret
     51 
     52 ; CHECK_WITH_CHECK-LABEL: define void @foo
     53 ; CHECK_WITH_CHECK: __sanitizer_cov_with_check
     54 ; CHECK_WITH_CHECK: ret void
     55 ; CHECK_WITH_CHECK-LABEL: define internal void @sancov.module_ctor
     56 ; CHECK_WITH_CHECK-NOT: ret
     57 ; CHECK_WITH_CHECK: call void @__sanitizer_cov_module_init({{.*}}, i64 4,
     58 ; CHECK_WITH_CHECK: ret
     59 
     60 ; CHECK2-LABEL: define void @foo
     61 ; CHECK2: call void @__sanitizer_cov
     62 ; CHECK2: call void asm sideeffect "", ""()
     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-NOT: call void @__sanitizer_cov
     68 ; CHECK2: ret void
     69 
     70 ; CHECK2-LABEL: define internal void @sancov.module_ctor
     71 ; CHECK2-NOT: ret
     72 ; CHECK2: call void @__sanitizer_cov_module_init({{.*}}, i64 4,
     73 ; CHECK2: ret
     74 
     75 ; CHECK3-LABEL: define void @foo
     76 ; CHECK3: call void @__sanitizer_cov
     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 
    105 define void @CallViaVptr(%struct.StructWithVptr* %foo) uwtable sanitize_address {
    106 entry:
    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 define void @call_unreachable() uwtable sanitize_address {
    124 entry:
    125   unreachable
    126 }
    127 
    128 ; CHECK4-LABEL: define void @call_unreachable
    129 ; CHECK4-NOT: __sanitizer_cov
    130 ; CHECK4: unreachable
    131