summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2014-09-03 23:11:22 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2014-09-03 23:11:22 +0000
commitf463436d9c02deb870f2ecbba4a69a96f6f9b3d7 (patch)
tree5810630f0ac6f5e0529de79d06c3179787871727 /clang/lib/Serialization
parentc6ab01eccae05aee4bae81a875a6eb88907247c5 (diff)
downloadbcm5719-llvm-f463436d9c02deb870f2ecbba4a69a96f6f9b3d7.tar.gz
bcm5719-llvm-f463436d9c02deb870f2ecbba4a69a96f6f9b3d7.zip
[modules] Make NamespaceAliasDecl redeclarable, as it should be. This fixes
merging of namespace aliases across modules and improves source fidelity. Incidentally also fixes PR20816. llvm-svn: 217103
Diffstat (limited to 'clang/lib/Serialization')
-rw-r--r--clang/lib/Serialization/ASTCommon.cpp10
-rw-r--r--clang/lib/Serialization/ASTReaderDecl.cpp21
-rw-r--r--clang/lib/Serialization/ASTWriterDecl.cpp1
3 files changed, 22 insertions, 10 deletions
diff --git a/clang/lib/Serialization/ASTCommon.cpp b/clang/lib/Serialization/ASTCommon.cpp
index ba20f281ea7..13393225b60 100644
--- a/clang/lib/Serialization/ASTCommon.cpp
+++ b/clang/lib/Serialization/ASTCommon.cpp
@@ -151,7 +151,7 @@ bool serialization::isRedeclarableDeclKind(unsigned Kind) {
switch (static_cast<Decl::Kind>(Kind)) {
case Decl::TranslationUnit: // Special case of a "merged" declaration.
case Decl::Namespace:
- case Decl::NamespaceAlias: // FIXME: Not yet redeclarable, but will be.
+ case Decl::NamespaceAlias:
case Decl::Typedef:
case Decl::TypeAlias:
case Decl::Enum:
@@ -189,8 +189,6 @@ bool serialization::isRedeclarableDeclKind(unsigned Kind) {
case Decl::MSProperty:
case Decl::ObjCIvar:
case Decl::ObjCAtDefsField:
- case Decl::ImplicitParam:
- case Decl::ParmVar:
case Decl::NonTypeTemplateParm:
case Decl::TemplateTemplateParm:
case Decl::Using:
@@ -213,6 +211,12 @@ bool serialization::isRedeclarableDeclKind(unsigned Kind) {
case Decl::Import:
case Decl::OMPThreadPrivate:
return false;
+
+ // These indirectly derive from Redeclarable<T> but are not actually
+ // redeclarable.
+ case Decl::ImplicitParam:
+ case Decl::ParmVar:
+ return false;
}
llvm_unreachable("Unhandled declaration kind");
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 9a5723058a5..1c52b200967 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1205,11 +1205,13 @@ void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
}
void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
+ RedeclarableResult Redecl = VisitRedeclarable(D);
VisitNamedDecl(D);
D->NamespaceLoc = ReadSourceLocation(Record, Idx);
D->IdentLoc = ReadSourceLocation(Record, Idx);
D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
+ mergeRedeclarable(D, Redecl);
}
void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
@@ -2355,10 +2357,10 @@ static bool isSameTemplateParameterList(const TemplateParameterList *X,
/// \brief Determine whether the two declarations refer to the same entity.
static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!");
-
+
if (X == Y)
return true;
-
+
// Must be in the same context.
if (!X->getDeclContext()->getRedeclContext()->Equals(
Y->getDeclContext()->getRedeclContext()))
@@ -2370,11 +2372,11 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
if (TypedefNameDecl *TypedefY = dyn_cast<TypedefNameDecl>(Y))
return X->getASTContext().hasSameType(TypedefX->getUnderlyingType(),
TypedefY->getUnderlyingType());
-
+
// Must have the same kind.
if (X->getKind() != Y->getKind())
return false;
-
+
// Objective-C classes and protocols with the same name always match.
if (isa<ObjCInterfaceDecl>(X) || isa<ObjCProtocolDecl>(X))
return true;
@@ -2396,8 +2398,8 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
}
// Functions with the same type and linkage match.
- // FIXME: This needs to cope with function template specializations,
- // merging of prototyped/non-prototyped functions, etc.
+ // FIXME: This needs to cope with merging of prototyped/non-prototyped
+ // functions, etc.
if (FunctionDecl *FuncX = dyn_cast<FunctionDecl>(X)) {
FunctionDecl *FuncY = cast<FunctionDecl>(Y);
return (FuncX->getLinkageInternal() == FuncY->getLinkageInternal()) &&
@@ -2430,7 +2432,6 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
// Fields with the same name and the same type match.
if (FieldDecl *FDX = dyn_cast<FieldDecl>(X)) {
FieldDecl *FDY = cast<FieldDecl>(Y);
- // FIXME: Diagnose if the types don't match.
// FIXME: Also check the bitwidth is odr-equivalent, if any.
return X->getASTContext().hasSameType(FDX->getType(), FDY->getType());
}
@@ -2446,6 +2447,12 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
return USX->getTargetDecl() == USY->getTargetDecl();
}
+ // Namespace alias definitions with the same target match.
+ if (auto *NAX = dyn_cast<NamespaceAliasDecl>(X)) {
+ auto *NAY = cast<NamespaceAliasDecl>(Y);
+ return NAX->getNamespace()->Equals(NAY->getNamespace());
+ }
+
// FIXME: Many other cases to implement.
return false;
}
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index cc656402d95..0549851cbf2 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -951,6 +951,7 @@ void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
}
void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
+ VisitRedeclarable(D);
VisitNamedDecl(D);
Writer.AddSourceLocation(D->getNamespaceLoc(), Record);
Writer.AddSourceLocation(D->getTargetNameLoc(), Record);
OpenPOWER on IntegriCloud