aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-02-12 17:40:34 +0000
committerDouglas Gregor <dgregor@apple.com>2010-02-12 17:40:34 +0000
commitb37b648b3f2bba4c557a1604ced19b526b25a372 (patch)
tree0e4777e1c739b4699f9283e5e718d5577356ca79
parent104f45c685e5a97306aa72c79f4d068e2999db62 (diff)
Improve representation of tag declarations first declared or defined
within the declarator of another declaration, from Enea Zaffanella! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95991 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/Decl.h17
-rw-r--r--lib/Frontend/PCHReaderDecl.cpp2
-rw-r--r--lib/Frontend/PCHWriterDecl.cpp2
-rw-r--r--lib/Sema/SemaType.cpp5
4 files changed, 15 insertions, 11 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index b9c9d9eb2c..07442896dc 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -1511,9 +1511,10 @@ private:
/// it is a declaration ("struct foo;").
bool IsDefinition : 1;
- /// IsDefinedInDeclarator - True if this tag declaration is
- /// syntactically defined in a declarator.
- bool IsDefinedInDeclarator : 1;
+ /// IsEmbeddedInDeclarator - True if this tag declaration is
+ /// "embedded" (i.e., defined or declared for the very first time)
+ /// in the syntax of a declarator,
+ bool IsEmbeddedInDeclarator : 1;
/// TypedefForAnonDecl - If a TagDecl is anonymous and part of a typedef,
/// this points to the TypedefDecl. Used for mangling.
@@ -1531,7 +1532,7 @@ protected:
assert((DK != Enum || TK == TK_enum) &&"EnumDecl not matched with TK_enum");
TagDeclKind = TK;
IsDefinition = false;
- IsDefinedInDeclarator = false;
+ IsEmbeddedInDeclarator = false;
setPreviousDeclaration(PrevDecl);
}
@@ -1565,11 +1566,11 @@ public:
return IsDefinition;
}
- bool isDefinedInDeclarator() const {
- return IsDefinedInDeclarator;
+ bool isEmbeddedInDeclarator() const {
+ return IsEmbeddedInDeclarator;
}
- void setDefinedInDeclarator(bool isInDeclarator) {
- IsDefinedInDeclarator = isInDeclarator;
+ void setEmbeddedInDeclarator(bool isInDeclarator) {
+ IsEmbeddedInDeclarator = isInDeclarator;
}
/// \brief Whether this declaration declares a type that is
diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp
index 6a93e6c265..625997cac2 100644
--- a/lib/Frontend/PCHReaderDecl.cpp
+++ b/lib/Frontend/PCHReaderDecl.cpp
@@ -117,7 +117,7 @@ void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
TD->setDefinition(Record[Idx++]);
- TD->setDefinedInDeclarator(Record[Idx++]);
+ TD->setEmbeddedInDeclarator(Record[Idx++]);
TD->setTypedefForAnonDecl(
cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp
index 1901b2fad6..d105382b43 100644
--- a/lib/Frontend/PCHWriterDecl.cpp
+++ b/lib/Frontend/PCHWriterDecl.cpp
@@ -115,7 +115,7 @@ void PCHDeclWriter::VisitTagDecl(TagDecl *D) {
Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
Record.push_back(D->isDefinition());
- Record.push_back(D->isDefinedInDeclarator());
+ Record.push_back(D->isEmbeddedInDeclarator());
Writer.AddDeclRef(D->getTypedefForAnonDecl(), Record);
Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Writer.AddSourceLocation(D->getTagKeywordLoc(), Record);
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index ceec5f226f..7911e76d44 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -930,7 +930,10 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
if (!D.isInvalidType() && D.getDeclSpec().isTypeSpecOwned()) {
TagDecl* Owned = cast<TagDecl>((Decl *)D.getDeclSpec().getTypeRep());
- Owned->setDefinedInDeclarator(Owned->isDefinition());
+ // Owned is embedded if it was defined here, or if it is the
+ // very first (i.e., canonical) declaration of this tag type.
+ Owned->setEmbeddedInDeclarator(Owned->isDefinition() ||
+ Owned->isCanonicalDecl());
if (OwnedDecl) *OwnedDecl = Owned;
}
break;