diff --git a/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp b/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp new file mode 100644 --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp @@ -0,0 +1,45 @@ +// Tests -fsanitize-coverage=control-flow. + +// REQUIRES: has_sancovcc,stable-runtime +// UNSUPPORTED: i386-darwin, x86_64-darwin + +// RUN: %clangxx -O0 -std=c++11 -fsanitize-coverage=control-flow %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s + +#include +#include + +extern "C" void __sanitizer_cov_cfs_init(const uintptr_t *cfs_beg, + const uintptr_t *cfs_end) { + printf("Control Flow section boundaries: [%p, %p)\n", cfs_beg, cfs_end); +} + +void foo(int recurse) { + if (recurse > 0) + foo(recurse - 1); +} + +int main() { + int x = 10; + for (int i = 0; i < 10; i++) { + if (x > 5) + foo(x); + } + + switch (x) { + case 5: + foo(x); + break; + case -5: + foo(-x); + break; + + default: + break; + } + printf("Success!\n"); + return 0; +} + +// CHECK: Control Flow section boundaries +// CHECK: Success!