xref: /llvm-project/compiler-rt/test/profile/Linux/coverage-linkage.cpp (revision 9788652dd08a1a0ac2e23a3b1e8c4054966a3b94)
1 /// Test instrumentation can handle various linkages.
2 // REQUIRES: lld-available
3 
4 // FIXME: Investigate and fix.
5 // XFAIL: powerpc64-target-arch
6 
7 // RUN: %clang_profgen -fcoverage-mapping %s -o %t
8 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
9 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s
10 
11 // RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -fuse-ld=lld -Wl,--gc-sections %s -o %t
12 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
13 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s
14 
15 // CHECK:      {{.*}}external{{.*}}:
16 // CHECK-NEXT:    Hash:
17 // CHECK-NEXT:    Counters: 1
18 // CHECK-NEXT:    Function count: 1
19 // CHECK:      {{.*}}weak{{.*}}:
20 // CHECK-NEXT:    Hash:
21 // CHECK-NEXT:    Counters: 1
22 // CHECK-NEXT:    Function count: 1
23 // CHECK:      main:
24 // CHECK-NEXT:    Hash:
25 // CHECK-NEXT:    Counters: 1
26 // CHECK-NEXT:    Function count: 1
27 // CHECK:      {{.*}}internal{{.*}}:
28 // CHECK-NEXT:    Hash:
29 // CHECK-NEXT:    Counters: 1
30 // CHECK-NEXT:    Function count: 1
31 // CHECK:      {{.*}}linkonce_odr{{.*}}:
32 // CHECK-NEXT:    Hash:
33 // CHECK-NEXT:    Counters: 1
34 // CHECK-NEXT:    Function count: 1
35 
36 #include <stdio.h>
37 
discarded0()38 void discarded0() {}
discarded1()39 __attribute__((weak)) void discarded1() {}
40 
external()41 void external() { puts("external"); }
weak()42 __attribute__((weak)) void weak() { puts("weak"); }
internal()43 static void internal() { puts("internal"); }
linkonce_odr()44 __attribute__((noinline)) inline void linkonce_odr() { puts("linkonce_odr"); }
45 
main()46 int main() {
47   internal();
48   external();
49   weak();
50   linkonce_odr();
51 }
52