Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / sanitizer_coverage_trace_pc_guard-dso.cpp
blobe27d552f3c318467c30efa17e120aaed03be1347
1 // Tests trace pc guard coverage collection.
3 // REQUIRES: has_sancovcc
4 // UNSUPPORTED: ubsan,target={{(powerpc64|s390x|thumb).*}}
5 // XFAIL: tsan,darwin
6 // XFAIL: android && asan
8 // RUN: DIR=%t_workdir
9 // RUN: CLANG_ARGS="-O0 -fsanitize-coverage=trace-pc-guard"
10 // RUN: rm -rf $DIR
11 // RUN: mkdir -p $DIR
12 // RUN: cd $DIR
13 // RUN: %clangxx -DSHARED1 $CLANG_ARGS -shared %s -o %t_1.so -fPIC
14 // RUN: %clangxx -DSHARED2 $CLANG_ARGS -shared %s -o %t_2.so -fPIC
15 // RUN: %clangxx -DMAIN $CLANG_ARGS %s -o %t %t_1.so %t_2.so
16 // RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s
17 // RUN: %sancovcc -covered-functions -strip_path_prefix=TestCases/ *.sancov \
18 // RUN: %t %t_1.so %t_2.so 2>&1 | \
19 // RUN: FileCheck --check-prefix=CHECK-SANCOV %s
20 // RUN: rm -rf $DIR
22 #include <stdio.h>
24 extern "C" {
25 int bar();
26 int baz();
29 #ifdef MAIN
31 int foo() {
32 fprintf(stderr, "foo\n");
33 return 1;
36 int main() {
37 fprintf(stderr, "main\n");
38 foo();
39 bar();
40 baz();
43 #endif // MAIN
45 extern "C" {
47 #ifdef SHARED1
48 int bar() {
49 fprintf(stderr, "bar\n");
50 return 1;
52 #endif
54 #ifdef SHARED2
55 int baz() {
56 fprintf(stderr, "baz\n");
57 return 1;
59 #endif
61 } // extern "C"
63 // CHECK: main
64 // CHECK-NEXT: foo
65 // CHECK-NEXT: bar
66 // CHECK-NEXT: baz
67 // CHECK-DAG: SanitizerCoverage: ./sanitizer_coverage_trace_pc_guard-dso.{{.*}}.sancov: 2 PCs written
68 // CHECK-DAG: SanitizerCoverage: ./sanitizer_coverage_trace_pc_guard-dso.{{.*}}_2.so.{{.*}}.sancov: 1 PCs written
69 // CHECK-DAG: SanitizerCoverage: ./sanitizer_coverage_trace_pc_guard-dso.{{.*}}_1.so.{{.*}}.sancov: 1 PCs written
71 // CHECK-SANCOV: Ignoring {{.*}}_1.so and its coverage because __sanitizer_cov* functions were not found.
72 // CHECK-SANCOV: Ignoring {{.*}}_2.so and its coverage because __sanitizer_cov* functions were not found.
73 // CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard-dso.cpp:[[@LINE-42]] foo
74 // CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard-dso.cpp:[[@LINE-38]] main