1 // RUN: %clang %s -target arm64-apple-darwin -emit-llvm -S -fsanitize-coverage=trace-pc-guard -mllvm -sanitizer-coverage-gated-trace-callbacks=1 -o - | FileCheck %s --check-prefixes=CHECK,GATED 2 // RUN: %clang %s -target arm64-apple-darwin -emit-llvm -S -fsanitize-coverage=trace-pc-guard -mllvm -sanitizer-coverage-gated-trace-callbacks=0 -o - | FileCheck %s --check-prefixes=CHECK,PLAIN 3 // RUN: %clang %s -target arm64-apple-darwin -emit-llvm -S -fsanitize-coverage=trace-pc-guard,trace-cmp -mllvm -sanitizer-coverage-gated-trace-callbacks=1 -o - | FileCheck %s --check-prefixes=CHECK,GATED,GATEDCMP 4 // RUN: %clang %s -target arm64-apple-darwin -emit-llvm -S -fsanitize-coverage=trace-pc-guard,trace-cmp -mllvm -sanitizer-coverage-gated-trace-callbacks=0 -o - | FileCheck %s --check-prefixes=CHECK,PLAIN,PLAINCMP 5 // RUN: not %clang %s -target arm64-apple-darwin -emit-llvm -S -fsanitize-coverage=trace-pc -mllvm -sanitizer-coverage-gated-trace-callbacks=1 -o /dev/null 2>&1 | FileCheck %s --check-prefixes=INCOMPATIBLE 6 // RUN: not %clang %s -target arm64-apple-darwin -emit-llvm -S -fsanitize-coverage=inline-8bit-counters -mllvm -sanitizer-coverage-gated-trace-callbacks=1 -o /dev/null 2>&1 | FileCheck %s --check-prefixes=INCOMPATIBLE 7 // RUN: not %clang %s -target arm64-apple-darwin -emit-llvm -S -fsanitize-coverage=inline-bool-flag -mllvm -sanitizer-coverage-gated-trace-callbacks=1 -o /dev/null 2>&1 | FileCheck %s --check-prefixes=INCOMPATIBLE 8 9 // Verify that we do not emit the __sancov_gate section for "plain" trace-pc-guard 10 // GATED: section "__DATA,__sancov_gate" 11 // PLAIN-NOT: section "__DATA,__sancov_gate" 12 13 // Produce an error for all incompatible sanitizer coverage modes. 14 // INCOMPATIBLE: error: 'sanitizer-coverage-gated-trace-callbacks' is only supported with trace-pc-guard or trace-cmp 15 16 int x[10]; 17 18 // CHECK: define{{.*}} void @foo 19 void foo(int n, int m) { 20 // COM: Verify that we're emitting the call to __sanitizer_cov_trace_pc_guard upon 21 // COM: checking the value of __sancov_should_track. 22 // GATED: [[VAL:%.*]] = load i64, {{.*}}@__sancov_should_track 23 // GATED-NOT: [[VAL:%.*]] = load i64, i64* @__sancov_should_track 24 // GATED-NEXT: [[CMP:%.*]] = icmp ne i64 [[VAL]], 0 25 // GATED-NEXT: br i1 [[CMP]], label %[[L_TRUE:.*]], label %[[L_FALSE:.*]], !prof [[WEIGHTS:!.+]] 26 // GATED: [[L_TRUE]]: 27 // GATED-NEXT: call void @__sanitizer_cov_trace_pc_guard 28 // COM: Check the trace-cmp instrumentation of the if (n) branch 29 // GATEDCMP: [[OPERAND:%.*]] = load i32, {{.*}} 30 // GATEDCMP-NEXT: br i1 [[CMP]], label %[[L_TRUE_1:.*]], label %[[L_FALSE_1:.*]] 31 // GATEDCMP: [[L_TRUE_1]]: 32 // GATEDCMP-NEXT: call void @__sanitizer_cov_trace_const_cmp4(i32 0, i32 [[OPERAND]]) 33 // GATED: br i1 [[CMP]], label %[[L_TRUE_2:.*]], label %[[L_FALSE_2:.*]] 34 // GATED: [[L_TRUE_2]]: 35 // GATED-NEXT: call void @__sanitizer_cov_trace_pc_guard 36 // GATED: [[WEIGHTS]] = !{!"branch_weights", i32 1, i32 100000} 37 38 // COM: With the non-gated instrumentation, we should not emit the 39 // COM: __sancov_should_track global. 40 // PLAIN-NOT: __sancov_should_track 41 // But we should still be emitting the calls to the callback. 42 // PLAIN: call void @__sanitizer_cov_trace_pc_guard 43 // PLAINCMP: [[OPERAND:%.*]] = load i32, {{.*}} 44 // PLAINCMP-NEXT: call void @__sanitizer_cov_trace_const_cmp4(i32 0, i32 [[OPERAND]]) 45 if (n) { 46 x[n] = 42; 47 if (m) { 48 x[m] = 41; 49 } 50 } 51 }