[PATCH] D154701: [ASTImporter] Fix 'isVirtual()' assert failure while importing overridden methods
Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 18 01:34:34 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5b99aa57f74e: [ASTImporter] Fix 'isVirtual()' assert failure while import overridden methods (authored by dingfei <fding at feysh.com>).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154701/new/
https://reviews.llvm.org/D154701
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
@@ -2332,6 +2332,43 @@
EXPECT_EQ(ToDFOutOfClass->getPreviousDecl(), ToDFInClass);
}
+TEST_P(ASTImporterOptionSpecificTestBase,
+ ImportVirtualOverriddenMethodOnALoopTest) {
+ // B::f() calls => f1() ==> C ==> C::f()
+ // \
+ // \---- A::f()
+ //
+ // C::f()'s ImportOverriddenMethods() asserts B::isVirtual(), so B::f()'s
+ // ImportOverriddenMethods() should be completed before B::f()'s body
+ const char *Code =
+ R"(
+ void f1();
+ class A {
+ virtual void f(){}
+ };
+ class B: public A {
+ void f() override {
+ f1();
+ }
+ };
+ class C: public B {
+ void f() override {}
+ };
+ void f1() { C c; }
+ )";
+ Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+
+ auto *FromF = FirstDeclMatcher<CXXMethodDecl>().match(
+ FromTU, cxxMethodDecl(hasName("B::f")));
+
+ auto *ToBF = Import(FromF, Lang_CXX11);
+ EXPECT_TRUE(ToBF->isVirtual());
+
+ auto *ToCF = FirstDeclMatcher<CXXMethodDecl>().match(
+ ToBF->getTranslationUnitDecl(), cxxMethodDecl(hasName("C::f")));
+ EXPECT_TRUE(ToCF->isVirtual());
+}
+
TEST_P(ASTImporterOptionSpecificTestBase, ImportVariableChainInC) {
std::string Code = "static int v; static int v = 0;";
auto Pattern = varDecl(hasName("v"));
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3782,6 +3782,11 @@
if (Error Err = ImportTemplateInformation(D, ToFunction))
return std::move(Err);
+ if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
+ if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction),
+ FromCXXMethod))
+ return std::move(Err);
+
if (D->doesThisDeclarationHaveABody()) {
Error Err = ImportFunctionDeclBody(D, ToFunction);
@@ -3805,11 +3810,6 @@
addDeclToContexts(D, ToFunction);
- if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
- if (Error Err = ImportOverriddenMethods(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) {
ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154701.541394.patch
Type: text/x-patch
Size: 2605 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230718/29d7b6b4/attachment.bin>
More information about the cfe-commits
mailing list