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-init.cpp
blob0b2da9aebac8e27298eca479b91c9484ab8645f0
1 // Tests trace pc guard coverage collection.
2 //
3 // REQUIRES: has_sancovcc,stable-runtime,x86_64-linux
4 //
5 // RUN: DIR=%t_workdir
6 // RUN: CLANG_ARGS="-O0 -fsanitize-coverage=trace-pc-guard"
7 // RUN: rm -rf $DIR
8 // RUN: mkdir -p $DIR
9 // RUN: cd $DIR
10 // RUN: %clangxx -DSHARED1 $CLANG_ARGS -shared %s -o %t_1.so -fPIC
11 // RUN: %clangxx -DSTATIC1 $CLANG_ARGS %s -c -o %t_2.o
12 // RUN: %clangxx -DMAIN $CLANG_ARGS %s -o %t %t_1.so %t_2.o
13 // RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s
14 // RUN: rm -rf $DIR
16 #include <stdio.h>
17 #include <stdint.h>
18 #include <stdlib.h>
20 extern "C" {
21 int bar();
22 int baz();
25 #ifdef MAIN
27 extern "C" void __sanitizer_cov_trace_pc_guard_init(uint32_t *start, uint32_t *stop) {
28 fprintf(stderr, "__sanitizer_cov_trace_pc_guard_init\n");
31 extern "C" void __sanitizer_cov_trace_pc_guard(uint32_t *guard) { }
34 int foo() {
35 fprintf(stderr, "foo\n");
36 return 1;
39 int main() {
40 fprintf(stderr, "main\n");
41 foo();
42 bar();
43 baz();
46 #endif // MAIN
48 extern "C" {
50 #ifdef SHARED1
51 int bar() {
52 fprintf(stderr, "bar\n");
53 return 1;
55 #endif
57 #ifdef STATIC1
58 int baz() {
59 fprintf(stderr, "baz\n");
60 return 1;
62 #endif
64 } // extern "C"
66 // Init is called once per DSO.
67 // CHECK: __sanitizer_cov_trace_pc_guard_init
68 // CHECK-NEXT: __sanitizer_cov_trace_pc_guard_init
69 // CHECK-NEXT: main
70 // CHECK-NEXT: foo
71 // CHECK-NEXT: bar
72 // CHECK-NEXT: baz