From 93a64efcd3358e85ca24da11d6fa765d01dd6e45 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Tue, 30 Oct 2018 20:46:29 +0000 Subject: [PATCH] Revert "[ASTImporter] Reorder fields after structure import is finished" This reverts commit r345545 because it breaks some lldb tests. llvm-svn: 345643 --- clang/lib/AST/ASTImporter.cpp | 46 +++------------------------------ clang/unittests/AST/ASTImporterTest.cpp | 13 +--------- 2 files changed, 4 insertions(+), 55 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 7498e0b..0b1bef1 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -1658,53 +1658,13 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { auto ToDCOrErr = Importer.ImportContext(FromDC); return ToDCOrErr.takeError(); } - - const auto *FromRD = dyn_cast(FromDC); + llvm::SmallVector ImportedDecls; for (auto *From : FromDC->decls()) { ExpectedDecl ImportedOrErr = import(From); - if (!ImportedOrErr) { - // For RecordDecls, failed import of a field will break the layout of the - // structure. Handle it as an error. - if (FromRD) - return ImportedOrErr.takeError(); + if (!ImportedOrErr) // Ignore the error, continue with next Decl. // FIXME: Handle this case somehow better. - else - consumeError(ImportedOrErr.takeError()); - } - } - - // Reorder declarations in RecordDecls because they may have another - // order. Keeping field order is vitable because it determines structure - // layout. - // FIXME: This is an ugly fix. Unfortunately, I cannot come with better - // solution for this issue. We cannot defer expression import here because - // type import can depend on them. - if (!FromRD) - return Error::success(); - - auto ImportedDC = import(cast(FromDC)); - assert(ImportedDC); - auto *ToRD = cast(*ImportedDC); - - for (auto *D : FromRD->decls()) { - if (isa(D) || isa(D)) { - Decl *ToD = Importer.GetAlreadyImportedOrNull(D); - assert(ToRD == ToD->getDeclContext() && ToRD->containsDecl(ToD)); - ToRD->removeDecl(ToD); - } - } - - assert(ToRD->field_empty()); - - for (auto *D : FromRD->decls()) { - if (isa(D) || isa(D)) { - Decl *ToD = Importer.GetAlreadyImportedOrNull(D); - assert(ToRD == ToD->getDeclContext()); - assert(ToRD == ToD->getLexicalDeclContext()); - assert(!ToRD->containsDecl(ToD)); - ToRD->addDeclInternal(ToD); - } + consumeError(ImportedOrErr.takeError()); } return Error::success(); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index de4cbfa..d1683cd 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -1457,7 +1457,7 @@ TEST_P(ASTImporterTestBase, CXXRecordDeclFieldsShouldBeInCorrectOrder) { } TEST_P(ASTImporterTestBase, - CXXRecordDeclFieldOrderShouldNotDependOnImportOrder) { + DISABLED_CXXRecordDeclFieldOrderShouldNotDependOnImportOrder) { Decl *From, *To; std::tie(From, To) = getImportedDecl( // The original recursive algorithm of ASTImporter first imports 'c' then @@ -3767,16 +3767,5 @@ INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportImplicitMethods, INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportVariables, DefaultTestValuesForRunOptions, ); -TEST_P(ImportDecl, ImportFieldOrder) { - MatchVerifier Verifier; - testImport("struct declToImport {" - " int b = a + 2;" - " int a = 5;" - "};", - Lang_CXX11, "", Lang_CXX11, Verifier, - recordDecl(hasFieldOrder({"b", "a"}))); -} - - } // end namespace ast_matchers } // end namespace clang -- 2.7.4