Several fixes/simplifications surrounding how we stream top-level decl AST's.
The following code...
typedef struct cssm_data {} CSSM_DATA, *CSSM_DATA_PTR;
struct Y { int A; };
struct X { int A; } D;
struct X E, F;
...now produces the following output...
> ../../Debug/bin/clang xx.c -ast-print
Read top-level tag decl: 'cssm_data'
typedef struct cssm_data CSSM_DATA;
typedef struct cssm_data *CSSM_DATA_PTR;
Read top-level tag decl: 'Y'
Read top-level tag decl: 'X'
Read top-level variable decl: 'D'
Read top-level variable decl: 'E'
Read top-level variable decl: 'F'
...which is much more accurate than the previous -ast-print output...
typedef struct cssm_data CSSM_DATA;
typedef struct cssm_data CSSM_DATA;
Read top-level variable decl: 'D'
Read top-level variable decl: 'E'
Read top-level variable decl: 'E'
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44421 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 88635c3..9907c06 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -192,7 +192,7 @@
II->setFETokenInfo(New);
}
// Make sure clients iterating over decls see this.
- LastInGroupList.push_back(New);
+ AddTopLevelDecl(New);
return New;
}
@@ -678,7 +678,7 @@
}
if (S->getParent() == 0)
- AddTopLevelDecl(New, LastDeclarator);
+ AddTopLevelDecl(New);
// If any semantic error occurred, mark the decl as invalid.
if (D.getInvalidType() || InvalidDecl)
@@ -973,7 +973,7 @@
NewFD->setNext(II->getFETokenInfo<ScopedDecl>());
II->setFETokenInfo(NewFD);
GlobalScope->AddDecl(NewFD);
- AddTopLevelDecl(NewFD, 0);
+ AddTopLevelDecl(NewFD);
// Allow all of Sema to see that we are entering a method definition.
CurMethodDecl = MDecl;
@@ -1683,6 +1683,12 @@
break;
}
+ // For top-level tag definitions, make sure we chain the the tag decl to
+ // the vardecl. This enables the AST streamer to see both X and D in the
+ // following example: struct X { int A; } D;
+ if (S->getParent() == 0)
+ AddTopLevelDecl(New);
+
// If this has an identifier, add it to the scope stack.
if (Name) {
// The scope passed in may not be a decl scope. Zip up the scope tree until
@@ -1695,7 +1701,7 @@
Name->setFETokenInfo(New);
S->AddDecl(New);
}
-
+
return New;
}
@@ -2456,13 +2462,12 @@
Enum->defineElements(EltList, BestType);
}
-void Sema::AddTopLevelDecl(Decl *current, Decl *last) {
+void Sema::AddTopLevelDecl(Decl *current) {
if (!current) return;
// If this is a top-level decl that is chained to some other (e.g. int A,B,C;)
- // remember this in the LastInGroupList list.
- if (last)
- LastInGroupList.push_back((Decl*)last);
+ // remember this in the TopLevelDeclList list.
+ TopLevelDeclList.push_back((Decl*)current);
}
void Sema::HandleDeclAttribute(Decl *New, AttributeList *rawAttr) {