Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / profile / Linux / coverage-weak-lld.cpp
blob485ec4719c044b197b7b17e32d6deb6b6f7e1b32
1 // REQUIRES: lld-available
3 // FIXME: Investigate and fix.
4 // XFAIL: powerpc64-target-arch
6 // RUN: %clang_profgen -fcoverage-mapping -c %s -o %t0.o
7 // RUN: %clang_profgen -fcoverage-mapping -c %s -DOBJ_1 -o %t1.o
8 // RUN: %clang_profgen -fcoverage-mapping -c %s -DOBJ_2 -o %t2.o
10 /// An external symbol can override a weak external symbol.
11 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld %t0.o %t1.o -o %t1
12 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK1
13 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE1_NOGC
14 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,--gc-sections %t0.o %t1.o -o %t1
15 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK1
16 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE1_NOGC
18 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld %t0.o %t2.o -o %t2
19 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t2 | FileCheck %s --check-prefix=CHECK2
20 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE2_NOGC
21 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,--gc-sections %t0.o %t2.o -o %t2
22 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t2 | FileCheck %s --check-prefix=CHECK2
23 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE2_GC
25 /// Repeat the above tests with -ffunction-sections.
26 // RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -c %s -o %t0.o
27 // RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -c %s -DOBJ_1 -o %t1.o
28 // RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -c %s -DOBJ_2 -o %t2.o
30 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld %t0.o %t1.o -o %t1
31 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK1
32 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE1_NOGC
33 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,--gc-sections %t0.o %t1.o -o %t1
34 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t1 | FileCheck %s --check-prefix=CHECK1
35 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE1_GC
37 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld %t0.o %t2.o -o %t2
38 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t2 | FileCheck %s --check-prefix=CHECK2
39 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE2_NOGC
40 // RUN: %clang_profgen -fcoverage-mapping -fuse-ld=lld -Wl,--gc-sections %t0.o %t2.o -o %t2
41 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t2 | FileCheck %s --check-prefix=CHECK2
42 // RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s --check-prefix=PROFILE2_GC
44 // CHECK1: strong
45 // CHECK1: strong
47 /// __profc__Z4weakv in %t1.o is local and has a zero value.
48 /// Without GC it takes a duplicate entry.
49 // PROFILE1_NOGC: _Z4weakv:
50 // PROFILE1_NOGC-NEXT: Hash:
51 // PROFILE1_NOGC-NEXT: Counters: 1
52 // PROFILE1_NOGC-NEXT: Function count: 0
53 // PROFILE1_NOGC: _Z4weakv:
54 // PROFILE1_NOGC-NEXT: Hash:
55 // PROFILE1_NOGC-NEXT: Counters: 1
56 // PROFILE1_NOGC-NEXT: Function count: 2
58 // PROFILE1_GC: _Z4weakv:
59 // PROFILE1_GC-NEXT: Hash:
60 // PROFILE1_GC-NEXT: Counters: 1
61 // PROFILE1_GC-NEXT: Function count: 2
62 // PROFILE1_GC-NOT: _Z4weakv:
64 // CHECK2: weak
65 // CHECK2: weak
67 /// __profc__Z4weakv in %t2.o is weak and resolves to the value of %t0.o's copy.
68 /// Without GC it takes a duplicate entry.
69 // PROFILE2_NOGC: _Z4weakv:
70 // PROFILE2_NOGC-NEXT: Hash:
71 // PROFILE2_NOGC-NEXT: Counters: 1
72 // PROFILE2_NOGC-NEXT: Function count: 2
73 // PROFILE2_NOGC: _Z4weakv:
74 // PROFILE2_NOGC-NEXT: Hash:
75 // PROFILE2_NOGC-NEXT: Counters: 1
76 // PROFILE2_NOGC-NEXT: Function count: 2
78 // PROFILE2_GC: _Z4weakv:
79 // PROFILE2_GC-NEXT: Hash:
80 // PROFILE2_GC-NEXT: Counters: 1
81 // PROFILE2_GC-NEXT: Function count: 2
82 // PROFILE2_GC-NOT: _Z4weakv:
84 #ifdef OBJ_1
85 #include <stdio.h>
87 void weak() { puts("strong"); }
88 void foo() { weak(); }
90 #elif defined(OBJ_2)
91 #include <stdio.h>
93 __attribute__((weak)) void weak() { puts("unreachable"); }
94 void foo() { weak(); }
96 #else
97 #include <stdio.h>
99 __attribute__((weak)) void weak() { puts("weak"); }
100 void foo();
102 int main() {
103 foo();
104 weak();
106 #endif