xref: /llvm-project/clang/test/CodeGenCXX/predefined-expr.cpp (revision 4e83bd2795bc7da9c81dd9e8b96ea9e1d7557e53)
1 // RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
2 
3 // CHECK: private constant [15 x i8] c"externFunction\00"
4 // CHECK: private constant [26 x i8] c"void NS::externFunction()\00"
5 
6 // CHECK: private constant [22 x i8] c"classTemplateFunction\00"
7 // CHECK: private constant [60 x i8] c"void NS::ClassTemplate<NS::Base *>::classTemplateFunction()\00"
8 // CHECK: private constant [53 x i8] c"void NS::ClassTemplate<int>::classTemplateFunction()\00"
9 
10 // CHECK: private constant [18 x i8] c"functionTemplate1\00"
11 // CHECK: private constant [45 x i8] c"void NS::Base::functionTemplate1(NS::Base *)\00"
12 // CHECK: private constant [38 x i8] c"void NS::Base::functionTemplate1(int)\00"
13 
14 // CHECK: private constant [23 x i8] c"anonymousUnionFunction\00"
15 // CHECK: private constant [83 x i8] c"void NS::ContainerForAnonymousRecords::<anonymous union>::anonymousUnionFunction()\00"
16 
17 // CHECK: private constant [24 x i8] c"anonymousStructFunction\00"
18 // CHECK: private constant [85 x i8] c"void NS::ContainerForAnonymousRecords::<anonymous struct>::anonymousStructFunction()\00"
19 
20 // CHECK: private constant [23 x i8] c"anonymousClassFunction\00"
21 // CHECK: private constant [83 x i8] c"void NS::ContainerForAnonymousRecords::<anonymous class>::anonymousClassFunction()\00"
22 
23 // CHECK: private constant [12 x i8] c"~Destructor\00"
24 // CHECK: private constant [30 x i8] c"NS::Destructor::~Destructor()\00"
25 
26 // CHECK: private constant [12 x i8] c"Constructor\00"
27 // CHECK: private constant [41 x i8] c"NS::Constructor::Constructor(NS::Base *)\00"
28 // CHECK: private constant [34 x i8] c"NS::Constructor::Constructor(int)\00"
29 // CHECK: private constant [31 x i8] c"NS::Constructor::Constructor()\00"
30 
31 // CHECK: private constant [16 x i8] c"virtualFunction\00"
32 // CHECK: private constant [44 x i8] c"virtual void NS::Derived::virtualFunction()\00"
33 
34 // CHECK: private constant [22 x i8] c"constVolatileFunction\00"
35 // CHECK: private constant [54 x i8] c"void NS::Base::constVolatileFunction() const volatile\00"
36 
37 // CHECK: private constant [17 x i8] c"volatileFunction\00"
38 // CHECK: private constant [43 x i8] c"void NS::Base::volatileFunction() volatile\00"
39 
40 // CHECK: private constant [14 x i8] c"constFunction\00"
41 // CHECK: private constant [37 x i8] c"void NS::Base::constFunction() const\00"
42 
43 // CHECK: private constant [26 x i8] c"functionReturingTemplate2\00"
44 // CHECK: private constant [64 x i8] c"ClassTemplate<NS::Base *> NS::Base::functionReturingTemplate2()\00"
45 
46 // CHECK: private constant [26 x i8] c"functionReturingTemplate1\00"
47 // CHECK: private constant [57 x i8] c"ClassTemplate<int> NS::Base::functionReturingTemplate1()\00"
48 
49 // CHECK: private constant [23 x i8] c"withTemplateParameter2\00"
50 // CHECK: private constant [65 x i8] c"void NS::Base::withTemplateParameter2(ClassTemplate<NS::Base *>)\00"
51 
52 // CHECK: private constant [23 x i8] c"withTemplateParameter1\00"
53 // CHECK: private constant [58 x i8] c"void NS::Base::withTemplateParameter1(ClassTemplate<int>)\00"
54 
55 // CHECK: private constant [23 x i8] c"functionReturningClass\00"
56 // CHECK: private constant [45 x i8] c"NS::Base *NS::Base::functionReturningClass()\00"
57 
58 // CHECK: private constant [23 x i8] c"functionWithParameters\00"
59 // CHECK: private constant [64 x i8] c"void NS::Base::functionWithParameters(int, float *, NS::Base *)\00"
60 
61 // CHECK: private constant [17 x i8] c"variadicFunction\00"
62 // CHECK: private constant [42 x i8] c"void NS::Base::variadicFunction(int, ...)\00"
63 
64 // CHECK: private constant [41 x i8] c"virtual void NS::Base::virtualFunction()\00"
65 
66 // CHECK: private constant [15 x i8] c"inlineFunction\00"
67 // CHECK: private constant [32 x i8] c"void NS::Base::inlineFunction()\00"
68 
69 // CHECK: private constant [15 x i8] c"staticFunction\00"
70 // CHECK: private constant [39 x i8] c"static void NS::Base::staticFunction()\00"
71 
72 // CHECK: private constant [26 x i8] c"topLevelNamespaceFunction\00"
73 // CHECK: private constant [59 x i8] c"void ClassInTopLevelNamespace::topLevelNamespaceFunction()\00"
74 
75 // CHECK: private constant [27 x i8] c"anonymousNamespaceFunction\00"
76 // CHECK: private constant [84 x i8] c"void <anonymous namespace>::ClassInAnonymousNamespace::anonymousNamespaceFunction()\00"
77 
78 int printf(const char * _Format, ...);
79 
80 class ClassInTopLevelNamespace {
81 public:
82   void topLevelNamespaceFunction() {
83     printf("__func__ %s\n", __func__);
84     printf("__FUNCTION__ %s\n", __FUNCTION__);
85     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
86   }
87 };
88 
89 namespace {
90 
91   class ClassInAnonymousNamespace {
92   public:
93     void anonymousNamespaceFunction() {
94       printf("__func__ %s\n", __func__);
95       printf("__FUNCTION__ %s\n", __FUNCTION__);
96       printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
97     }
98   };
99 
100 } // end anonymous namespace
101 
102 namespace NS {
103 
104 template<typename T>
105 class ClassTemplate {
106 public:
107   void classTemplateFunction() {
108     printf("__func__ %s\n", __func__);
109     printf("__FUNCTION__ %s\n", __FUNCTION__);
110     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
111   }
112 };
113 
114 class Base {
115 public:
116   static void staticFunction() {
117     printf("__func__ %s\n", __func__);
118     printf("__FUNCTION__ %s\n", __FUNCTION__);
119     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
120   }
121 
122   inline void inlineFunction() {
123     printf("__func__ %s\n", __func__);
124     printf("__FUNCTION__ %s\n", __FUNCTION__);
125     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
126   }
127 
128   virtual void virtualFunction() {
129     printf("__func__ %s\n", __func__);
130     printf("__FUNCTION__ %s\n", __FUNCTION__);
131     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
132   }
133 
134   void functionWithParameters(int, float*, Base* base) {
135     printf("__func__ %s\n", __func__);
136     printf("__FUNCTION__ %s\n", __FUNCTION__);
137     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
138   }
139 
140   Base *functionReturningClass() {
141     printf("__func__ %s\n", __func__);
142     printf("__FUNCTION__ %s\n", __FUNCTION__);
143     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
144     return 0;
145   }
146 
147   void variadicFunction(int, ...) {
148     printf("__func__ %s\n", __func__);
149     printf("__FUNCTION__ %s\n", __FUNCTION__);
150     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
151   }
152 
153   void withTemplateParameter1(ClassTemplate<int>) {
154     printf("__func__ %s\n", __func__);
155     printf("__FUNCTION__ %s\n", __FUNCTION__);
156     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
157   }
158 
159   void withTemplateParameter2(ClassTemplate<Base *>) {
160     printf("__func__ %s\n", __func__);
161     printf("__FUNCTION__ %s\n", __FUNCTION__);
162     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
163   }
164 
165   ClassTemplate<int> functionReturingTemplate1() {
166     printf("__func__ %s\n", __func__);
167     printf("__FUNCTION__ %s\n", __FUNCTION__);
168     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
169     return ClassTemplate<int>();
170   }
171 
172   ClassTemplate<Base *> functionReturingTemplate2() {
173     printf("__func__ %s\n", __func__);
174     printf("__FUNCTION__ %s\n", __FUNCTION__);
175     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
176     return ClassTemplate<Base *>();
177   }
178 
179   template<typename T>
180   void functionTemplate1(T t) {
181     printf("__func__ %s\n", __func__);
182     printf("__FUNCTION__ %s\n", __FUNCTION__);
183     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
184   }
185 
186   void constFunction() const {
187     printf("__func__ %s\n", __func__);
188     printf("__FUNCTION__ %s\n", __FUNCTION__);
189     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
190   }
191 
192   void volatileFunction() volatile {
193     printf("__func__ %s\n", __func__);
194     printf("__FUNCTION__ %s\n", __FUNCTION__);
195     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
196   }
197 
198   void constVolatileFunction() const volatile {
199     printf("__func__ %s\n", __func__);
200     printf("__FUNCTION__ %s\n", __FUNCTION__);
201     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
202   }
203 };
204 
205 class Derived : public Base {
206 public:
207   // Virtual function without being explicitally written.
208   void virtualFunction() {
209     printf("__func__ %s\n", __func__);
210     printf("__FUNCTION__ %s\n", __FUNCTION__);
211     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
212   }
213 };
214 
215 class Constructor {
216 public:
217   Constructor() {
218     printf("__func__ %s\n", __func__);
219     printf("__FUNCTION__ %s\n", __FUNCTION__);
220     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
221   }
222 
223   Constructor(int) {
224     printf("__func__ %s\n", __func__);
225     printf("__FUNCTION__ %s\n", __FUNCTION__);
226     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
227   }
228 
229   Constructor(Base *) {
230     printf("__func__ %s\n", __func__);
231     printf("__FUNCTION__ %s\n", __FUNCTION__);
232     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
233   }
234 };
235 
236 class Destructor {
237 public:
238   ~Destructor() {
239     printf("__func__ %s\n", __func__);
240     printf("__FUNCTION__ %s\n", __FUNCTION__);
241     printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
242   }
243 };
244 
245 class ContainerForAnonymousRecords {
246 public:
247   class {
248   public:
249     void anonymousClassFunction() {
250       printf("__func__ %s\n", __func__);
251       printf("__FUNCTION__ %s\n", __FUNCTION__);
252       printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
253     }
254   } anonymousClass;
255 
256   struct {
257     void anonymousStructFunction() {
258       printf("__func__ %s\n", __func__);
259       printf("__FUNCTION__ %s\n", __FUNCTION__);
260       printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
261     }
262   } anonymousStruct;
263 
264   union {
265     void anonymousUnionFunction() {
266       printf("__func__ %s\n", __func__);
267       printf("__FUNCTION__ %s\n", __FUNCTION__);
268       printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
269     }
270   } anonymousUnion;
271 };
272 
273 extern void externFunction() {
274   printf("__func__ %s\n", __func__);
275   printf("__FUNCTION__ %s\n", __FUNCTION__);
276   printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
277 }
278 
279 } // end NS namespace
280 
281 int main() {
282   ClassInAnonymousNamespace anonymousNamespace;
283   anonymousNamespace.anonymousNamespaceFunction();
284 
285   ClassInTopLevelNamespace topLevelNamespace;
286   topLevelNamespace.topLevelNamespaceFunction();
287 
288   NS::Base::staticFunction();
289 
290   NS::Base b;
291   b.inlineFunction();
292   b.virtualFunction();
293   b.variadicFunction(0);
294   b.functionWithParameters(0, 0, 0);
295   b.functionReturningClass();
296 
297   b.withTemplateParameter1(NS::ClassTemplate<int>());
298   b.withTemplateParameter2(NS::ClassTemplate<NS::Base *>());
299   b.functionReturingTemplate1();
300   b.functionReturingTemplate2();
301   b.functionTemplate1<int>(0);
302   b.functionTemplate1<NS::Base *>(0);
303   b.constFunction();
304   b.volatileFunction();
305   b.constVolatileFunction();
306 
307   NS::Derived d;
308   d.virtualFunction();
309 
310   NS::ClassTemplate<int> t1;
311   t1.classTemplateFunction();
312   NS::ClassTemplate<NS::Base *> t2;
313   t2.classTemplateFunction();
314 
315   NS::Constructor c1;
316   NS::Constructor c2(0);
317   NS::Constructor c3((NS::Base *)0);
318 
319   {
320     NS::Destructor destructor;
321   }
322 
323   NS::ContainerForAnonymousRecords anonymous;
324   anonymous.anonymousClass.anonymousClassFunction();
325   anonymous.anonymousStruct.anonymousStructFunction();
326   anonymous.anonymousUnion.anonymousUnionFunction();
327 
328   NS::externFunction();
329 
330   return 0;
331 }
332