Author: balazske Date: Mon Sep 2 00:17:01 2019 New Revision: 370621 URL: http://llvm.org/viewvc/llvm-project?rev=370621&view=rev Log: [ASTImporter] At import of records re-order indirect fields too.
Summary: Correct order of fields and indirect fields in imported RecordDecl is needed for correct work of record layout calculations. Reviewers: martong, a.sidorin, shafik, a_sidorin Reviewed By: martong, a_sidorin Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66866 Modified: cfe/trunk/lib/AST/ASTImporter.cpp cfe/trunk/unittests/AST/ASTImporterTest.cpp Modified: cfe/trunk/lib/AST/ASTImporter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=370621&r1=370620&r2=370621&view=diff ============================================================================== --- cfe/trunk/lib/AST/ASTImporter.cpp (original) +++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Sep 2 00:17:01 2019 @@ -1702,7 +1702,7 @@ ASTNodeImporter::ImportDeclContext(DeclC // Remove all declarations, which may be in wrong order in the // lexical DeclContext and then add them in the proper order. for (auto *D : FromRD->decls()) { - if (isa<FieldDecl>(D) || isa<FriendDecl>(D)) { + if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D)) { assert(D && "DC contains a null decl"); Decl *ToD = Importer.GetAlreadyImportedOrNull(D); // Remove only the decls which we successfully imported. Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=370621&r1=370620&r2=370621&view=diff ============================================================================== --- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original) +++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Mon Sep 2 00:17:01 2019 @@ -1421,12 +1421,15 @@ TEST_P(ASTImporterOptionSpecificTestBase AST_MATCHER_P(RecordDecl, hasFieldOrder, std::vector<StringRef>, Order) { size_t Index = 0; - for (FieldDecl *Field : Node.fields()) { - if (Index == Order.size()) - return false; - if (Field->getName() != Order[Index]) - return false; - ++Index; + for (Decl *D : Node.decls()) { + if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D)) { + auto *ND = cast<NamedDecl>(D); + if (Index == Order.size()) + return false; + if (ND->getName() != Order[Index]) + return false; + ++Index; + } } return Index == Order.size(); } @@ -1493,6 +1496,31 @@ TEST_P(ASTImporterOptionSpecificTestBase Verifier.match(To, cxxRecordDecl(hasFieldOrder({"a", "b", "c"})))); } +TEST_P(ASTImporterOptionSpecificTestBase, + CXXRecordDeclFieldAndIndirectFieldOrder) { + Decl *From, *To; + std::tie(From, To) = getImportedDecl( + // First field is "a", then the field for unnamed union, then "b" and "c" + // from it (indirect fields), then "d". + R"s( + struct declToImport { + int a = d; + union { + int b; + int c; + }; + int d; + }; + )s", + Lang_CXX11, "", Lang_CXX11); + + MatchVerifier<Decl> Verifier; + ASSERT_TRUE(Verifier.match( + From, cxxRecordDecl(hasFieldOrder({"a", "", "b", "c", "d"})))); + EXPECT_TRUE(Verifier.match( + To, cxxRecordDecl(hasFieldOrder({"a", "", "b", "c", "d"})))); +} + TEST_P(ASTImporterOptionSpecificTestBase, ShouldImportImplicitCXXRecordDecl) { Decl *From, *To; std::tie(From, To) = getImportedDecl( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits