From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/CodeGenCXX/predefined-expr.cpp | 517 ++++++++++++++++++++++++++++++ 1 file changed, 517 insertions(+) create mode 100644 clang/test/CodeGenCXX/predefined-expr.cpp (limited to 'clang/test/CodeGenCXX/predefined-expr.cpp') diff --git a/clang/test/CodeGenCXX/predefined-expr.cpp b/clang/test/CodeGenCXX/predefined-expr.cpp new file mode 100644 index 0000000..1795ec8 --- /dev/null +++ b/clang/test/CodeGenCXX/predefined-expr.cpp @@ -0,0 +1,517 @@ +// RUN: %clang_cc1 -std=c++11 %s -emit-llvm -o - | FileCheck %s + +// CHECK: private unnamed_addr constant [15 x i8] c"externFunction\00" +// CHECK: private unnamed_addr constant [26 x i8] c"void NS::externFunction()\00" +// CHECK: private unnamed_addr constant [49 x i8] c"void functionTemplateExplicitSpecialization(int)\00" + +// CHECK: private unnamed_addr constant [95 x i8] c"void SpecializedClassTemplate::memberFunctionTemplate(T, U) const [T = char, U = double]\00" +// CHECK: private unnamed_addr constant [85 x i8] c"void SpecializedClassTemplate::memberFunctionTemplate(int, U) const [U = float]\00" +// CHECK: private unnamed_addr constant [57 x i8] c"void NonTypeTemplateParam<42>::size() const [Count = 42]\00" +// CHECK: private unnamed_addr constant [122 x i8] c"static void ClassWithTemplateTemplateParam::staticMember() [T = char, Param = NS::ClassTemplate]\00" +// CHECK: private unnamed_addr constant [106 x i8] c"void OuterClass::MiddleClass::InnerClass::memberFunction(T, U) const [T = int *, U = float]\00" +// CHECK: private unnamed_addr constant [65 x i8] c"void functionTemplateWithUnnamedTemplateParameter(T) [T = float]\00" + +// CHECK: private unnamed_addr constant [60 x i8] c"void functionTemplateExplicitSpecialization(T) [T = double]\00" +// CHECK: private unnamed_addr constant [52 x i8] c"T *functionTemplateWithCompoundTypes(T *) [T = int]\00" +// CHECK: private unnamed_addr constant [54 x i8] c"T functionTemplateWithTemplateReturnType() [T = char]\00" +// CHECK: private unnamed_addr constant [57 x i8] c"void functionTemplateWithoutParameterList() [T = double]\00" +// CHECK: private unnamed_addr constant [62 x i8] c"void functionTemplateWithTwoParams(T, U) [T = int, U = float]\00" + +// CHECK: private unnamed_addr constant [22 x i8] c"classTemplateFunction\00" +// CHECK: private unnamed_addr constant [77 x i8] c"void NS::ClassTemplate::classTemplateFunction() [T = NS::Base *]\00" +// CHECK: private unnamed_addr constant [63 x i8] c"void NS::ClassTemplate::classTemplateFunction() [T = int]\00" + +// CHECK: private unnamed_addr constant [18 x i8] c"functionTemplate1\00" +// CHECK: private unnamed_addr constant [53 x i8] c"void NS::Base::functionTemplate1(T) [T = NS::Base *]\00" +// CHECK: private unnamed_addr constant [46 x i8] c"void NS::Base::functionTemplate1(T) [T = int]\00" + +// CHECK: private unnamed_addr constant [23 x i8] c"anonymousUnionFunction\00" +// CHECK: private unnamed_addr constant [83 x i8] c"void NS::ContainerForAnonymousRecords::::anonymousUnionFunction()\00" + +// CHECK: private unnamed_addr constant [24 x i8] c"anonymousStructFunction\00" +// CHECK: private unnamed_addr constant [85 x i8] c"void NS::ContainerForAnonymousRecords::::anonymousStructFunction()\00" + +// CHECK: private unnamed_addr constant [23 x i8] c"anonymousClassFunction\00" +// CHECK: private unnamed_addr constant [83 x i8] c"void NS::ContainerForAnonymousRecords::::anonymousClassFunction()\00" + +// CHECK: private unnamed_addr constant [12 x i8] c"~Destructor\00" +// CHECK: private unnamed_addr constant [30 x i8] c"NS::Destructor::~Destructor()\00" + +// CHECK: private unnamed_addr constant [12 x i8] c"Constructor\00" +// CHECK: private unnamed_addr constant [41 x i8] c"NS::Constructor::Constructor(NS::Base *)\00" +// CHECK: private unnamed_addr constant [34 x i8] c"NS::Constructor::Constructor(int)\00" +// CHECK: private unnamed_addr constant [31 x i8] c"NS::Constructor::Constructor()\00" + +// CHECK: private unnamed_addr constant [16 x i8] c"virtualFunction\00" +// CHECK: private unnamed_addr constant [44 x i8] c"virtual void NS::Derived::virtualFunction()\00" + +// CHECK: private unnamed_addr constant [21 x i8] c"refQualifiedFunction\00" +// CHECK: private unnamed_addr constant [41 x i8] c"void NS::Base::refQualifiedFunction() &&\00" +// CHECK: private unnamed_addr constant [40 x i8] c"void NS::Base::refQualifiedFunction() &\00" + +// CHECK: private unnamed_addr constant [22 x i8] c"constVolatileFunction\00" +// CHECK: private unnamed_addr constant [54 x i8] c"void NS::Base::constVolatileFunction() const volatile\00" + +// CHECK: private unnamed_addr constant [17 x i8] c"volatileFunction\00" +// CHECK: private unnamed_addr constant [43 x i8] c"void NS::Base::volatileFunction() volatile\00" + +// CHECK: private unnamed_addr constant [14 x i8] c"constFunction\00" +// CHECK: private unnamed_addr constant [37 x i8] c"void NS::Base::constFunction() const\00" + +// CHECK: private unnamed_addr constant [26 x i8] c"functionReturingTemplate2\00" +// CHECK: private unnamed_addr constant [64 x i8] c"ClassTemplate NS::Base::functionReturingTemplate2()\00" + +// CHECK: private unnamed_addr constant [26 x i8] c"functionReturingTemplate1\00" +// CHECK: private unnamed_addr constant [57 x i8] c"ClassTemplate NS::Base::functionReturingTemplate1()\00" + +// CHECK: private unnamed_addr constant [23 x i8] c"withTemplateParameter2\00" +// CHECK: private unnamed_addr constant [65 x i8] c"void NS::Base::withTemplateParameter2(ClassTemplate)\00" + +// CHECK: private unnamed_addr constant [23 x i8] c"withTemplateParameter1\00" +// CHECK: private unnamed_addr constant [58 x i8] c"void NS::Base::withTemplateParameter1(ClassTemplate)\00" + +// CHECK: private unnamed_addr constant [23 x i8] c"functionReturningClass\00" +// CHECK: private unnamed_addr constant [45 x i8] c"NS::Base *NS::Base::functionReturningClass()\00" + +// CHECK: private unnamed_addr constant [23 x i8] c"functionWithParameters\00" +// CHECK: private unnamed_addr constant [64 x i8] c"void NS::Base::functionWithParameters(int, float *, NS::Base *)\00" + +// CHECK: private unnamed_addr constant [17 x i8] c"variadicFunction\00" +// CHECK: private unnamed_addr constant [42 x i8] c"void NS::Base::variadicFunction(int, ...)\00" + +// CHECK: private unnamed_addr constant [41 x i8] c"virtual void NS::Base::virtualFunction()\00" + +// CHECK: private unnamed_addr constant [15 x i8] c"inlineFunction\00" +// CHECK: private unnamed_addr constant [32 x i8] c"void NS::Base::inlineFunction()\00" + +// CHECK: private unnamed_addr constant [15 x i8] c"staticFunction\00" +// CHECK: private unnamed_addr constant [39 x i8] c"static void NS::Base::staticFunction()\00" + +// CHECK: private unnamed_addr constant [26 x i8] c"topLevelNamespaceFunction\00" +// CHECK: private unnamed_addr constant [59 x i8] c"void ClassInTopLevelNamespace::topLevelNamespaceFunction()\00" + +// CHECK: private unnamed_addr constant [27 x i8] c"anonymousNamespaceFunction\00" +// CHECK: private unnamed_addr constant [84 x i8] c"void ::ClassInAnonymousNamespace::anonymousNamespaceFunction()\00" + +// CHECK: private unnamed_addr constant [19 x i8] c"localClassFunction\00" +// CHECK: private unnamed_addr constant [59 x i8] c"void NS::localClass(int)::LocalClass::localClassFunction()\00" + + + +int printf(const char * _Format, ...); + +class ClassInTopLevelNamespace { +public: + void topLevelNamespaceFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } +}; + +namespace { + + class ClassInAnonymousNamespace { + public: + void anonymousNamespaceFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + }; + +} // end anonymous namespace + +namespace NS { + +template +class ClassTemplate { +public: + void classTemplateFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } +}; + +class Base { +public: + static void staticFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + inline void inlineFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + virtual void virtualFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + void functionWithParameters(int, float*, Base* base) { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + Base *functionReturningClass() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + return 0; + } + + void variadicFunction(int, ...) { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + void withTemplateParameter1(ClassTemplate) { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + void withTemplateParameter2(ClassTemplate) { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + ClassTemplate functionReturingTemplate1() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + return ClassTemplate(); + } + + ClassTemplate functionReturingTemplate2() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + return ClassTemplate(); + } + + template + void functionTemplate1(T t) { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + void constFunction() const { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + void volatileFunction() volatile { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + void constVolatileFunction() const volatile { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + void refQualifiedFunction() & { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + void refQualifiedFunction() && { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } +}; + +class Derived : public Base { +public: + // Virtual function without being explicitly written. + void virtualFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } +}; + +class Constructor { +public: + Constructor() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + Constructor(int) { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + + Constructor(Base *) { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } +}; + +class Destructor { +public: + ~Destructor() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } +}; + +class ContainerForAnonymousRecords { +public: + class { + public: + void anonymousClassFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + } anonymousClass; + + struct { + void anonymousStructFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + } anonymousStruct; + + union { + void anonymousUnionFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + } anonymousUnion; +}; + +void localClass(int) { + class LocalClass { + public: + void localClassFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + }; + LocalClass lc; + lc.localClassFunction(); +} + +extern void externFunction() { + printf("__func__ %s\n", __func__); + printf("__FUNCTION__ %s\n", __FUNCTION__); + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); +} + +} // end NS namespace + +// additional tests for __PRETTY_FUNCTION__ +template +void functionTemplateWithTwoParams(T, U) +{ + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); +} + +template +void functionTemplateWithoutParameterList() +{ + T t = T(); + + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); +} + +template +T functionTemplateWithTemplateReturnType() +{ + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + + return T(); +} + +template +T * functionTemplateWithCompoundTypes(T a[]) +{ + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + + return 0; +} + +template +void functionTemplateExplicitSpecialization(T t) +{ + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); +} + +template <> +void functionTemplateExplicitSpecialization(int i) +{ + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); +} + +template +void functionTemplateWithUnnamedTemplateParameter(T t) +{ + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); +} + +template +class OuterClass +{ +public: + class MiddleClass + { + public: + template + class InnerClass + { + public: + void memberFunction(T x, U y) const + { + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } + }; + }; +}; + +template class Param = NS::ClassTemplate> +class ClassWithTemplateTemplateParam +{ +public: + static void staticMember() + { + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } +}; + +template +class NonTypeTemplateParam +{ +public: + void size() const + { + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } +}; + +template +class SpecializedClassTemplate +{ +public: + template + void memberFunctionTemplate(T t, U u) const + { + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } +}; + +template <> +class SpecializedClassTemplate +{ +public: + template + void memberFunctionTemplate(int i, U u) const + { + printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); + } +}; + +int main() { + ClassInAnonymousNamespace anonymousNamespace; + anonymousNamespace.anonymousNamespaceFunction(); + + ClassInTopLevelNamespace topLevelNamespace; + topLevelNamespace.topLevelNamespaceFunction(); + + NS::Base::staticFunction(); + + NS::Base b; + b.inlineFunction(); + b.virtualFunction(); + b.variadicFunction(0); + b.functionWithParameters(0, 0, 0); + b.functionReturningClass(); + + b.withTemplateParameter1(NS::ClassTemplate()); + b.withTemplateParameter2(NS::ClassTemplate()); + b.functionReturingTemplate1(); + b.functionReturingTemplate2(); + b.functionTemplate1(0); + b.functionTemplate1(0); + b.constFunction(); + b.volatileFunction(); + b.constVolatileFunction(); + b.refQualifiedFunction(); + NS::Base().refQualifiedFunction(); + + NS::Derived d; + d.virtualFunction(); + + NS::ClassTemplate t1; + t1.classTemplateFunction(); + NS::ClassTemplate t2; + t2.classTemplateFunction(); + + NS::Constructor c1; + NS::Constructor c2(0); + NS::Constructor c3((NS::Base *)0); + + { + NS::Destructor destructor; + } + + NS::ContainerForAnonymousRecords anonymous; + anonymous.anonymousClass.anonymousClassFunction(); + anonymous.anonymousStruct.anonymousStructFunction(); + anonymous.anonymousUnion.anonymousUnionFunction(); + + NS::localClass(0); + + NS::externFunction(); + + // additional tests for __PRETTY_FUNCTION__ + + functionTemplateWithTwoParams(0, 0.0f); + functionTemplateWithoutParameterList(); + functionTemplateWithTemplateReturnType(); + int array[] = { 1, 2, 3 }; + functionTemplateWithCompoundTypes(array); + functionTemplateExplicitSpecialization(0); + functionTemplateExplicitSpecialization(0.0); + functionTemplateWithUnnamedTemplateParameter(0.0f); + + OuterClass::MiddleClass::InnerClass omi; + omi.memberFunction(0, 0.0f); + + ClassWithTemplateTemplateParam::staticMember(); + + NonTypeTemplateParam<42> ntt; + ntt.size(); + + SpecializedClassTemplate sct1; + sct1.memberFunctionTemplate(0, 0.0f); + SpecializedClassTemplate sct2; + sct2.memberFunctionTemplate('0', 0.0); + + return 0; +} -- cgit v1.2.3