Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / profile / instrprof-discarded-comdat.cpp
blobfeaa7c1083c14eda9910f01d9fde312ca2f932dd
1 // Check that instrprof does not introduce references to discarded sections when
2 // using comdats.
3 //
4 // Occasionally, it is possible that the same function can be compiled in
5 // different TUs with slightly different linkages, e.g., due to different
6 // compiler options. However, if these are comdat functions, a single
7 // implementation will be chosen at link time. we want to ensure that the
8 // profiling data does not contain a reference to the discarded section.
10 // UNSUPPORTED: target={{.*windows.*}}
12 // RUN: mkdir -p %t.d
13 // RUN: %clangxx_pgogen -O2 -fPIC -ffunction-sections -fdata-sections -c %s -o %t.d/a1.o -DOBJECT_1 -mllvm -disable-preinline
14 // RUN: %clangxx_pgogen -O2 -fPIC -ffunction-sections -fdata-sections -c %s -o %t.d/a2.o
15 // RUN: %clangxx_pgogen -fPIC -shared -o %t.d/liba.so %t.d/a1.o %t.d/a2.o 2>&1 | FileCheck %s --allow-empty
17 // Ensure that we don't get an error when linking
18 // CHECK-NOT: relocation refers to a discarded section: .text._ZN1CIiE1fEi
20 template <typename T> struct C {
21 void f(T x);
22 int g(T x) {
23 f(x);
24 return v;
26 int v;
29 template <typename T>
30 #ifdef OBJECT_1
31 __attribute__((weak))
32 #else
33 __attribute__((noinline))
34 #endif
35 void C<T>::f(T x) {
36 v += x;
39 #ifdef OBJECT_1
40 int foo() {
41 C<int> c;
42 c.f(1);
43 return c.g(2);
45 #else
46 int bar() {
47 C<int> c;
48 c.f(3);
49 return c.g(4);
51 #endif