predefined-expr.cpp 12 KB

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