Fix adding an anonymous namespace in a chained PCH to a namespace from a previous PCH.

Fix anonymous namespaces in PCH.

llvm-svn: 130104
This commit is contained in:
Sebastian Redl 2011-04-24 16:28:13 +00:00
parent ab238a7d18
commit fa1f370b7d
4 changed files with 67 additions and 1 deletions

View File

@ -23,7 +23,8 @@ namespace serialization {
enum DeclUpdateKind {
UPD_CXX_SET_DEFINITIONDATA,
UPD_CXX_ADDED_IMPLICIT_MEMBER,
UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION
UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION,
UPD_CXX_ADDED_ANONYMOUS_NAMESPACE
};
TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT);

View File

@ -1737,6 +1737,16 @@ void ASTDeclReader::UpdateDecl(Decl *D, const RecordData &Record) {
case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
// It will be added to the template's specializations set when loaded.
Reader.GetDecl(Record[Idx++]);
break;
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);
break;
}
}
}
}

View File

@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Serialization/ASTWriter.h"
#include "ASTCommon.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclTemplate.h"
@ -21,6 +22,7 @@
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/Support/ErrorHandling.h"
using namespace clang;
using namespace serialization;
//===----------------------------------------------------------------------===//
// Declaration serialization
@ -705,6 +707,18 @@ void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
}
}
}
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 (Parent->getPCHLevel() > 0) {
ASTWriter::UpdateRecord &Record = Writer.DeclUpdates[Parent];
Record.push_back(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE);
Writer.AddDeclRef(D, Record);
}
}
}
void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {

View File

@ -0,0 +1,41 @@
// no PCH
// RUN: %clang_cc1 -include %s -include %s -fsyntax-only %s
// with PCH
// RUN: %clang_cc1 -chain-include %s -chain-include %s -fsyntax-only %s
#if !defined(PASS1)
#define PASS1
namespace ns {}
#elif !defined(PASS2)
#define PASS2
namespace ns {
namespace {
extern int x;
}
}
namespace {
extern int y;
}
#else
namespace ns {
namespace {
int x;
}
void test() {
(void)x;
}
}
namespace {
int y;
}
void test() {
(void)y;
}
#endif