[cfe-commits] r92149 - in /cfe/trunk: lib/AST/Decl.cpp test/CodeGenCXX/predefined-expr.cpp
Sam Weinig
sam.weinig at gmail.com
Thu Dec 24 15:15:04 PST 2009
Author: weinig
Date: Thu Dec 24 17:15:03 2009
New Revision: 92149
URL: http://llvm.org/viewvc/llvm-project?rev=92149&view=rev
Log:
Fix for PR5844. Be explicit about anonymous struct/class/union/namespaces in __PRETTY_FUNCTION__ predefined expression.
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/test/CodeGenCXX/predefined-expr.cpp
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=92149&r1=92148&r2=92149&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Dec 24 17:15:03 2009
@@ -469,6 +469,20 @@
TemplateArgs.flat_size(),
P);
Names.push_back(Spec->getIdentifier()->getNameStart() + TemplateArgsStr);
+ } else if (const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(Ctx)) {
+ if (ND->isAnonymousNamespace())
+ Names.push_back("<anonymous namespace>");
+ else
+ Names.push_back(ND->getNameAsString());
+ } else if (const RecordDecl *RD = dyn_cast<RecordDecl>(Ctx)) {
+ if (!RD->getIdentifier()) {
+ std::string RecordString = "<anonymous ";
+ RecordString += RD->getKindName();
+ RecordString += ">";
+ Names.push_back(RecordString);
+ } else {
+ Names.push_back(RD->getNameAsString());
+ }
} else if (const NamedDecl *ND = dyn_cast<NamedDecl>(Ctx))
Names.push_back(ND->getNameAsString());
else
Modified: cfe/trunk/test/CodeGenCXX/predefined-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/predefined-expr.cpp?rev=92149&r1=92148&r2=92149&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/predefined-expr.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/predefined-expr.cpp Thu Dec 24 17:15:03 2009
@@ -11,6 +11,15 @@
// CHECK: private constant [45 x i8] c"void NS::Base::functionTemplate1(NS::Base *)\00"
// CHECK: private constant [38 x i8] c"void NS::Base::functionTemplate1(int)\00"
+// CHECK: private constant [23 x i8] c"anonymousUnionFunction\00"
+// CHECK: private constant [83 x i8] c"void NS::ContainerForAnonymousRecords::<anonymous union>::anonymousUnionFunction()\00"
+
+// CHECK: private constant [24 x i8] c"anonymousStructFunction\00"
+// CHECK: private constant [85 x i8] c"void NS::ContainerForAnonymousRecords::<anonymous struct>::anonymousStructFunction()\00"
+
+// CHECK: private constant [23 x i8] c"anonymousClassFunction\00"
+// CHECK: private constant [83 x i8] c"void NS::ContainerForAnonymousRecords::<anonymous class>::anonymousClassFunction()\00"
+
// CHECK: private constant [12 x i8] c"~Destructor\00"
// CHECK: private constant [30 x i8] c"NS::Destructor::~Destructor()\00"
@@ -51,8 +60,36 @@
// CHECK: private constant [11 x i8] c"staticFunc\00"
// CHECK: private constant [28 x i8] c"void NS::Base::staticFunc()\00"
+// CHECK: private constant [26 x i8] c"topLevelNamespaceFunction\00"
+// CHECK: private constant [59 x i8] c"void ClassInTopLevelNamespace::topLevelNamespaceFunction()\00"
+
+// CHECK: private constant [27 x i8] c"anonymousNamespaceFunction\00"
+// CHECK: private constant [84 x i8] c"void <anonymous namespace>::ClassInAnonymousNamespace::anonymousNamespaceFunction()\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<typename T>
@@ -167,7 +204,6 @@
printf("__FUNCTION__ %s\n", __FUNCTION__);
printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
}
-
};
class Destructor {
@@ -179,17 +215,51 @@
}
};
+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;
+};
+
extern void externFunction() {
printf("__func__ %s\n", __func__);
printf("__FUNCTION__ %s\n", __FUNCTION__);
printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
}
-}
+} // end NS namespace
int main() {
- NS::Base::staticFunc();
+ ClassInAnonymousNamespace anonymousNamespace;
+ anonymousNamespace.anonymousNamespaceFunction();
+
+ ClassInTopLevelNamespace topLevelNamespace;
+ topLevelNamespace.topLevelNamespaceFunction();
+ NS::Base::staticFunc();
+
NS::Base b;
b.inlineFunction();
b.virtualFunction();
@@ -219,8 +289,13 @@
{
NS::Destructor destructor;
}
-
+
+ NS::ContainerForAnonymousRecords anonymous;
+ anonymous.anonymousClass.anonymousClassFunction();
+ anonymous.anonymousStruct.anonymousStructFunction();
+ anonymous.anonymousUnion.anonymousUnionFunction();
+
NS::externFunction();
-
+
return 0;
}
More information about the cfe-commits
mailing list