aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp')
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp48
1 files changed, 24 insertions, 24 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 6fe85a1298fc..0f34c48c7e82 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -71,20 +71,22 @@ ClangASTSource::~ClangASTSource() {
if (!m_target)
return;
- // We are in the process of destruction, don't create clang ast context on
- // demand by passing false to
- // Target::GetScratchTypeSystemClang(create_on_demand).
- TypeSystemClang *scratch_clang_ast_context =
- TypeSystemClang::GetScratch(*m_target, false);
- if (!scratch_clang_ast_context)
- return;
+ // Unregister the current ASTContext as a source for all scratch
+ // ASTContexts in the ClangASTImporter. Without this the scratch AST might
+ // query the deleted ASTContext for additional type information.
+ // We unregister from *all* scratch ASTContexts in case a type got exported
+ // to a scratch AST that isn't the best fitting scratch ASTContext.
+ TypeSystemClang *scratch_ast = ScratchTypeSystemClang::GetForTarget(
+ *m_target, ScratchTypeSystemClang::DefaultAST, false);
- clang::ASTContext &scratch_ast_context =
- scratch_clang_ast_context->getASTContext();
+ if (!scratch_ast)
+ return;
- if (m_ast_context != &scratch_ast_context && m_ast_importer_sp)
- m_ast_importer_sp->ForgetSource(&scratch_ast_context, m_ast_context);
+ ScratchTypeSystemClang *default_scratch_ast =
+ llvm::cast<ScratchTypeSystemClang>(scratch_ast);
+ // Unregister from the default scratch AST (and all sub-ASTs).
+ default_scratch_ast->ForgetSource(m_ast_context, *m_ast_importer_sp);
}
void ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer) {
@@ -482,6 +484,15 @@ void ClangASTSource::FindExternalLexicalDecls(
if (!copied_decl)
continue;
+ // FIXME: We should add the copied decl to the 'decls' list. This would
+ // add the copied Decl into the DeclContext and make sure that we
+ // correctly propagate that we added some Decls back to Clang.
+ // By leaving 'decls' empty we incorrectly return false from
+ // DeclContext::LoadLexicalDeclsFromExternalStorage which might cause
+ // lookup issues later on.
+ // We can't just add them for now as the ASTImporter already added the
+ // decl into the DeclContext and this would add it twice.
+
if (FieldDecl *copied_field = dyn_cast<FieldDecl>(copied_decl)) {
QualType copied_field_type = copied_field->getType();
@@ -679,12 +690,7 @@ void ClangASTSource::FillNamespaceMap(
return;
}
- const ModuleList &target_images = m_target->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
-
- for (size_t i = 0, e = target_images.GetSize(); i < e; ++i) {
- lldb::ModuleSP image = target_images.GetModuleAtIndexUnlocked(i);
-
+ for (lldb::ModuleSP image : m_target->GetImages().Modules()) {
if (!image)
continue;
@@ -1656,14 +1662,8 @@ void ClangASTSource::CompleteNamespaceMap(
module_sp->GetFileSpec().GetFilename());
}
} else {
- const ModuleList &target_images = m_target->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
-
CompilerDeclContext null_namespace_decl;
-
- for (size_t i = 0, e = target_images.GetSize(); i < e; ++i) {
- lldb::ModuleSP image = target_images.GetModuleAtIndexUnlocked(i);
-
+ for (lldb::ModuleSP image : m_target->GetImages().Modules()) {
if (!image)
continue;