51 lines · c
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,GATED2// 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,PLAIN3// 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,GATEDCMP4// 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,PLAINCMP5// 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=INCOMPATIBLE6// 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=INCOMPATIBLE7// 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=INCOMPATIBLE8 9// Verify that we do not emit the __sancov_gate section for "plain" trace-pc-guard10// 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-cmp15 16int x[10];17 18// CHECK: define{{.*}} void @foo19void foo(int n, int m) {20 // COM: Verify that we're emitting the call to __sanitizer_cov_trace_pc_guard upon21 // COM: checking the value of __sancov_should_track.22 // GATED: [[VAL:%.*]] = load i64, {{.*}}@__sancov_should_track23 // GATED-NOT: [[VAL:%.*]] = load i64, i64* @__sancov_should_track24 // GATED-NEXT: [[CMP:%.*]] = icmp ne i64 [[VAL]], 025 // 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_guard28 // COM: Check the trace-cmp instrumentation of the if (n) branch29 // 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_guard36 // GATED: [[WEIGHTS]] = !{!"branch_weights", i32 1, i32 100000}37 38 // COM: With the non-gated instrumentation, we should not emit the39 // COM: __sancov_should_track global.40 // PLAIN-NOT: __sancov_should_track41 // But we should still be emitting the calls to the callback.42 // PLAIN: call void @__sanitizer_cov_trace_pc_guard43 // 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}