xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/linkage.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -std=c++11 -O1 -disable-llvm-optzns %s -o - | FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc namespace test1 {
4*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define linkonce_odr void @_ZN5test11fIZNS_1gEvE1SEEvT_(
5*f4a2713aSLionel Sambuc   template <typename T> void f(T) {}
6*f4a2713aSLionel Sambuc   inline void *g() {
7*f4a2713aSLionel Sambuc     struct S {
8*f4a2713aSLionel Sambuc     } s;
9*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(f<S>);
10*f4a2713aSLionel Sambuc   }
11*f4a2713aSLionel Sambuc   void *h() { return g(); }
12*f4a2713aSLionel Sambuc }
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc namespace test2 {
15*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define internal void @_ZN5test21fIZNS_L1gEvE1SEEvT_(
16*f4a2713aSLionel Sambuc   template <typename T> void f(T) {}
17*f4a2713aSLionel Sambuc   static inline void *g() {
18*f4a2713aSLionel Sambuc     struct S {
19*f4a2713aSLionel Sambuc     } s;
20*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(f<S>);
21*f4a2713aSLionel Sambuc   }
22*f4a2713aSLionel Sambuc   void *h() { return g(); }
23*f4a2713aSLionel Sambuc }
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc namespace test3 {
26*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define internal void @_ZN5test31fIZNS_1gEvE1SEEvT_(
27*f4a2713aSLionel Sambuc   template <typename T> void f(T) {}
28*f4a2713aSLionel Sambuc   void *g() {
29*f4a2713aSLionel Sambuc     struct S {
30*f4a2713aSLionel Sambuc     } s;
31*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(f<S>);
32*f4a2713aSLionel Sambuc   }
33*f4a2713aSLionel Sambuc   void *h() { return g(); }
34*f4a2713aSLionel Sambuc }
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc namespace test4 {
37*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define linkonce_odr void @_ZN5test41fIZNS_1gILi1EEEPvvE1SEEvT_(
38*f4a2713aSLionel Sambuc   template <typename T> void f(T) {}
39*f4a2713aSLionel Sambuc   template <int N> inline void *g() {
40*f4a2713aSLionel Sambuc     struct S {
41*f4a2713aSLionel Sambuc     } s;
42*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(f<S>);
43*f4a2713aSLionel Sambuc   }
44*f4a2713aSLionel Sambuc   extern template void *g<1>();
45*f4a2713aSLionel Sambuc   template void *g<1>();
46*f4a2713aSLionel Sambuc }
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc namespace test5 {
49*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define linkonce_odr void @_ZN5test51fIZNS_1gILi1EEEPvvE1SEEvT_(
50*f4a2713aSLionel Sambuc   template <typename T> void f(T) {}
51*f4a2713aSLionel Sambuc   template <int N> inline void *g() {
52*f4a2713aSLionel Sambuc     struct S {
53*f4a2713aSLionel Sambuc     } s;
54*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(f<S>);
55*f4a2713aSLionel Sambuc   }
56*f4a2713aSLionel Sambuc   extern template void *g<1>();
57*f4a2713aSLionel Sambuc   void *h() { return g<1>(); }
58*f4a2713aSLionel Sambuc }
59*f4a2713aSLionel Sambuc 
60*f4a2713aSLionel Sambuc namespace test6 {
61*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define linkonce_odr void @_ZN5test61fIZZNS_1gEvEN1S1hEvE1TEEvv(
62*f4a2713aSLionel Sambuc   template <typename T> void f() {}
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc   inline void *g() {
65*f4a2713aSLionel Sambuc     struct S {
66*f4a2713aSLionel Sambuc       void *h() {
67*f4a2713aSLionel Sambuc         struct T {
68*f4a2713aSLionel Sambuc         };
69*f4a2713aSLionel Sambuc         return (void *)f<T>;
70*f4a2713aSLionel Sambuc       }
71*f4a2713aSLionel Sambuc     } s;
72*f4a2713aSLionel Sambuc     return s.h();
73*f4a2713aSLionel Sambuc   }
74*f4a2713aSLionel Sambuc 
75*f4a2713aSLionel Sambuc   void *h() { return g(); }
76*f4a2713aSLionel Sambuc }
77*f4a2713aSLionel Sambuc 
78*f4a2713aSLionel Sambuc namespace test7 {
79*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define internal void @_ZN5test71fIZZNS_1gEvEN1S1hEvE1TEEvv(
80*f4a2713aSLionel Sambuc   template <typename T> void f() {}
81*f4a2713aSLionel Sambuc 
82*f4a2713aSLionel Sambuc   void *g() {
83*f4a2713aSLionel Sambuc     struct S {
84*f4a2713aSLionel Sambuc       void *h() {
85*f4a2713aSLionel Sambuc         struct T {
86*f4a2713aSLionel Sambuc         };
87*f4a2713aSLionel Sambuc         return (void *)f<T>;
88*f4a2713aSLionel Sambuc       }
89*f4a2713aSLionel Sambuc     } s;
90*f4a2713aSLionel Sambuc     return s.h();
91*f4a2713aSLionel Sambuc   }
92*f4a2713aSLionel Sambuc 
93*f4a2713aSLionel Sambuc   void *h() { return g(); }
94*f4a2713aSLionel Sambuc }
95*f4a2713aSLionel Sambuc 
96*f4a2713aSLionel Sambuc namespace test8 {
97*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define linkonce_odr void @_ZN5test81fIZNS_1gEvE1SEEvT_(
98*f4a2713aSLionel Sambuc   template <typename T> void f(T) {}
99*f4a2713aSLionel Sambuc   inline void *g() {
100*f4a2713aSLionel Sambuc     enum S {
101*f4a2713aSLionel Sambuc     };
102*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(f<S>);
103*f4a2713aSLionel Sambuc   }
104*f4a2713aSLionel Sambuc   void *h() { return g(); }
105*f4a2713aSLionel Sambuc }
106*f4a2713aSLionel Sambuc 
107*f4a2713aSLionel Sambuc namespace test9 {
108*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define linkonce_odr void @_ZN5test91fIPZNS_1gEvE1SEEvT_(
109*f4a2713aSLionel Sambuc   template <typename T> void f(T) {}
110*f4a2713aSLionel Sambuc   inline void *g() {
111*f4a2713aSLionel Sambuc     struct S {
112*f4a2713aSLionel Sambuc     } s;
113*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(f<S*>);
114*f4a2713aSLionel Sambuc   }
115*f4a2713aSLionel Sambuc   void *h() { return g(); }
116*f4a2713aSLionel Sambuc }
117*f4a2713aSLionel Sambuc 
118*f4a2713aSLionel Sambuc namespace test10 {
119*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define linkonce_odr void @_ZN6test101fIPFZNS_1gEvE1SvEEEvT_(
120*f4a2713aSLionel Sambuc   template <typename T> void f(T) {}
121*f4a2713aSLionel Sambuc   inline void *g() {
122*f4a2713aSLionel Sambuc     struct S {
123*f4a2713aSLionel Sambuc     } s;
124*f4a2713aSLionel Sambuc     typedef S(*ftype)();
125*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(f<ftype>);
126*f4a2713aSLionel Sambuc   }
127*f4a2713aSLionel Sambuc   void *h() { return g(); }
128*f4a2713aSLionel Sambuc }
129*f4a2713aSLionel Sambuc 
130*f4a2713aSLionel Sambuc namespace test11 {
131*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define internal void @_ZN6test111fIPFZNS_1gEvE1SPNS_12_GLOBAL__N_11IEEEEvT_(
132*f4a2713aSLionel Sambuc   namespace {
133*f4a2713aSLionel Sambuc     struct I {
134*f4a2713aSLionel Sambuc     };
135*f4a2713aSLionel Sambuc   }
136*f4a2713aSLionel Sambuc 
137*f4a2713aSLionel Sambuc   template <typename T> void f(T) {}
138*f4a2713aSLionel Sambuc   inline void *g() {
139*f4a2713aSLionel Sambuc     struct S {
140*f4a2713aSLionel Sambuc     };
141*f4a2713aSLionel Sambuc     typedef S(*ftype)(I * x);
142*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(f<ftype>);
143*f4a2713aSLionel Sambuc   }
144*f4a2713aSLionel Sambuc   void *h() { return g(); }
145*f4a2713aSLionel Sambuc }
146*f4a2713aSLionel Sambuc 
147*f4a2713aSLionel Sambuc namespace test12 {
148*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define linkonce_odr void @_ZN6test123fooIZNS_3barIZNS_3zedEvE2S2EEPvvE2S1EEvv
149*f4a2713aSLionel Sambuc   template <typename T> void foo() {}
150*f4a2713aSLionel Sambuc   template <typename T> inline void *bar() {
151*f4a2713aSLionel Sambuc     enum S1 {
152*f4a2713aSLionel Sambuc     };
153*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(foo<S1>);
154*f4a2713aSLionel Sambuc   }
155*f4a2713aSLionel Sambuc   inline void *zed() {
156*f4a2713aSLionel Sambuc     enum S2 {
157*f4a2713aSLionel Sambuc     };
158*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(bar<S2>);
159*f4a2713aSLionel Sambuc   }
160*f4a2713aSLionel Sambuc   void *h() { return zed(); }
161*f4a2713aSLionel Sambuc }
162*f4a2713aSLionel Sambuc 
163*f4a2713aSLionel Sambuc namespace test13 {
164*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define linkonce_odr void @_ZZN6test133fooEvEN1S3barEv(
165*f4a2713aSLionel Sambuc   inline void *foo() {
166*f4a2713aSLionel Sambuc     struct S {
167*f4a2713aSLionel Sambuc       static void bar() {}
168*f4a2713aSLionel Sambuc     };
169*f4a2713aSLionel Sambuc     return (void *)S::bar;
170*f4a2713aSLionel Sambuc   }
171*f4a2713aSLionel Sambuc   void *zed() { return foo(); }
172*f4a2713aSLionel Sambuc }
173*f4a2713aSLionel Sambuc 
174*f4a2713aSLionel Sambuc namespace test14 {
175*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define linkonce_odr void @_ZN6test143fooIZNS_1fEvE1SE3barILPS1_0EEEvv(
176*f4a2713aSLionel Sambuc   template <typename T> struct foo {
177*f4a2713aSLionel Sambuc     template <T *P> static void bar() {}
178*f4a2713aSLionel Sambuc     static void *g() { return (void *)bar<nullptr>; }
179*f4a2713aSLionel Sambuc   };
180*f4a2713aSLionel Sambuc   inline void *f() {
181*f4a2713aSLionel Sambuc     struct S {
182*f4a2713aSLionel Sambuc     };
183*f4a2713aSLionel Sambuc     return foo<S>::g();
184*f4a2713aSLionel Sambuc   }
185*f4a2713aSLionel Sambuc   void h() { f(); }
186*f4a2713aSLionel Sambuc }
187*f4a2713aSLionel Sambuc 
188*f4a2713aSLionel Sambuc namespace test15 {
189*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define linkonce_odr void @_ZN6test153zedIZNS_3fooIiEEPvvE3barEEvv(
190*f4a2713aSLionel Sambuc   template <class T> void zed() {}
191*f4a2713aSLionel Sambuc   template <class T> void *foo() {
192*f4a2713aSLionel Sambuc     class bar {
193*f4a2713aSLionel Sambuc     };
194*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(zed<bar>);
195*f4a2713aSLionel Sambuc   }
196*f4a2713aSLionel Sambuc   void test() { foo<int>(); }
197*f4a2713aSLionel Sambuc }
198*f4a2713aSLionel Sambuc 
199*f4a2713aSLionel Sambuc namespace test16 {
200*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define linkonce_odr void @_ZN6test163zedIZNS_3fooIiE3barEvE1SEEvv(
201*f4a2713aSLionel Sambuc   template <class T> void zed() {}
202*f4a2713aSLionel Sambuc   template <class T> struct foo {
203*f4a2713aSLionel Sambuc     static void *bar();
204*f4a2713aSLionel Sambuc   };
205*f4a2713aSLionel Sambuc   template <class T> void *foo<T>::bar() {
206*f4a2713aSLionel Sambuc     class S {
207*f4a2713aSLionel Sambuc     };
208*f4a2713aSLionel Sambuc     return reinterpret_cast<void *>(zed<S>);
209*f4a2713aSLionel Sambuc   }
210*f4a2713aSLionel Sambuc   void *test() { return foo<int>::bar(); }
211*f4a2713aSLionel Sambuc }
212*f4a2713aSLionel Sambuc 
213*f4a2713aSLionel Sambuc namespace test17 {
214*f4a2713aSLionel Sambuc   // CHECK-DAG: @_ZZN6test173fooILi42EEEPivE3bar = linkonce_odr
215*f4a2713aSLionel Sambuc   // CHECK-DAG-LABEL: define weak_odr i32* @_ZN6test173fooILi42EEEPiv(
216*f4a2713aSLionel Sambuc   template<int I>
217*f4a2713aSLionel Sambuc   int *foo() {
218*f4a2713aSLionel Sambuc     static int bar;
219*f4a2713aSLionel Sambuc     return &bar;
220*f4a2713aSLionel Sambuc   }
221*f4a2713aSLionel Sambuc   template int *foo<42>();
222*f4a2713aSLionel Sambuc }
223