[PATCH] D48773: [ASTImporter] Fix import of objects with anonymous types

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 29 08:30:44 PDT 2018


martong created this revision.
martong added reviewers: a.sidorin, balazske, r.stahl.
Herald added subscribers: cfe-commits, dkrupp, rnkovacs.

Currently, anonymous types are merged into the same redecl chain even if they
are structurally inequivalent. This results that global objects are not
imported, if there are at least two global objects with different anonymous
types. This patch provides a fix.


Repository:
  rC Clang

https://reviews.llvm.org/D48773

Files:
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterTest.cpp


Index: unittests/AST/ASTImporterTest.cpp
===================================================================
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1622,6 +1622,35 @@
                     .match(ToTU, classTemplateSpecializationDecl()));
 }
 
+TEST_P(ASTImporterTestBase, ObjectsWithUnnamedStructType) {
+  Decl *FromTU = getTuDecl(
+      R"(
+      struct { int a; int b; } object0 = { 2, 3 };
+      struct { int x; int y; int z; } object1;
+      )",
+      Lang_CXX, "input0.cc");
+
+  auto getRecordDecl = [](VarDecl *VD) {
+    auto *ET = cast<ElaboratedType>(VD->getType().getTypePtr());
+    return cast<RecordType>(ET->getNamedType().getTypePtr())->getDecl();
+  };
+
+  auto *Obj0 =
+      FirstDeclMatcher<VarDecl>().match(FromTU, varDecl(hasName("object0")));
+  auto *From0 = getRecordDecl(Obj0);
+  auto *Obj1 =
+      FirstDeclMatcher<VarDecl>().match(FromTU, varDecl(hasName("object1")));
+  auto *From1 = getRecordDecl(Obj1);
+
+  auto *To0 = Import(From0, Lang_CXX);
+  auto *To1 = Import(From1, Lang_CXX);
+
+  EXPECT_TRUE(To0);
+  EXPECT_TRUE(To1);
+  EXPECT_NE(To0, To1);
+  EXPECT_NE(To0->getCanonicalDecl(), To1->getCanonicalDecl());
+}
+
 struct ImportFunctions : ASTImporterTestBase {};
 
 TEST_P(ImportFunctions,
Index: lib/AST/ASTImporter.cpp
===================================================================
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -2082,6 +2082,9 @@
               if (*Index1 != *Index2)
                 continue;
             }
+          } else {
+            if (!IsStructuralMatch(D, FoundRecord, false))
+              continue;
           }
         }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48773.153500.patch
Type: text/x-patch
Size: 1670 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180629/a70464e2/attachment.bin>


More information about the cfe-commits mailing list