/external/clang/test/CodeGenCXX/predefined-expr.cpp

https://gitlab.com/brian0218/rk3188_r-box_android4.2.2_sdk · C++ · 517 lines · 347 code · 98 blank · 72 comment · 1 complexity · 837a8a9e3571add30b6c53ac17143726 MD5 · raw file

  1. // RUN: %clang_cc1 -std=c++11 %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 [49 x i8] c"void functionTemplateExplicitSpecialization(int)\00"
  5. // CHECK: private unnamed_addr constant [95 x i8] c"void SpecializedClassTemplate<char>::memberFunctionTemplate(T, U) const [T = char, U = double]\00"
  6. // CHECK: private unnamed_addr constant [85 x i8] c"void SpecializedClassTemplate<int>::memberFunctionTemplate(int, U) const [U = float]\00"
  7. // CHECK: private unnamed_addr constant [57 x i8] c"void NonTypeTemplateParam<42>::size() const [Count = 42]\00"
  8. // CHECK: private unnamed_addr constant [122 x i8] c"static void ClassWithTemplateTemplateParam<char, NS::ClassTemplate>::staticMember() [T = char, Param = NS::ClassTemplate]\00"
  9. // CHECK: private unnamed_addr constant [106 x i8] c"void OuterClass<int *>::MiddleClass::InnerClass<float>::memberFunction(T, U) const [T = int *, U = float]\00"
  10. // CHECK: private unnamed_addr constant [65 x i8] c"void functionTemplateWithUnnamedTemplateParameter(T) [T = float]\00"
  11. // CHECK: private unnamed_addr constant [60 x i8] c"void functionTemplateExplicitSpecialization(T) [T = double]\00"
  12. // CHECK: private unnamed_addr constant [52 x i8] c"T *functionTemplateWithCompoundTypes(T *) [T = int]\00"
  13. // CHECK: private unnamed_addr constant [54 x i8] c"T functionTemplateWithTemplateReturnType() [T = char]\00"
  14. // CHECK: private unnamed_addr constant [57 x i8] c"void functionTemplateWithoutParameterList() [T = double]\00"
  15. // CHECK: private unnamed_addr constant [62 x i8] c"void functionTemplateWithTwoParams(T, U) [T = int, U = float]\00"
  16. // CHECK: private unnamed_addr constant [22 x i8] c"classTemplateFunction\00"
  17. // CHECK: private unnamed_addr constant [77 x i8] c"void NS::ClassTemplate<NS::Base *>::classTemplateFunction() [T = NS::Base *]\00"
  18. // CHECK: private unnamed_addr constant [63 x i8] c"void NS::ClassTemplate<int>::classTemplateFunction() [T = int]\00"
  19. // CHECK: private unnamed_addr constant [18 x i8] c"functionTemplate1\00"
  20. // CHECK: private unnamed_addr constant [53 x i8] c"void NS::Base::functionTemplate1(T) [T = NS::Base *]\00"
  21. // CHECK: private unnamed_addr constant [46 x i8] c"void NS::Base::functionTemplate1(T) [T = int]\00"
  22. // CHECK: private unnamed_addr constant [23 x i8] c"anonymousUnionFunction\00"
  23. // CHECK: private unnamed_addr constant [83 x i8] c"void NS::ContainerForAnonymousRecords::<anonymous union>::anonymousUnionFunction()\00"
  24. // CHECK: private unnamed_addr constant [24 x i8] c"anonymousStructFunction\00"
  25. // CHECK: private unnamed_addr constant [85 x i8] c"void NS::ContainerForAnonymousRecords::<anonymous struct>::anonymousStructFunction()\00"
  26. // CHECK: private unnamed_addr constant [23 x i8] c"anonymousClassFunction\00"
  27. // CHECK: private unnamed_addr constant [83 x i8] c"void NS::ContainerForAnonymousRecords::<anonymous class>::anonymousClassFunction()\00"
  28. // CHECK: private unnamed_addr constant [12 x i8] c"~Destructor\00"
  29. // CHECK: private unnamed_addr constant [30 x i8] c"NS::Destructor::~Destructor()\00"
  30. // CHECK: private unnamed_addr constant [12 x i8] c"Constructor\00"
  31. // CHECK: private unnamed_addr constant [41 x i8] c"NS::Constructor::Constructor(NS::Base *)\00"
  32. // CHECK: private unnamed_addr constant [34 x i8] c"NS::Constructor::Constructor(int)\00"
  33. // CHECK: private unnamed_addr constant [31 x i8] c"NS::Constructor::Constructor()\00"
  34. // CHECK: private unnamed_addr constant [16 x i8] c"virtualFunction\00"
  35. // CHECK: private unnamed_addr constant [44 x i8] c"virtual void NS::Derived::virtualFunction()\00"
  36. // CHECK: private unnamed_addr constant [21 x i8] c"refQualifiedFunction\00"
  37. // CHECK: private unnamed_addr constant [41 x i8] c"void NS::Base::refQualifiedFunction() &&\00"
  38. // CHECK: private unnamed_addr constant [40 x i8] c"void NS::Base::refQualifiedFunction() &\00"
  39. // CHECK: private unnamed_addr constant [22 x i8] c"constVolatileFunction\00"
  40. // CHECK: private unnamed_addr constant [54 x i8] c"void NS::Base::constVolatileFunction() const volatile\00"
  41. // CHECK: private unnamed_addr constant [17 x i8] c"volatileFunction\00"
  42. // CHECK: private unnamed_addr constant [43 x i8] c"void NS::Base::volatileFunction() volatile\00"
  43. // CHECK: private unnamed_addr constant [14 x i8] c"constFunction\00"
  44. // CHECK: private unnamed_addr constant [37 x i8] c"void NS::Base::constFunction() const\00"
  45. // CHECK: private unnamed_addr constant [26 x i8] c"functionReturingTemplate2\00"
  46. // CHECK: private unnamed_addr constant [64 x i8] c"ClassTemplate<NS::Base *> NS::Base::functionReturingTemplate2()\00"
  47. // CHECK: private unnamed_addr constant [26 x i8] c"functionReturingTemplate1\00"
  48. // CHECK: private unnamed_addr constant [57 x i8] c"ClassTemplate<int> NS::Base::functionReturingTemplate1()\00"
  49. // CHECK: private unnamed_addr constant [23 x i8] c"withTemplateParameter2\00"
  50. // CHECK: private unnamed_addr constant [65 x i8] c"void NS::Base::withTemplateParameter2(ClassTemplate<NS::Base *>)\00"
  51. // CHECK: private unnamed_addr constant [23 x i8] c"withTemplateParameter1\00"
  52. // CHECK: private unnamed_addr constant [58 x i8] c"void NS::Base::withTemplateParameter1(ClassTemplate<int>)\00"
  53. // CHECK: private unnamed_addr constant [23 x i8] c"functionReturningClass\00"
  54. // CHECK: private unnamed_addr constant [45 x i8] c"NS::Base *NS::Base::functionReturningClass()\00"
  55. // CHECK: private unnamed_addr constant [23 x i8] c"functionWithParameters\00"
  56. // CHECK: private unnamed_addr constant [64 x i8] c"void NS::Base::functionWithParameters(int, float *, NS::Base *)\00"
  57. // CHECK: private unnamed_addr constant [17 x i8] c"variadicFunction\00"
  58. // CHECK: private unnamed_addr constant [42 x i8] c"void NS::Base::variadicFunction(int, ...)\00"
  59. // CHECK: private unnamed_addr constant [41 x i8] c"virtual void NS::Base::virtualFunction()\00"
  60. // CHECK: private unnamed_addr constant [15 x i8] c"inlineFunction\00"
  61. // CHECK: private unnamed_addr constant [32 x i8] c"void NS::Base::inlineFunction()\00"
  62. // CHECK: private unnamed_addr constant [15 x i8] c"staticFunction\00"
  63. // CHECK: private unnamed_addr constant [39 x i8] c"static void NS::Base::staticFunction()\00"
  64. // CHECK: private unnamed_addr constant [26 x i8] c"topLevelNamespaceFunction\00"
  65. // CHECK: private unnamed_addr constant [59 x i8] c"void ClassInTopLevelNamespace::topLevelNamespaceFunction()\00"
  66. // CHECK: private unnamed_addr constant [27 x i8] c"anonymousNamespaceFunction\00"
  67. // CHECK: private unnamed_addr constant [84 x i8] c"void <anonymous namespace>::ClassInAnonymousNamespace::anonymousNamespaceFunction()\00"
  68. // CHECK: private unnamed_addr constant [19 x i8] c"localClassFunction\00"
  69. // CHECK: private unnamed_addr constant [59 x i8] c"void NS::localClass(int)::LocalClass::localClassFunction()\00"
  70. int printf(const char * _Format, ...);
  71. class ClassInTopLevelNamespace {
  72. public:
  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. namespace {
  80. class ClassInAnonymousNamespace {
  81. public:
  82. void anonymousNamespaceFunction() {
  83. printf("__func__ %s\n", __func__);
  84. printf("__FUNCTION__ %s\n", __FUNCTION__);
  85. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  86. }
  87. };
  88. } // end anonymous namespace
  89. namespace NS {
  90. template<typename T>
  91. class ClassTemplate {
  92. public:
  93. void classTemplateFunction() {
  94. printf("__func__ %s\n", __func__);
  95. printf("__FUNCTION__ %s\n", __FUNCTION__);
  96. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  97. }
  98. };
  99. class Base {
  100. public:
  101. static void staticFunction() {
  102. printf("__func__ %s\n", __func__);
  103. printf("__FUNCTION__ %s\n", __FUNCTION__);
  104. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  105. }
  106. inline void inlineFunction() {
  107. printf("__func__ %s\n", __func__);
  108. printf("__FUNCTION__ %s\n", __FUNCTION__);
  109. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  110. }
  111. virtual void virtualFunction() {
  112. printf("__func__ %s\n", __func__);
  113. printf("__FUNCTION__ %s\n", __FUNCTION__);
  114. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  115. }
  116. void functionWithParameters(int, float*, Base* base) {
  117. printf("__func__ %s\n", __func__);
  118. printf("__FUNCTION__ %s\n", __FUNCTION__);
  119. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  120. }
  121. Base *functionReturningClass() {
  122. printf("__func__ %s\n", __func__);
  123. printf("__FUNCTION__ %s\n", __FUNCTION__);
  124. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  125. return 0;
  126. }
  127. void variadicFunction(int, ...) {
  128. printf("__func__ %s\n", __func__);
  129. printf("__FUNCTION__ %s\n", __FUNCTION__);
  130. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  131. }
  132. void withTemplateParameter1(ClassTemplate<int>) {
  133. printf("__func__ %s\n", __func__);
  134. printf("__FUNCTION__ %s\n", __FUNCTION__);
  135. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  136. }
  137. void withTemplateParameter2(ClassTemplate<Base *>) {
  138. printf("__func__ %s\n", __func__);
  139. printf("__FUNCTION__ %s\n", __FUNCTION__);
  140. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  141. }
  142. ClassTemplate<int> functionReturingTemplate1() {
  143. printf("__func__ %s\n", __func__);
  144. printf("__FUNCTION__ %s\n", __FUNCTION__);
  145. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  146. return ClassTemplate<int>();
  147. }
  148. ClassTemplate<Base *> functionReturingTemplate2() {
  149. printf("__func__ %s\n", __func__);
  150. printf("__FUNCTION__ %s\n", __FUNCTION__);
  151. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  152. return ClassTemplate<Base *>();
  153. }
  154. template<typename T>
  155. void functionTemplate1(T t) {
  156. printf("__func__ %s\n", __func__);
  157. printf("__FUNCTION__ %s\n", __FUNCTION__);
  158. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  159. }
  160. void constFunction() const {
  161. printf("__func__ %s\n", __func__);
  162. printf("__FUNCTION__ %s\n", __FUNCTION__);
  163. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  164. }
  165. void volatileFunction() volatile {
  166. printf("__func__ %s\n", __func__);
  167. printf("__FUNCTION__ %s\n", __FUNCTION__);
  168. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  169. }
  170. void constVolatileFunction() const volatile {
  171. printf("__func__ %s\n", __func__);
  172. printf("__FUNCTION__ %s\n", __FUNCTION__);
  173. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  174. }
  175. void refQualifiedFunction() & {
  176. printf("__func__ %s\n", __func__);
  177. printf("__FUNCTION__ %s\n", __FUNCTION__);
  178. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  179. }
  180. void refQualifiedFunction() && {
  181. printf("__func__ %s\n", __func__);
  182. printf("__FUNCTION__ %s\n", __FUNCTION__);
  183. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  184. }
  185. };
  186. class Derived : public Base {
  187. public:
  188. // Virtual function without being explicitly written.
  189. void virtualFunction() {
  190. printf("__func__ %s\n", __func__);
  191. printf("__FUNCTION__ %s\n", __FUNCTION__);
  192. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  193. }
  194. };
  195. class Constructor {
  196. public:
  197. Constructor() {
  198. printf("__func__ %s\n", __func__);
  199. printf("__FUNCTION__ %s\n", __FUNCTION__);
  200. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  201. }
  202. Constructor(int) {
  203. printf("__func__ %s\n", __func__);
  204. printf("__FUNCTION__ %s\n", __FUNCTION__);
  205. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  206. }
  207. Constructor(Base *) {
  208. printf("__func__ %s\n", __func__);
  209. printf("__FUNCTION__ %s\n", __FUNCTION__);
  210. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  211. }
  212. };
  213. class Destructor {
  214. public:
  215. ~Destructor() {
  216. printf("__func__ %s\n", __func__);
  217. printf("__FUNCTION__ %s\n", __FUNCTION__);
  218. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  219. }
  220. };
  221. class ContainerForAnonymousRecords {
  222. public:
  223. class {
  224. public:
  225. void anonymousClassFunction() {
  226. printf("__func__ %s\n", __func__);
  227. printf("__FUNCTION__ %s\n", __FUNCTION__);
  228. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  229. }
  230. } anonymousClass;
  231. struct {
  232. void anonymousStructFunction() {
  233. printf("__func__ %s\n", __func__);
  234. printf("__FUNCTION__ %s\n", __FUNCTION__);
  235. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  236. }
  237. } anonymousStruct;
  238. union {
  239. void anonymousUnionFunction() {
  240. printf("__func__ %s\n", __func__);
  241. printf("__FUNCTION__ %s\n", __FUNCTION__);
  242. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  243. }
  244. } anonymousUnion;
  245. };
  246. void localClass(int) {
  247. class LocalClass {
  248. public:
  249. void localClassFunction() {
  250. printf("__func__ %s\n", __func__);
  251. printf("__FUNCTION__ %s\n", __FUNCTION__);
  252. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  253. }
  254. };
  255. LocalClass lc;
  256. lc.localClassFunction();
  257. }
  258. extern void externFunction() {
  259. printf("__func__ %s\n", __func__);
  260. printf("__FUNCTION__ %s\n", __FUNCTION__);
  261. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  262. }
  263. } // end NS namespace
  264. // additional tests for __PRETTY_FUNCTION__
  265. template <typename T, typename U>
  266. void functionTemplateWithTwoParams(T, U)
  267. {
  268. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  269. }
  270. template <typename T>
  271. void functionTemplateWithoutParameterList()
  272. {
  273. T t = T();
  274. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  275. }
  276. template <typename T>
  277. T functionTemplateWithTemplateReturnType()
  278. {
  279. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  280. return T();
  281. }
  282. template <typename T>
  283. T * functionTemplateWithCompoundTypes(T a[])
  284. {
  285. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  286. return 0;
  287. }
  288. template <typename T>
  289. void functionTemplateExplicitSpecialization(T t)
  290. {
  291. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  292. }
  293. template <>
  294. void functionTemplateExplicitSpecialization<int>(int i)
  295. {
  296. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  297. }
  298. template <typename, typename T>
  299. void functionTemplateWithUnnamedTemplateParameter(T t)
  300. {
  301. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  302. }
  303. template <typename T>
  304. class OuterClass
  305. {
  306. public:
  307. class MiddleClass
  308. {
  309. public:
  310. template <typename U>
  311. class InnerClass
  312. {
  313. public:
  314. void memberFunction(T x, U y) const
  315. {
  316. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  317. }
  318. };
  319. };
  320. };
  321. template <typename T, template <typename> class Param = NS::ClassTemplate>
  322. class ClassWithTemplateTemplateParam
  323. {
  324. public:
  325. static void staticMember()
  326. {
  327. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  328. }
  329. };
  330. template <int Count>
  331. class NonTypeTemplateParam
  332. {
  333. public:
  334. void size() const
  335. {
  336. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  337. }
  338. };
  339. template <typename T>
  340. class SpecializedClassTemplate
  341. {
  342. public:
  343. template <typename U>
  344. void memberFunctionTemplate(T t, U u) const
  345. {
  346. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  347. }
  348. };
  349. template <>
  350. class SpecializedClassTemplate<int>
  351. {
  352. public:
  353. template <typename U>
  354. void memberFunctionTemplate(int i, U u) const
  355. {
  356. printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
  357. }
  358. };
  359. int main() {
  360. ClassInAnonymousNamespace anonymousNamespace;
  361. anonymousNamespace.anonymousNamespaceFunction();
  362. ClassInTopLevelNamespace topLevelNamespace;
  363. topLevelNamespace.topLevelNamespaceFunction();
  364. NS::Base::staticFunction();
  365. NS::Base b;
  366. b.inlineFunction();
  367. b.virtualFunction();
  368. b.variadicFunction(0);
  369. b.functionWithParameters(0, 0, 0);
  370. b.functionReturningClass();
  371. b.withTemplateParameter1(NS::ClassTemplate<int>());
  372. b.withTemplateParameter2(NS::ClassTemplate<NS::Base *>());
  373. b.functionReturingTemplate1();
  374. b.functionReturingTemplate2();
  375. b.functionTemplate1<int>(0);
  376. b.functionTemplate1<NS::Base *>(0);
  377. b.constFunction();
  378. b.volatileFunction();
  379. b.constVolatileFunction();
  380. b.refQualifiedFunction();
  381. NS::Base().refQualifiedFunction();
  382. NS::Derived d;
  383. d.virtualFunction();
  384. NS::ClassTemplate<int> t1;
  385. t1.classTemplateFunction();
  386. NS::ClassTemplate<NS::Base *> t2;
  387. t2.classTemplateFunction();
  388. NS::Constructor c1;
  389. NS::Constructor c2(0);
  390. NS::Constructor c3((NS::Base *)0);
  391. {
  392. NS::Destructor destructor;
  393. }
  394. NS::ContainerForAnonymousRecords anonymous;
  395. anonymous.anonymousClass.anonymousClassFunction();
  396. anonymous.anonymousStruct.anonymousStructFunction();
  397. anonymous.anonymousUnion.anonymousUnionFunction();
  398. NS::localClass(0);
  399. NS::externFunction();
  400. // additional tests for __PRETTY_FUNCTION__
  401. functionTemplateWithTwoParams(0, 0.0f);
  402. functionTemplateWithoutParameterList<double>();
  403. functionTemplateWithTemplateReturnType<char>();
  404. int array[] = { 1, 2, 3 };
  405. functionTemplateWithCompoundTypes(array);
  406. functionTemplateExplicitSpecialization(0);
  407. functionTemplateExplicitSpecialization(0.0);
  408. functionTemplateWithUnnamedTemplateParameter<int, float>(0.0f);
  409. OuterClass<int *>::MiddleClass::InnerClass<float> omi;
  410. omi.memberFunction(0, 0.0f);
  411. ClassWithTemplateTemplateParam<char>::staticMember();
  412. NonTypeTemplateParam<42> ntt;
  413. ntt.size();
  414. SpecializedClassTemplate<int> sct1;
  415. sct1.memberFunctionTemplate(0, 0.0f);
  416. SpecializedClassTemplate<char> sct2;
  417. sct2.memberFunctionTemplate('0', 0.0);
  418. return 0;
  419. }