jcsxky created this revision.
jcsxky added a reviewer: danix800.
jcsxky added a project: clang.
Herald added a subscriber: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
jcsxky requested review of this revision.
Herald added a subscriber: cfe-commits.

when import a class contains two anonymous unions, constructor accesses member 
in the second union would lead to import the second union, after that, import 
the first union will lead to conflict, skip when two union are both anonymous.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155537

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


Index: clang/unittests/AST/ASTImporterTest.cpp
===================================================================
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -2462,6 +2462,36 @@
                 functionDecl(hasName("f"), hasDescendant(declRefExpr()))))));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+       ImportAnnonymousUnionInClassTest) {
+  const char *Code =
+      R"(
+      class B{
+
+      public:
+
+        B(){
+          c=1;
+        }
+
+        void foo1(){}
+
+      private:
+        union{
+          int a;
+          int b;
+        };
+        union {
+          int c;
+          int d;
+        };
+      };
+      )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  EXPECT_TRUE(FromTU);
+}
+
+
 struct ImportFunctionTemplates : ASTImporterOptionSpecificTestBase {};
 
 TEST_P(ImportFunctionTemplates, ImportFunctionTemplateInRecordDeclTwice) {
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3861,7 +3861,9 @@
           ASTImporter::getFieldIndex(D) !=
           ASTImporter::getFieldIndex(FoundField))
         continue;
-
+      if (D->isAnonymousStructOrUnion() && 
FoundField->isAnonymousStructOrUnion()) {
+        continue;
+      }
       if (Importer.IsStructurallyEquivalent(D->getType(),
                                             FoundField->getType())) {
         Importer.MapImported(D, FoundField);


Index: clang/unittests/AST/ASTImporterTest.cpp
===================================================================
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -2462,6 +2462,36 @@
                 functionDecl(hasName("f"), hasDescendant(declRefExpr()))))));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+       ImportAnnonymousUnionInClassTest) {
+  const char *Code =
+      R"(
+      class B{
+
+      public:
+
+        B(){
+          c=1;
+        }
+
+        void foo1(){}
+
+      private:
+        union{
+          int a;
+          int b;
+        };
+        union {
+          int c;
+          int d;
+        };
+      };
+      )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  EXPECT_TRUE(FromTU);
+}
+
+
 struct ImportFunctionTemplates : ASTImporterOptionSpecificTestBase {};
 
 TEST_P(ImportFunctionTemplates, ImportFunctionTemplateInRecordDeclTwice) {
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3861,7 +3861,9 @@
           ASTImporter::getFieldIndex(D) !=
           ASTImporter::getFieldIndex(FoundField))
         continue;
-
+      if (D->isAnonymousStructOrUnion() && FoundField->isAnonymousStructOrUnion()) {
+        continue;
+      }
       if (Importer.IsStructurallyEquivalent(D->getType(),
                                             FoundField->getType())) {
         Importer.MapImported(D, FoundField);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to