[PATCH] D66933: [ASTImporter] Propagate errors during import of overridden methods.
Balázs Kéri via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 29 02:58:09 PDT 2019
balazske created this revision.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp.
Herald added a reviewer: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: clang.
If importing overridden methods fails for a method it can be seen
incorrectly as non-virtual. To avoid this inconsistency the method
is marked with import error to avoid later use of it.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66933
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
@@ -5183,6 +5183,46 @@
}
}
+TEST_P(ErrorHandlingTest, ImportOfOverriddenMethods) {
+ auto MatchFooA =
+ functionDecl(hasName("foo"), hasAncestor(cxxRecordDecl(hasName("A"))));
+ auto MatchFooB =
+ functionDecl(hasName("foo"), hasAncestor(cxxRecordDecl(hasName("B"))));
+ auto MatchFooC =
+ functionDecl(hasName("foo"), hasAncestor(cxxRecordDecl(hasName("C"))));
+
+ // Provoke import of a method that has overridden methods with import error.
+ TranslationUnitDecl *FromTU = getTuDecl(std::string(R"(
+ struct C;
+ struct A {
+ virtual void foo();
+ void f1(C *);
+ };
+ void A::foo() {
+ )") + ErroneousStmt + R"(
+ }
+ struct B : public A {
+ void foo() override;
+ };
+ struct C : public B {
+ void foo() override;
+ };
+ )",
+ Lang_CXX11);
+ auto *FromFooA = FirstDeclMatcher<FunctionDecl>().match(FromTU, MatchFooA);
+ auto *FromFooB = FirstDeclMatcher<FunctionDecl>().match(FromTU, MatchFooB);
+ auto *FromFooC = FirstDeclMatcher<FunctionDecl>().match(FromTU, MatchFooC);
+
+ FunctionDecl *ImportedFooA = Import(FromFooA, Lang_CXX11);
+ EXPECT_FALSE(ImportedFooA);
+ ASTImporter *Importer = findFromTU(FromFooA)->Importer.get();
+ Optional<ImportError> OptErr = Importer->getImportDeclErrorIfAny(FromFooA);
+ ASSERT_TRUE(OptErr);
+ EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
+ EXPECT_FALSE(Import(FromFooB, Lang_CXX11));
+ EXPECT_FALSE(Import(FromFooC, Lang_CXX11));
+}
+
TEST_P(ASTImporterOptionSpecificTestBase, LambdaInFunctionBody) {
Decl *FromTU = getTuDecl(
R"(
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -639,7 +639,7 @@
return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
}
- void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod);
+ Error ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod);
Expected<FunctionDecl *> FindFunctionTemplateSpecialization(
FunctionDecl *FromFD);
@@ -3370,7 +3370,9 @@
}
if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
- ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod);
+ if (Error Err =
+ ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod))
+ return std::move(Err);
// Import the rest of the chain. I.e. import all subsequent declarations.
for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
@@ -7804,15 +7806,18 @@
*ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
}
-void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
- CXXMethodDecl *FromMethod) {
+Error ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
+ CXXMethodDecl *FromMethod) {
+ Error ImportErrors = Error::success();
for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
if (auto ImportedOrErr = import(FromOverriddenMethod))
ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>(
(*ImportedOrErr)->getCanonicalDecl()));
else
- consumeError(ImportedOrErr.takeError());
+ ImportErrors =
+ joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
}
+ return ImportErrors;
}
ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66933.217807.patch
Type: text/x-patch
Size: 3796 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190829/a596c94d/attachment.bin>
More information about the cfe-commits
mailing list