Skip to content

Commit 7eca50c

Browse files
Merge pull request #5677 from adrian-prantl/102525085
Create a TypeSystemClang to wrap ClangImporter's clang::ASTContext
2 parents 4383eef + c2d12fd commit 7eca50c

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -759,22 +759,7 @@ void TypeSystemClang::CreateASTContext() {
759759

760760
TypeSystemClang *TypeSystemClang::GetASTContext(clang::ASTContext *ast) {
761761
TypeSystemClang *clang_ast = GetASTMap().Lookup(ast);
762-
// BEGIN SWIFT
763-
// FIXME: rdar://102525085
764-
// The following code existed only on swift-lldb. Presumably it's a
765-
// hack to wrap the clang::ASTContext owned by a ClangImporter in a
766-
// TypeSystemClang.
767-
if (!clang_ast) {
768-
/// rdar://102525085
769-
auto ts = std::make_shared<TypeSystemClang>(
770-
"ASTContext from TypeSystemClang::GetASTContext", *ast);
771-
static std::vector<std::shared_ptr<TypeSystemClang>> g_adhoc_typesystems;
772-
g_adhoc_typesystems.push_back(ts);
773-
774-
GetASTMap().Insert(ast, ts.get());
775-
clang_ast = ts.get();
776-
}
777-
// END SWIFT
762+
lldbassert(clang_ast && "Orphaned clang::ASTContext");
778763
return clang_ast;
779764
}
780765

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,9 +3063,12 @@ swift::ASTContext *SwiftASTContext::GetASTContext() {
30633063

30643064
// 4. Install the clang importer.
30653065
if (clang_importer_ap) {
3066-
m_clang_importer = (swift::ClangImporter *)clang_importer_ap.get();
3066+
m_clangimporter = (swift::ClangImporter *)clang_importer_ap.get();
30673067
m_ast_context_ap->addModuleLoader(std::move(clang_importer_ap),
30683068
/*isClang=*/true);
3069+
m_clangimporter_typesystem = std::make_shared<TypeSystemClang>(
3070+
"ClangImporter-owned clang::ASTContext for '" + m_description,
3071+
m_clangimporter->getClangASTContext());
30693072
}
30703073

30713074
// Set up the required state for the evaluator in the TypeChecker.
@@ -3097,7 +3100,7 @@ swift::ClangImporter *SwiftASTContext::GetClangImporter() {
30973100
VALID_OR_RETURN(nullptr);
30983101

30993102
GetASTContext();
3100-
return m_clang_importer;
3103+
return m_clangimporter;
31013104
}
31023105

31033106
const swift::SearchPathOptions *SwiftASTContext::GetSearchPathOptions() const {

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "llvm/ADT/SmallVector.h"
2525
#include "llvm/ADT/StringRef.h"
2626
#include "llvm/Target/TargetOptions.h"
27+
#include <memory>
2728

2829
namespace swift {
2930
enum class IRGenDebugInfoLevel : unsigned;
@@ -863,7 +864,9 @@ class SwiftASTContext : public TypeSystemSwift {
863864
/// Owned by the AST.
864865
swift::MemoryBufferSerializedModuleLoader *m_memory_buffer_module_loader =
865866
nullptr;
866-
swift::ClangImporter *m_clang_importer = nullptr;
867+
swift::ClangImporter *m_clangimporter = nullptr;
868+
/// Wraps the clang::ASTContext owned by ClangImporter.
869+
std::shared_ptr<TypeSystemClang> m_clangimporter_typesystem;
867870
SwiftModuleMap m_swift_module_cache;
868871
SwiftTypeFromMangledNameMap m_mangled_name_to_type_map;
869872
SwiftMangledNameFromTypeMap m_type_to_mangled_name_map;

0 commit comments

Comments
 (0)