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