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,40 @@ +// 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 +// RUN: llvm-objdump -s %t | grep "Contents of section __sancov_cfs:" + +#include + +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: Success! +// TODO(navidem): make sure this is all to be checked for the collected control flow. \ No newline at end of file