Page MenuHomePhabricator

File Metadata

Author
baloghadamsoftware
Created
Mar 12 2018, 5:50 AM

D44079-Mod.diff

diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp
index 9e498c0..70e84eb 100644
--- a/lib/AST/ASTImporter.cpp
+++ b/lib/AST/ASTImporter.cpp
@@ -1046,6 +1046,17 @@ void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
Importer.Import(From);
}
+static void setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To,
+ ASTImporter &Importer) {
+ if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
+ auto *ToTypedef =
+ cast_or_null<TypedefNameDecl>(Importer.Import(FromTypedef));
+ assert (ToTypedef && "Failed to import typedef of an anonymous structure");
+
+ To->setTypedefNameForAnonDecl(ToTypedef);
+ }
+}
+
bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To,
ImportDefinitionKind Kind) {
if (To->getDefinition() || To->isBeingDefined()) {
@@ -1056,6 +1067,8 @@ bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To,
}
To->startDefinition();
+
+ setTypedefNameForAnonDecl(From, To, Importer);
// Add base classes.
if (CXXRecordDecl *ToCXX = dyn_cast<CXXRecordDecl>(To)) {
@@ -1185,6 +1198,8 @@ bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To,
To->startDefinition();
+ setTypedefNameForAnonDecl(From, To, Importer);
+
QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From));
if (T.isNull())
return true;
@@ -6578,19 +6593,7 @@ Decl *ASTImporter::Import(Decl *FromD) {
// Record the imported declaration.
ImportedDecls[FromD] = ToD;
-
- if (TagDecl *FromTag = dyn_cast<TagDecl>(FromD)) {
- // Keep track of anonymous tags that have an associated typedef.
- if (TypedefNameDecl *AnonTypedef = FromTag->getTypedefNameForAnonDecl()) {
- auto *ToTypedef = cast_or_null<TypedefNameDecl>(Import(AnonTypedef));
- if (!ToTypedef)
- return nullptr;
- TagDecl *ToTag = cast<TagDecl>(ToD);
- ToTag->setTypedefNameForAnonDecl(ToTypedef);
- }
- }
-
return ToD;
}
diff --git a/test/Analysis/Inputs/ctu-other.cpp b/test/Analysis/Inputs/ctu-other.cpp
index d35b7b2..eceac5a 100644
--- a/test/Analysis/Inputs/ctu-other.cpp
+++ b/test/Analysis/Inputs/ctu-other.cpp
@@ -65,3 +65,6 @@ int chf1(int x) {
return chf2(x);
}
}
+
+typedef struct { int n; } Anonymous;
+int fun_using_anon_struct(int n) { Anonymous anon; anon.n = n; return anon.n; }
diff --git a/test/Analysis/Inputs/externalFnMap.txt b/test/Analysis/Inputs/externalFnMap.txt
index 2c93d3e..805990f 100644
--- a/test/Analysis/Inputs/externalFnMap.txt
+++ b/test/Analysis/Inputs/externalFnMap.txt
@@ -11,3 +11,4 @@ c:@F@h#I# ctu-other.cpp.ast
c:@F@h_chain#I# ctu-chain.cpp.ast
c:@N@chns@S@chcls@F@chf4#I# ctu-chain.cpp.ast
c:@N@chns@F@chf2#I# ctu-chain.cpp.ast
+c:@F@fun_using_anon_struct#I# ctu-other.cpp.ast
diff --git a/test/Analysis/ctu-main.cpp b/test/Analysis/ctu-main.cpp
index cb82cd4..3e9db81 100644
--- a/test/Analysis/ctu-main.cpp
+++ b/test/Analysis/ctu-main.cpp
@@ -40,6 +40,8 @@ namespace chns {
int chf1(int x);
}
+int fun_using_anon_struct(int);
+
int main() {
clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}}
clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}}
@@ -55,4 +57,5 @@ int main() {
clang_analyzer_eval(mycls::embed_cls2().fecl2(0) == -11); // expected-warning{{TRUE}}
clang_analyzer_eval(chns::chf1(4) == 12); // expected-warning{{TRUE}}
+ clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}}
}

Event Timeline