[cfe-commits] r130105 - in /cfe/trunk: include/clang/AST/Decl.h lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriterDecl.cpp test/PCH/chain-late-anonymous-namespace.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Sun Apr 24 09:28:21 PDT 2011
Author: cornedbee
Date: Sun Apr 24 11:28:21 2011
New Revision: 130105
URL: http://llvm.org/viewvc/llvm-project?rev=130105&view=rev
Log:
Set the correct anonymous namespace (must be last reopening), and behave correctly in the presence of the ever-annoying linkage specifications.
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/PCH/chain-late-anonymous-namespace.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=130105&r1=130104&r2=130105&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sun Apr 24 11:28:21 2011
@@ -447,7 +447,7 @@
void setAnonymousNamespace(NamespaceDecl *D) {
assert(!D || D->isAnonymousNamespace());
- assert(!D || D->getParent() == this);
+ assert(!D || D->getParent()->getRedeclContext() == this);
getOriginalNamespace()->OrigOrAnonNamespace.setPointer(D);
}
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=130105&r1=130104&r2=130105&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Sun Apr 24 11:28:21 2011
@@ -1741,10 +1741,15 @@
case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
NamespaceDecl *Anon = cast<NamespaceDecl>(Reader.GetDecl(Record[Idx++]));
- if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
- TU->setAnonymousNamespace(Anon);
- else
- cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
+ // Guard against these being loaded out of original order. Don't use
+ // getNextNamespace(), since it tries to access the context and can't in
+ // the middle of deserialization.
+ if (!Anon->NextNamespace) {
+ if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
+ TU->setAnonymousNamespace(Anon);
+ else
+ cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
+ }
break;
}
}
Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=130105&r1=130104&r2=130105&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Sun Apr 24 11:28:21 2011
@@ -708,11 +708,13 @@
}
}
- if (Writer.hasChain() && D->isOriginalNamespace() &&
- D->isAnonymousNamespace()) {
- // This is an original anonymous namespace. If its parent is in a previous
- // PCH (or is the TU), mark that parent for update.
- Decl *Parent = cast<Decl>(D->getParent()->getPrimaryContext());
+ if (Writer.hasChain() && D->isAnonymousNamespace() && !D->getNextNamespace()){
+ // This is a most recent reopening of the anonymous namespace. If its parent
+ // is in a previous PCH (or is the TU), mark that parent for update, because
+ // the original namespace always points to the latest re-opening of its
+ // anonymous namespace.
+ Decl *Parent = cast<Decl>(
+ D->getParent()->getRedeclContext()->getPrimaryContext());
if (Parent->getPCHLevel() > 0) {
ASTWriter::UpdateRecord &Record = Writer.DeclUpdates[Parent];
Record.push_back(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE);
Modified: cfe/trunk/test/PCH/chain-late-anonymous-namespace.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/chain-late-anonymous-namespace.cpp?rev=130105&r1=130104&r2=130105&view=diff
==============================================================================
--- cfe/trunk/test/PCH/chain-late-anonymous-namespace.cpp (original)
+++ cfe/trunk/test/PCH/chain-late-anonymous-namespace.cpp Sun Apr 24 11:28:21 2011
@@ -6,6 +6,7 @@
#define PASS1
namespace ns {}
+namespace os {}
#elif !defined(PASS2)
#define PASS2
@@ -19,6 +20,16 @@
namespace {
extern int y;
}
+namespace {
+}
+
+namespace os {
+ extern "C" {
+ namespace {
+ extern int z;
+ }
+ }
+}
#else
@@ -38,4 +49,13 @@
(void)y;
}
+namespace os {
+ namespace {
+ int z;
+ }
+ void test() {
+ (void)z;
+ }
+}
+
#endif
More information about the cfe-commits
mailing list