Rafael Espindola | 838dc59 | 2013-01-12 06:42:30 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i386-unknown-unknown -std=c++11 -fvisibility-inlines-hidden -emit-llvm -o - %s -O2 -disable-llvm-optzns | FileCheck %s |
John McCall | 479edbc | 2010-10-28 18:10:36 +0000 | [diff] [blame] | 2 | |
| 3 | // The trickery with optimization in the run line is to get IR |
| 4 | // generation to emit available_externally function bodies, but not |
| 5 | // actually inline them (and thus remove the emitted bodies). |
| 6 | |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 7 | struct X0 { |
| 8 | void __attribute__((visibility("default"))) f1() { } |
| 9 | void f2() { } |
| 10 | void f3(); |
| 11 | static void f5() { } |
| 12 | virtual void f6() { } |
| 13 | }; |
| 14 | |
| 15 | inline void X0::f3() { } |
| 16 | |
| 17 | template<typename T> |
| 18 | struct 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 | |
| 27 | template<typename T> |
| 28 | inline void X1<T>::f3() { } |
| 29 | |
| 30 | template<> |
| 31 | inline void X1<int>::f4() { } |
| 32 | |
| 33 | struct __attribute__((visibility("default"))) X2 { |
| 34 | void f2() { } |
| 35 | }; |
| 36 | |
John McCall | 479edbc | 2010-10-28 18:10:36 +0000 | [diff] [blame] | 37 | extern template struct X1<float>; |
| 38 | |
| 39 | void use(X0 *x0, X1<int> *x1, X2 *x2, X1<float> *x3) { |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 40 | // CHECK-LABEL: define linkonce_odr void @_ZN2X02f1Ev |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 41 | x0->f1(); |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 42 | // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X02f2Ev |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 43 | x0->f2(); |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 44 | // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X02f3Ev |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 45 | x0->f3(); |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 46 | // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X02f5Ev |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 47 | X0::f5(); |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 48 | // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X02f6Ev |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 49 | x0->X0::f6(); |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 50 | // CHECK-LABEL: define linkonce_odr void @_ZN2X1IiE2f1Ev |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 51 | x1->f1(); |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 52 | // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X1IiE2f2Ev |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 53 | x1->f2(); |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 54 | // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X1IiE2f3Ev |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 55 | x1->f3(); |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 56 | // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X1IiE2f4Ev |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 57 | x1->f4(); |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 58 | // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X1IiE2f5Ev |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 59 | X1<int>::f5(); |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 60 | // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X1IiE2f6Ev |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 61 | x1->X1::f6(); |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 62 | // CHECK-LABEL: define linkonce_odr hidden void @_ZN2X22f2Ev |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 63 | x2->f2(); |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 64 | // CHECK-LABEL: define available_externally void @_ZN2X1IfE2f2Ev |
John McCall | 479edbc | 2010-10-28 18:10:36 +0000 | [diff] [blame] | 65 | x3->f2(); |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 66 | } |
John McCall | 66cbcf3 | 2010-11-01 01:29:57 +0000 | [diff] [blame] | 67 | |
| 68 | // rdar://problem/8614470 |
| 69 | namespace test1 { |
| 70 | struct __attribute__((visibility("default"))) A { |
| 71 | inline void foo(); |
| 72 | ~A(); |
| 73 | }; |
| 74 | |
| 75 | void test() { |
| 76 | A a; |
| 77 | a.foo(); |
| 78 | } |
| 79 | // CHECK: declare void @_ZN5test11A3fooEv |
Eli Friedman | 065bb5e | 2011-06-15 18:37:44 +0000 | [diff] [blame] | 80 | // CHECK: declare {{.*}} @_ZN5test11AD1Ev |
John McCall | 66cbcf3 | 2010-11-01 01:29:57 +0000 | [diff] [blame] | 81 | } |
John McCall | 90f1450 | 2010-12-10 02:59:44 +0000 | [diff] [blame] | 82 | |
| 83 | // PR8713 |
| 84 | namespace test2 { |
| 85 | struct A {}; |
| 86 | template <class T> class B {}; |
| 87 | typedef B<A> arg; |
| 88 | |
| 89 | namespace ns __attribute__((visibility("default"))) { |
| 90 | template <class T> inline void foo() {} |
| 91 | extern template void foo<arg>(); |
| 92 | } |
| 93 | |
| 94 | void test() { |
| 95 | ns::foo<arg>(); |
| 96 | } |
| 97 | |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 98 | // CHECK-LABEL: define available_externally void @_ZN5test22ns3fooINS_1BINS_1AEEEEEvv() |
John McCall | 90f1450 | 2010-12-10 02:59:44 +0000 | [diff] [blame] | 99 | } |
Rafael Espindola | fedb6ec | 2011-12-27 21:15:28 +0000 | [diff] [blame] | 100 | |
| 101 | namespace PR11642 { |
| 102 | template <typename T> |
| 103 | class Foo { |
| 104 | public: |
| 105 | T foo(T x) { return x; } |
| 106 | }; |
| 107 | extern template class Foo<int>; |
| 108 | template class Foo<int>; |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 109 | // CHECK-LABEL: define weak_odr i32 @_ZN7PR116423FooIiE3fooEi |
Rafael Espindola | fedb6ec | 2011-12-27 21:15:28 +0000 | [diff] [blame] | 110 | } |
Rafael Espindola | b04b731 | 2012-07-13 14:25:36 +0000 | [diff] [blame] | 111 | |
| 112 | // Test that clang implements the new gcc behaviour for inline functions. |
| 113 | // GCC PR30066. |
| 114 | namespace test3 { |
| 115 | inline void foo(void) { |
| 116 | } |
| 117 | template<typename T> |
| 118 | inline void zed() { |
| 119 | } |
| 120 | template void zed<float>(); |
| 121 | void bar(void) { |
| 122 | foo(); |
| 123 | zed<int>(); |
| 124 | } |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 125 | // CHECK-LABEL: define weak_odr void @_ZN5test33zedIfEEvv |
| 126 | // CHECK-LABEL: define linkonce_odr hidden void @_ZN5test33fooEv |
| 127 | // CHECK-LABEL: define linkonce_odr hidden void @_ZN5test33zedIiEEvv |
Rafael Espindola | b04b731 | 2012-07-13 14:25:36 +0000 | [diff] [blame] | 128 | } |
Rafael Espindola | 0142f0c | 2012-10-11 16:32:25 +0000 | [diff] [blame] | 129 | |
| 130 | namespace test4 { |
| 131 | extern inline __attribute__ ((__gnu_inline__)) |
| 132 | void foo() {} |
| 133 | void bar() { |
| 134 | foo(); |
| 135 | } |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 136 | // CHECK-LABEL: define available_externally void @_ZN5test43fooE |
Rafael Espindola | 0142f0c | 2012-10-11 16:32:25 +0000 | [diff] [blame] | 137 | } |
Rafael Espindola | 140aadf | 2012-12-25 07:31:49 +0000 | [diff] [blame] | 138 | |
| 139 | namespace test5 { |
| 140 | // just don't crash. |
| 141 | template <int> inline void Op(); |
| 142 | class UnaryInstruction { |
| 143 | UnaryInstruction() { |
| 144 | Op<0>(); |
| 145 | } |
| 146 | }; |
| 147 | template <int Idx_nocapture> void Op() { |
| 148 | } |
| 149 | } |
Rafael Espindola | 838dc59 | 2013-01-12 06:42:30 +0000 | [diff] [blame] | 150 | |
| 151 | namespace test6 { |
| 152 | // just don't crash. |
| 153 | template <typename T> |
| 154 | void f(T x) { |
| 155 | } |
| 156 | struct C { |
| 157 | static void g() { |
| 158 | f([](){}); |
| 159 | } |
| 160 | }; |
| 161 | void g() { |
| 162 | C::g(); |
| 163 | } |
| 164 | } |