177 lines · cpp
1// RUN: %clang_cc1 -triple i386-unknown-unknown -std=c++11 -fvisibility-inlines-hidden -emit-llvm -o - %s -O2 -disable-llvm-passes | FileCheck %s2 3// The trickery with optimization in the run line is to get IR4// generation to emit available_externally function bodies, but not5// actually inline them (and thus remove the emitted bodies).6 7struct X0 {8 void __attribute__((visibility("default"))) f1() { }9 void f2() { }10 void f3();11 static void f5() { }12 virtual void f6() { }13};14 15inline void X0::f3() { }16 17template<typename T>18struct X1 {19 void __attribute__((visibility("default"))) f1() { }20 void f2() { }21 void f3();22 void f4();23 static void f5() { }24 virtual void f6() { }25};26 27template<typename T>28inline void X1<T>::f3() { }29 30template<>31inline void X1<int>::f4() { }32 33struct __attribute__((visibility("default"))) X2 {34 void f2() { }35};36 37extern template struct X1<float>;38 39void use(X0 *x0, X1<int> *x1, X2 *x2, X1<float> *x3) {40 // CHECK-LABEL: define linkonce_odr void @_ZN2X02f1Ev41 x0->f1();42 // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X02f2Ev43 x0->f2();44 // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X02f3Ev45 x0->f3();46 // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X02f5Ev47 X0::f5();48 // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X02f6Ev49 x0->X0::f6();50 // CHECK-LABEL: define linkonce_odr void @_ZN2X1IiE2f1Ev51 x1->f1();52 // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X1IiE2f2Ev53 x1->f2();54 // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X1IiE2f3Ev55 x1->f3();56 // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X1IiE2f4Ev57 x1->f4();58 // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X1IiE2f5Ev59 X1<int>::f5();60 // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X1IiE2f6Ev61 x1->X1::f6();62 // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X22f2Ev63 x2->f2();64 // CHECK-LABEL: define available_externally void @_ZN2X1IfE2f2Ev65 x3->f2();66}67 68namespace test1 {69 struct __attribute__((visibility("default"))) A {70 inline void foo();71 ~A();72 };73 74 void test() {75 A a;76 a.foo();77 }78// CHECK: declare void @_ZN5test11A3fooEv79// CHECK: declare {{.*}} @_ZN5test11AD1Ev80}81 82// PR871383namespace test2 {84 struct A {};85 template <class T> class B {};86 typedef B<A> arg;87 88 namespace ns __attribute__((visibility("default"))) {89 template <class T> inline void foo() {}90 extern template void foo<arg>();91 }92 93 void test() {94 ns::foo<arg>();95 }96 97 // CHECK-LABEL: define available_externally void @_ZN5test22ns3fooINS_1BINS_1AEEEEEvv()98}99 100namespace PR11642 {101 template <typename T>102 class Foo {103 public:104 T foo(T x) { return x; }105 };106 extern template class Foo<int>;107 template class Foo<int>;108 // CHECK-LABEL: define weak_odr noundef i32 @_ZN7PR116423FooIiE3fooEi109}110 111// Test that clang implements the new gcc behaviour for inline functions.112// GCC PR30066.113namespace test3 {114 inline void foo(void) {115 }116 template<typename T>117 inline void zed() {118 }119 template void zed<float>();120 void bar(void) {121 foo();122 zed<int>();123 }124 // CHECK-LABEL: define weak_odr void @_ZN5test33zedIfEEvv125 // CHECK-LABEL: define linkonce_odr hidden void @_ZN5test33fooEv126 // CHECK-LABEL: define linkonce_odr hidden void @_ZN5test33zedIiEEvv127}128 129namespace test4 {130 extern inline __attribute__ ((__gnu_inline__))131 void foo() {}132 void bar() {133 foo();134 }135 // CHECK-LABEL: define available_externally void @_ZN5test43fooE136}137 138namespace test5 {139 // just don't crash.140 template <int> inline void Op();141 class UnaryInstruction {142 UnaryInstruction() {143 Op<0>();144 }145 };146 template <int Idx_nocapture> void Op() {147 }148}149 150namespace test6 {151 // just don't crash.152 template <typename T>153 void f(T x) {154 }155 struct C {156 static void g() {157 f([](){});158 }159 };160 void g() {161 C::g();162 }163}164 165namespace PR34811 {166 template <typename T> void tf() {}167 168 // CHECK-LABEL: define linkonce_odr hidden noundef ptr @_ZN7PR348111fEv(169 inline void *f() {170 auto l = []() {};171 // CHECK-LABEL: define linkonce_odr hidden void @_ZN7PR348112tfIZNS_1fEvEUlvE_EEvv(172 return (void *)&tf<decltype(l)>;173 }174 175 void *p = (void *)f;176}177