[PATCH] D39886: [ASTImporter] Fix wrong conflict detections for unnamed structures
Takafumi Kubota via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 9 20:02:51 PST 2017
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39886.122390.patch
Type: text/x-patch
Size: 1896 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171110/d6554ef6/attachment.bin>
More information about the cfe-commits
mailing list