569 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -fblocks %s -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s2 3// CHECK-DAG: private unnamed_addr constant [15 x i8] c"externFunction\00"4// CHECK-DAG: private unnamed_addr constant [26 x i8] c"void NS::externFunction()\00"5// CHECK-DAG: private unnamed_addr constant [49 x i8] c"void functionTemplateExplicitSpecialization(int)\00"6 7// CHECK-DAG: private unnamed_addr constant [95 x i8] c"void SpecializedClassTemplate<char>::memberFunctionTemplate(T, U) const [T = char, U = double]\00"8// CHECK-DAG: private unnamed_addr constant [85 x i8] c"void SpecializedClassTemplate<int>::memberFunctionTemplate(int, U) const [U = float]\00"9// CHECK-DAG: private unnamed_addr constant [57 x i8] c"void NonTypeTemplateParam<42>::size() const [Count = 42]\00"10// CHECK-DAG: private unnamed_addr constant [103 x i8] c"static void ClassWithTemplateTemplateParam<char>::staticMember() [T = char, Param = NS::ClassTemplate]\00"11// CHECK-DAG: private unnamed_addr constant [106 x i8] c"void OuterClass<int *>::MiddleClass::InnerClass<float>::memberFunction(T, U) const [T = int *, U = float]\00"12// CHECK-DAG: private unnamed_addr constant [51 x i8] c"void functionTemplateWithCapturedStmt(T) [T = int]\00"13// CHECK-DAG: private unnamed_addr constant [76 x i8] c"auto functionTemplateWithLambda(int)::(anonymous class)::operator()() const\00"14// CHECK-DAG: private unnamed_addr constant [65 x i8] c"void functionTemplateWithUnnamedTemplateParameter(T) [T = float]\00"15 16// CHECK-DAG: private unnamed_addr constant [60 x i8] c"void functionTemplateExplicitSpecialization(T) [T = double]\00"17// CHECK-DAG: private unnamed_addr constant [52 x i8] c"T *functionTemplateWithCompoundTypes(T *) [T = int]\00" 18// CHECK-DAG: private unnamed_addr constant [54 x i8] c"T functionTemplateWithTemplateReturnType() [T = char]\00"19// CHECK-DAG: private unnamed_addr constant [57 x i8] c"void functionTemplateWithoutParameterList() [T = double]\00"20// CHECK-DAG: private unnamed_addr constant [62 x i8] c"void functionTemplateWithTwoParams(T, U) [T = int, U = float]\00"21 22// CHECK-DAG: private unnamed_addr constant [22 x i8] c"classTemplateFunction\00"23// CHECK-DAG: private unnamed_addr constant [77 x i8] c"void NS::ClassTemplate<NS::Base *>::classTemplateFunction() [T = NS::Base *]\00"24// CHECK-DAG: private unnamed_addr constant [63 x i8] c"void NS::ClassTemplate<int>::classTemplateFunction() [T = int]\00"25 26// CHECK-DAG: private unnamed_addr constant [18 x i8] c"functionTemplate1\00"27// CHECK-DAG: private unnamed_addr constant [53 x i8] c"void NS::Base::functionTemplate1(T) [T = NS::Base *]\00"28// CHECK-DAG: private unnamed_addr constant [46 x i8] c"void NS::Base::functionTemplate1(T) [T = int]\00"29 30// CHECK-DAG: private unnamed_addr constant [23 x i8] c"anonymousUnionFunction\00"31// CHECK-DAG: private unnamed_addr constant [83 x i8] c"void NS::ContainerForAnonymousRecords::(anonymous union)::anonymousUnionFunction()\00"32 33// CHECK-DAG: private unnamed_addr constant [24 x i8] c"anonymousStructFunction\00"34// CHECK-DAG: private unnamed_addr constant [85 x i8] c"void NS::ContainerForAnonymousRecords::(anonymous struct)::anonymousStructFunction()\00"35 36// CHECK-DAG: private unnamed_addr constant [23 x i8] c"anonymousClassFunction\00"37// CHECK-DAG: private unnamed_addr constant [83 x i8] c"void NS::ContainerForAnonymousRecords::(anonymous class)::anonymousClassFunction()\00"38 39// CHECK-DAG: private unnamed_addr constant [12 x i8] c"~Destructor\00"40// CHECK-DAG: private unnamed_addr constant [30 x i8] c"NS::Destructor::~Destructor()\00"41 42// CHECK-DAG: private unnamed_addr constant [12 x i8] c"Constructor\00"43// CHECK-DAG: private unnamed_addr constant [37 x i8] c"NS::Constructor::Constructor(Base *)\00"44// CHECK-DAG: private unnamed_addr constant [34 x i8] c"NS::Constructor::Constructor(int)\00"45// CHECK-DAG: private unnamed_addr constant [31 x i8] c"NS::Constructor::Constructor()\00"46 47// CHECK-DAG: private unnamed_addr constant [16 x i8] c"virtualFunction\00"48// CHECK-DAG: private unnamed_addr constant [44 x i8] c"virtual void NS::Derived::virtualFunction()\00"49 50// CHECK-DAG: private unnamed_addr constant [21 x i8] c"refQualifiedFunction\00"51// CHECK-DAG: private unnamed_addr constant [41 x i8] c"void NS::Base::refQualifiedFunction() &&\00"52// CHECK-DAG: private unnamed_addr constant [40 x i8] c"void NS::Base::refQualifiedFunction() &\00"53 54// CHECK-DAG: private unnamed_addr constant [22 x i8] c"constVolatileFunction\00"55// CHECK-DAG: private unnamed_addr constant [54 x i8] c"void NS::Base::constVolatileFunction() const volatile\00"56 57// CHECK-DAG: private unnamed_addr constant [17 x i8] c"volatileFunction\00"58// CHECK-DAG: private unnamed_addr constant [43 x i8] c"void NS::Base::volatileFunction() volatile\00"59 60// CHECK-DAG: private unnamed_addr constant [14 x i8] c"constFunction\00"61// CHECK-DAG: private unnamed_addr constant [37 x i8] c"void NS::Base::constFunction() const\00"62 63// CHECK-DAG: private unnamed_addr constant [26 x i8] c"functionReturingTemplate2\00"64// CHECK-DAG: private unnamed_addr constant [60 x i8] c"ClassTemplate<Base *> NS::Base::functionReturingTemplate2()\00"65 66// CHECK-DAG: private unnamed_addr constant [26 x i8] c"functionReturingTemplate1\00"67// CHECK-DAG: private unnamed_addr constant [57 x i8] c"ClassTemplate<int> NS::Base::functionReturingTemplate1()\00"68 69// CHECK-DAG: private unnamed_addr constant [23 x i8] c"withTemplateParameter2\00"70// CHECK-DAG: private unnamed_addr constant [61 x i8] c"void NS::Base::withTemplateParameter2(ClassTemplate<Base *>)\00"71 72// CHECK-DAG: private unnamed_addr constant [23 x i8] c"withTemplateParameter1\00"73// CHECK-DAG: private unnamed_addr constant [58 x i8] c"void NS::Base::withTemplateParameter1(ClassTemplate<int>)\00"74 75// CHECK-DAG: private unnamed_addr constant [23 x i8] c"functionReturningClass\00"76// CHECK-DAG: private unnamed_addr constant [41 x i8] c"Base *NS::Base::functionReturningClass()\00"77 78// CHECK-DAG: private unnamed_addr constant [23 x i8] c"functionWithParameters\00"79// CHECK-DAG: private unnamed_addr constant [60 x i8] c"void NS::Base::functionWithParameters(int, float *, Base *)\00"80 81// CHECK-DAG: private unnamed_addr constant [17 x i8] c"variadicFunction\00"82// CHECK-DAG: private unnamed_addr constant [42 x i8] c"void NS::Base::variadicFunction(int, ...)\00"83 84// CHECK-DAG: private unnamed_addr constant [41 x i8] c"virtual void NS::Base::virtualFunction()\00"85 86// CHECK-DAG: private unnamed_addr constant [15 x i8] c"inlineFunction\00"87// CHECK-DAG: private unnamed_addr constant [32 x i8] c"void NS::Base::inlineFunction()\00"88 89// CHECK-DAG: private unnamed_addr constant [15 x i8] c"staticFunction\00"90// CHECK-DAG: private unnamed_addr constant [39 x i8] c"static void NS::Base::staticFunction()\00"91 92// CHECK-DAG: private unnamed_addr constant [26 x i8] c"topLevelNamespaceFunction\00"93// CHECK-DAG: private unnamed_addr constant [59 x i8] c"void ClassInTopLevelNamespace::topLevelNamespaceFunction()\00"94 95// CHECK-DAG: private unnamed_addr constant [27 x i8] c"anonymousNamespaceFunction\00"96// CHECK-DAG: private unnamed_addr constant [84 x i8] c"void (anonymous namespace)::ClassInAnonymousNamespace::anonymousNamespaceFunction()\00"97 98// CHECK-DAG: private unnamed_addr constant [19 x i8] c"localClassFunction\00"99// CHECK-DAG: private unnamed_addr constant [59 x i8] c"void NS::localClass(int)::LocalClass::localClassFunction()\00"100 101 102 103int printf(const char * _Format, ...);104 105class ClassInTopLevelNamespace {106public:107 void topLevelNamespaceFunction() {108 printf("__func__ %s\n", __func__);109 printf("__FUNCTION__ %s\n", __FUNCTION__);110 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);111 }112};113 114namespace {115 116 class ClassInAnonymousNamespace {117 public:118 void anonymousNamespaceFunction() {119 printf("__func__ %s\n", __func__);120 printf("__FUNCTION__ %s\n", __FUNCTION__);121 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);122 }123 };124 125} // end anonymous namespace126 127namespace NS {128 129template<typename T>130class ClassTemplate {131public:132 void classTemplateFunction() {133 printf("__func__ %s\n", __func__);134 printf("__FUNCTION__ %s\n", __FUNCTION__);135 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);136 }137};138 139class Base {140public:141 static void staticFunction() {142 printf("__func__ %s\n", __func__);143 printf("__FUNCTION__ %s\n", __FUNCTION__);144 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);145 }146 147 inline void (inlineFunction)() {148 printf("__func__ %s\n", __func__);149 printf("__FUNCTION__ %s\n", __FUNCTION__);150 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);151 }152 153 virtual void virtualFunction() {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 functionWithParameters(int, float*, Base* 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 Base *functionReturningClass() {166 printf("__func__ %s\n", __func__);167 printf("__FUNCTION__ %s\n", __FUNCTION__);168 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);169 return 0;170 }171 172 void variadicFunction(int, ...) {173 printf("__func__ %s\n", __func__);174 printf("__FUNCTION__ %s\n", __FUNCTION__);175 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);176 }177 178 void withTemplateParameter1(ClassTemplate<int>) {179 printf("__func__ %s\n", __func__);180 printf("__FUNCTION__ %s\n", __FUNCTION__);181 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);182 }183 184 void withTemplateParameter2(ClassTemplate<Base *>) {185 printf("__func__ %s\n", __func__);186 printf("__FUNCTION__ %s\n", __FUNCTION__);187 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);188 }189 190 ClassTemplate<int> functionReturingTemplate1() {191 printf("__func__ %s\n", __func__);192 printf("__FUNCTION__ %s\n", __FUNCTION__);193 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);194 return ClassTemplate<int>();195 }196 197 ClassTemplate<Base *> functionReturingTemplate2() {198 printf("__func__ %s\n", __func__);199 printf("__FUNCTION__ %s\n", __FUNCTION__);200 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);201 return ClassTemplate<Base *>();202 }203 204 template<typename T>205 void functionTemplate1(T t) {206 printf("__func__ %s\n", __func__);207 printf("__FUNCTION__ %s\n", __FUNCTION__);208 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);209 }210 211 void constFunction() const {212 printf("__func__ %s\n", __func__);213 printf("__FUNCTION__ %s\n", __FUNCTION__);214 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);215 }216 217 void volatileFunction() volatile {218 printf("__func__ %s\n", __func__);219 printf("__FUNCTION__ %s\n", __FUNCTION__);220 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);221 }222 223 void constVolatileFunction() const volatile {224 printf("__func__ %s\n", __func__);225 printf("__FUNCTION__ %s\n", __FUNCTION__);226 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);227 }228 229 void refQualifiedFunction() & {230 printf("__func__ %s\n", __func__);231 printf("__FUNCTION__ %s\n", __FUNCTION__);232 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);233 }234 235 void refQualifiedFunction() && {236 printf("__func__ %s\n", __func__);237 printf("__FUNCTION__ %s\n", __FUNCTION__);238 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);239 }240};241 242class Derived : public Base {243public:244 // Virtual function without being explicitly written.245 void virtualFunction() {246 printf("__func__ %s\n", __func__);247 printf("__FUNCTION__ %s\n", __FUNCTION__);248 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);249 }250};251 252class Constructor {253public:254 Constructor() {255 printf("__func__ %s\n", __func__);256 printf("__FUNCTION__ %s\n", __FUNCTION__);257 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);258 }259 260 Constructor(int) {261 printf("__func__ %s\n", __func__);262 printf("__FUNCTION__ %s\n", __FUNCTION__);263 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);264 }265 266 Constructor(Base *) {267 printf("__func__ %s\n", __func__);268 printf("__FUNCTION__ %s\n", __FUNCTION__);269 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);270 }271};272 273class Destructor {274public:275 ~Destructor() {276 printf("__func__ %s\n", __func__);277 printf("__FUNCTION__ %s\n", __FUNCTION__);278 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);279 }280};281 282class ContainerForAnonymousRecords {283public:284 class {285 public:286 void anonymousClassFunction() {287 printf("__func__ %s\n", __func__);288 printf("__FUNCTION__ %s\n", __FUNCTION__);289 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);290 }291 } anonymousClass;292 293 struct {294 void anonymousStructFunction() {295 printf("__func__ %s\n", __func__);296 printf("__FUNCTION__ %s\n", __FUNCTION__);297 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);298 }299 } anonymousStruct;300 301 union {302 void anonymousUnionFunction() {303 printf("__func__ %s\n", __func__);304 printf("__FUNCTION__ %s\n", __FUNCTION__);305 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);306 }307 } anonymousUnion;308};309 310void localClass(int) {311 class LocalClass {312 public:313 void localClassFunction() {314 printf("__func__ %s\n", __func__);315 printf("__FUNCTION__ %s\n", __FUNCTION__);316 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);317 }318 };319 LocalClass lc;320 lc.localClassFunction();321}322 323extern void externFunction() {324 printf("__func__ %s\n", __func__);325 printf("__FUNCTION__ %s\n", __FUNCTION__);326 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);327}328 329} // end NS namespace330 331// additional tests for __PRETTY_FUNCTION__332template <typename T, typename U>333void functionTemplateWithTwoParams(T, U)334{335 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);336}337 338template <typename T>339void functionTemplateWithoutParameterList()340{341 T t = T();342 343 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);344}345 346template <typename T>347T functionTemplateWithTemplateReturnType()348{349 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);350 351 return T();352}353 354template <typename T>355T * functionTemplateWithCompoundTypes(T a[])356{357 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);358 359 return 0;360}361 362template <typename T>363void functionTemplateExplicitSpecialization(T t)364{365 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);366}367 368template <>369void functionTemplateExplicitSpecialization<int>(int i)370{371 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);372}373 374template <typename, typename T>375void functionTemplateWithUnnamedTemplateParameter(T t)376{377 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);378}379 380template <typename T>381void functionTemplateWithLambda(T t)382{383 []() {384 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);385 } ();386}387 388template <typename T>389void functionTemplateWithCapturedStmt(T t)390{391 #pragma clang __debug captured392 {393 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);394 }395}396 397template <typename T>398class OuterClass399{400public:401 class MiddleClass402 {403 public:404 template <typename U>405 class InnerClass406 {407 public:408 void memberFunction(T x, U y) const409 {410 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);411 }412 };413 };414};415 416template <typename T, template <typename> class Param = NS::ClassTemplate>417class ClassWithTemplateTemplateParam418{419public:420 static void staticMember()421 {422 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);423 }424};425 426template <int Count>427class NonTypeTemplateParam428{429public:430 void size() const431 {432 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);433 }434};435 436template <typename T>437class SpecializedClassTemplate438{439public:440 template <typename U>441 void memberFunctionTemplate(T t, U u) const442 {443 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);444 }445};446 447template <>448class SpecializedClassTemplate<int>449{450public:451 template <typename U>452 void memberFunctionTemplate(int i, U u) const453 {454 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);455 }456};457 458int main() {459 ClassInAnonymousNamespace anonymousNamespace;460 anonymousNamespace.anonymousNamespaceFunction();461 462 ClassInTopLevelNamespace topLevelNamespace;463 topLevelNamespace.topLevelNamespaceFunction();464 465 NS::Base::staticFunction();466 467 NS::Base b;468 b.inlineFunction();469 b.virtualFunction();470 b.variadicFunction(0);471 b.functionWithParameters(0, 0, 0);472 b.functionReturningClass();473 474 b.withTemplateParameter1(NS::ClassTemplate<int>());475 b.withTemplateParameter2(NS::ClassTemplate<NS::Base *>());476 b.functionReturingTemplate1();477 b.functionReturingTemplate2();478 b.functionTemplate1<int>(0);479 b.functionTemplate1<NS::Base *>(0);480 b.constFunction();481 b.volatileFunction();482 b.constVolatileFunction();483 b.refQualifiedFunction();484 NS::Base().refQualifiedFunction();485 486 NS::Derived d;487 d.virtualFunction();488 489 NS::ClassTemplate<int> t1;490 t1.classTemplateFunction();491 NS::ClassTemplate<NS::Base *> t2;492 t2.classTemplateFunction();493 494 NS::Constructor c1;495 NS::Constructor c2(0);496 NS::Constructor c3((NS::Base *)0);497 498 {499 NS::Destructor destructor;500 }501 502 NS::ContainerForAnonymousRecords anonymous; 503 anonymous.anonymousClass.anonymousClassFunction();504 anonymous.anonymousStruct.anonymousStructFunction();505 anonymous.anonymousUnion.anonymousUnionFunction();506 507 NS::localClass(0);508 509 NS::externFunction();510 511 // additional tests for __PRETTY_FUNCTION__512 513 functionTemplateWithTwoParams(0, 0.0f);514 functionTemplateWithoutParameterList<double>();515 functionTemplateWithTemplateReturnType<char>();516 int array[] = { 1, 2, 3 };517 functionTemplateWithCompoundTypes(array);518 functionTemplateExplicitSpecialization(0);519 functionTemplateExplicitSpecialization(0.0);520 functionTemplateWithUnnamedTemplateParameter<int, float>(0.0f);521 522 functionTemplateWithLambda<int>(0);523 functionTemplateWithCapturedStmt<int>(0);524 525 OuterClass<int *>::MiddleClass::InnerClass<float> omi;526 omi.memberFunction(0, 0.0f);527 528 ClassWithTemplateTemplateParam<char>::staticMember();529 530 NonTypeTemplateParam<42> ntt;531 ntt.size();532 533 SpecializedClassTemplate<int> sct1;534 sct1.memberFunctionTemplate(0, 0.0f);535 SpecializedClassTemplate<char> sct2;536 sct2.memberFunctionTemplate('0', 0.0);537 538 return 0;539}540 541class XXX {542 XXX();543 ~XXX();544};545 546void XXLog(const char *functionName) { }547 548typedef void (^notify_handler_t)(int token);549 550typedef void (^dispatch_block_t)(void);551 552void notify_register_dispatch(notify_handler_t handler);553 554void _dispatch_once(dispatch_block_t block);555 556XXX::XXX()557{558 _dispatch_once(^{ notify_register_dispatch( ^(int token) { XXLog(__FUNCTION__); }); 559 });560}561// CHECK: define internal {{.*}}void @___ZN3XXXC2Ev_block_invoke_562 563XXX::~XXX()564{565 _dispatch_once(^{ notify_register_dispatch( ^(int token) { XXLog(__FUNCTION__); }); 566 });567}568// CHECK: define internal {{.*}}void @___ZN3XXXD2Ev_block_invoke_569