Skip to content

Commit c94b559

Browse files
authored
Merge pull request #4885 from Michael137/95803948
[swift/release/5.7][LLDB][ClangASTImporter] Revert "[lldb] Disable minimal import mode for RecordDecls that back FieldDecls"
2 parents 15cd482 + 4e3cdfd commit c94b559

File tree

6 files changed

+44
-32
lines changed

6 files changed

+44
-32
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -888,37 +888,6 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) {
888888
LLDB_LOG(log, "[ClangASTImporter] Complete definition not found");
889889
}
890890

891-
// Disable the minimal import for fields that have record types. There is
892-
// no point in minimally importing the record behind their type as Clang
893-
// will anyway request their definition when the FieldDecl is added to the
894-
// RecordDecl (as Clang will query the FieldDecl's type for things such
895-
// as a deleted constexpr destructor).
896-
// By importing the type ahead of time we avoid some corner cases where
897-
// the FieldDecl's record is importing in the middle of Clang's
898-
// `DeclContext::addDecl` logic.
899-
if (clang::FieldDecl *fd = dyn_cast<FieldDecl>(From)) {
900-
// This is only necessary because we do the 'minimal import'. Remove this
901-
// once LLDB stopped using that mode.
902-
assert(isMinimalImport() && "Only necessary for minimal import");
903-
QualType field_type = fd->getType();
904-
if (field_type->isRecordType()) {
905-
// First get the underlying record and minimally import it.
906-
clang::TagDecl *record_decl = field_type->getAsTagDecl();
907-
llvm::Expected<Decl *> imported = Import(record_decl);
908-
if (!imported)
909-
return imported.takeError();
910-
// Check how/if the import got redirected to a different AST. Now
911-
// import the definition of what was actually imported. If there is no
912-
// origin then that means the record was imported by just picking a
913-
// compatible type in the target AST (in which case there is no more
914-
// importing to do).
915-
if (clang::Decl *origin = m_master.GetDeclOrigin(*imported).decl) {
916-
if (llvm::Error def_err = ImportDefinition(record_decl))
917-
return std::move(def_err);
918-
}
919-
}
920-
}
921-
922891
return ASTImporter::ImportImpl(From);
923892
}
924893

lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,10 @@ void ClangASTSource::FindExternalLexicalDecls(
480480
decl->getDeclKindName(), ast_dump);
481481
}
482482

483-
CopyDecl(decl);
483+
Decl *copied_decl = CopyDecl(decl);
484+
485+
if (!copied_decl)
486+
continue;
484487

485488
// FIXME: We should add the copied decl to the 'decls' list. This would
486489
// add the copied Decl into the DeclContext and make sure that we
@@ -490,6 +493,12 @@ void ClangASTSource::FindExternalLexicalDecls(
490493
// lookup issues later on.
491494
// We can't just add them for now as the ASTImporter already added the
492495
// decl into the DeclContext and this would add it twice.
496+
497+
if (FieldDecl *copied_field = dyn_cast<FieldDecl>(copied_decl)) {
498+
QualType copied_field_type = copied_field->getType();
499+
500+
m_ast_importer_sp->RequireCompleteType(copied_field_type);
501+
}
493502
} else {
494503
SkippedDecls = true;
495504
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Verify that LLDB doesn't crash during expression evaluation.
3+
"""
4+
5+
import lldb
6+
from lldbsuite.test.decorators import *
7+
from lldbsuite.test.lldbtest import *
8+
from lldbsuite.test import lldbutil
9+
10+
11+
class ExprCrashTestCase(TestBase):
12+
13+
mydir = TestBase.compute_mydir(__file__)
14+
15+
def test_pr52257(self):
16+
self.build()
17+
self.createTestTarget()
18+
self.expect_expr("b", result_type="B", result_children=[ValueCheck(name="tag_set_")])
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
template <typename> struct pair {};
2+
struct A {
3+
using iterator = pair<char *>;
4+
pair<char *> a_[];
5+
};
6+
struct B {
7+
using iterator = A::iterator;
8+
iterator begin();
9+
A *tag_set_;
10+
};
11+
B b;
12+
int main() {};

lldb/test/API/lang/cpp/reference-to-outer-type/TestCppReferenceToOuterClass.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class TestCase(TestBase):
77

88
mydir = TestBase.compute_mydir(__file__)
99

10+
@expectedFailure("The fix for this was reverted due to llvm.org/PR52257")
1011
def test(self):
1112
self.build()
1213
self.dbg.CreateTarget(self.getBuildArtifact("a.out"))

0 commit comments

Comments
 (0)