tk1012 created this revision. This patch fixes wrong conflict detections for unnamed structures. Current ASTImporter mistakenly identifies two different unnamed structs as the same one. This is because ASTImporter checks the name of each RecordDecl for the conflict identification and the both of them have the same "unnamed" name. To avoid this, this patch skips the confliction check if SearchName is the null string and also adds a tase case.
https://reviews.llvm.org/D39886 Files: lib/AST/ASTImporter.cpp unittests/AST/ASTImporterTest.cpp Index: unittests/AST/ASTImporterTest.cpp =================================================================== --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -485,6 +485,36 @@ has(atomicType())))))))))); } +TEST(ImportDecl, ImportUnnamedRecordDecl) { + MatchVerifier<Decl> Verifier; + EXPECT_TRUE( + testImport( + "void declToImport() {" + " struct Root {" + " struct { int a; } A;" + " struct { float b; } B;" + " } root;" + "}", + Lang_C, "", Lang_C, Verifier, + functionDecl( + hasBody( + compoundStmt( + has( + declStmt( + has( + recordDecl( + has( + recordDecl( + has( + fieldDecl( + hasType(asString("int")))))), + has( + recordDecl( + has( + fieldDecl( + hasType(asString("float")))))) + ))))))))); +} } // end namespace ast_matchers } // end namespace clang Index: lib/AST/ASTImporter.cpp =================================================================== --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -1631,7 +1631,7 @@ // We may already have a record of the same name; try to find and match it. RecordDecl *AdoptDecl = nullptr; RecordDecl *PrevDecl = nullptr; - if (!DC->isFunctionOrMethod()) { + if (!DC->isFunctionOrMethod() && SearchName.getAsString() != "") { SmallVector<NamedDecl *, 4> ConflictingDecls; SmallVector<NamedDecl *, 2> FoundDecls; DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls);
Index: unittests/AST/ASTImporterTest.cpp =================================================================== --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -485,6 +485,36 @@ has(atomicType())))))))))); } +TEST(ImportDecl, ImportUnnamedRecordDecl) { + MatchVerifier<Decl> Verifier; + EXPECT_TRUE( + testImport( + "void declToImport() {" + " struct Root {" + " struct { int a; } A;" + " struct { float b; } B;" + " } root;" + "}", + Lang_C, "", Lang_C, Verifier, + functionDecl( + hasBody( + compoundStmt( + has( + declStmt( + has( + recordDecl( + has( + recordDecl( + has( + fieldDecl( + hasType(asString("int")))))), + has( + recordDecl( + has( + fieldDecl( + hasType(asString("float")))))) + ))))))))); +} } // end namespace ast_matchers } // end namespace clang Index: lib/AST/ASTImporter.cpp =================================================================== --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -1631,7 +1631,7 @@ // We may already have a record of the same name; try to find and match it. RecordDecl *AdoptDecl = nullptr; RecordDecl *PrevDecl = nullptr; - if (!DC->isFunctionOrMethod()) { + if (!DC->isFunctionOrMethod() && SearchName.getAsString() != "") { SmallVector<NamedDecl *, 4> ConflictingDecls; SmallVector<NamedDecl *, 2> FoundDecls; DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits