diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h --- a/lldb/include/lldb/lldb-forward.h +++ b/lldb/include/lldb/lldb-forward.h @@ -258,6 +258,7 @@ class TypeSummaryImpl; class TypeSummaryOptions; class TypeSystem; +class TypeSystemClang; class UUID; class UnixSignals; class Unwind; @@ -432,6 +433,7 @@ typedef std::shared_ptr TypeEnumMemberImplSP; typedef std::shared_ptr TypeFilterImplSP; typedef std::shared_ptr TypeSystemSP; +typedef std::shared_ptr TypeSystemClangSP; typedef std::weak_ptr TypeSystemWP; typedef std::shared_ptr TypeFormatImplSP; typedef std::shared_ptr diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp @@ -1112,14 +1112,14 @@ } StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0); if (frame_sp) { - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(target); - if (!clang_ast_context) + if (!scratch_ts_sp) return LLDB_INVALID_ADDRESS; CompilerType clang_void_ptr_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); Address pthread_getspecific_addr = GetPthreadSetSpecificAddress(); if (pthread_getspecific_addr.IsValid()) { EvaluateExpressionOptions options; diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp @@ -260,9 +260,9 @@ // Build up the value array to store the three arguments given above, then // get the values from the ABI: - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(process->GetTarget()); - if (!clang_ast_context) + if (!scratch_ts_sp) return false; ValueList argument_values; @@ -273,13 +273,13 @@ Value headers_value; // uint64_t machHeaders[] (aka void*) CompilerType clang_void_ptr_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); CompilerType clang_uint32_type = - clang_ast_context->GetBuiltinTypeForEncodingAndBitSize( - lldb::eEncodingUint, 32); + scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint, + 32); CompilerType clang_uint64_type = - clang_ast_context->GetBuiltinTypeForEncodingAndBitSize( - lldb::eEncodingUint, 32); + scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint, + 32); mode_value.SetValueType(Value::ValueType::Scalar); mode_value.SetCompilerType(clang_uint32_type); diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -357,19 +357,19 @@ // Build up the value array to store the three arguments given above, then // get the values from the ABI: - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(process->GetTarget()); - if (!clang_ast_context) + if (!scratch_ts_sp) return false; ValueList argument_values; Value input_value; CompilerType clang_void_ptr_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); CompilerType clang_uint32_type = - clang_ast_context->GetBuiltinTypeForEncodingAndBitSize( - lldb::eEncodingUint, 32); + scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint, + 32); input_value.SetValueType(Value::ValueType::Scalar); input_value.SetCompilerType(clang_uint32_type); // input_value.SetContext (Value::eContextTypeClangType, diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp @@ -470,7 +470,7 @@ auto *persistent_vars = llvm::cast(state); - TypeSystemClang *scratch_ctx = ScratchTypeSystemClang::GetForTarget( + lldb::TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget( m_target, m_ast_context->getLangOpts()); for (clang::NamedDecl *decl : m_decls) { @@ -478,7 +478,7 @@ ConstString name_cs(name.str().c_str()); Decl *D_scratch = persistent_vars->GetClangASTImporter()->DeportDecl( - &scratch_ctx->getASTContext(), decl); + &scratch_ts_sp->getASTContext(), decl); if (!D_scratch) { Log *log = GetLog(LLDBLog::Expressions); @@ -497,7 +497,7 @@ if (NamedDecl *NamedDecl_scratch = dyn_cast(D_scratch)) persistent_vars->RegisterPersistentDecl(name_cs, NamedDecl_scratch, - scratch_ctx); + scratch_ts_sp); } } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -78,14 +78,14 @@ // 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( + lldb::TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget( *m_target, ScratchTypeSystemClang::DefaultAST, false); - if (!scratch_ast) + if (!scratch_ts_sp) return; ScratchTypeSystemClang *default_scratch_ast = - llvm::cast(scratch_ast); + llvm::cast(scratch_ts_sp.get()); // Unregister from the default scratch AST (and all sub-ASTs). default_scratch_ast->ForgetSource(m_ast_context, *m_ast_importer_sp); } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h @@ -12,6 +12,7 @@ #include #include +#include #include #include "ClangASTSource.h" @@ -377,7 +378,7 @@ /// Deallocate struct variables void DisableStructVars() { m_struct_vars.reset(); } - TypeSystemClang *GetScratchContext(Target &target) { + lldb::TypeSystemClangSP GetScratchContext(Target &target) { return ScratchTypeSystemClang::GetForTarget(target, m_ast_context->getLangOpts()); } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -205,7 +205,7 @@ TypeFromUser ClangExpressionDeclMap::DeportType(TypeSystemClang &target, TypeSystemClang &source, TypeFromParser parser_type) { - assert(&target == GetScratchContext(*m_target)); + assert(&target == GetScratchContext(*m_target).get()); assert((TypeSystem *)&source == parser_type.GetTypeSystem().GetSharedPointer().get()); assert(&source.getASTContext() == m_ast_context); @@ -242,7 +242,7 @@ if (target == nullptr) return false; - auto *clang_ast_context = GetScratchContext(*target); + auto clang_ast_context = GetScratchContext(*target); if (!clang_ast_context) return false; @@ -280,7 +280,7 @@ if (target == nullptr) return false; - TypeSystemClang *context = GetScratchContext(*target); + auto context = GetScratchContext(*target); if (!context) return false; @@ -1728,7 +1728,7 @@ if (target == nullptr) return; - TypeSystemClang *scratch_ast_context = GetScratchContext(*target); + auto scratch_ast_context = GetScratchContext(*target); if (!scratch_ast_context) return; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h @@ -70,7 +70,7 @@ GetCompilerTypeFromPersistentDecl(ConstString type_name) override; void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl, - TypeSystemClang *ctx); + std::shared_ptr ctx); clang::NamedDecl *GetPersistentDecl(ConstString name); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp @@ -21,6 +21,7 @@ #include "llvm/ADT/StringMap.h" #include +#include using namespace lldb; using namespace lldb_private; @@ -85,15 +86,15 @@ return std::nullopt; } -void ClangPersistentVariables::RegisterPersistentDecl(ConstString name, - clang::NamedDecl *decl, - TypeSystemClang *ctx) { - PersistentDecl p = {decl, ctx->weak_from_this()}; +void ClangPersistentVariables::RegisterPersistentDecl( + ConstString name, clang::NamedDecl *decl, + std::shared_ptr ctx) { + PersistentDecl p = {decl, ctx}; m_persistent_decls.insert(std::make_pair(name.GetCString(), p)); if (clang::EnumDecl *enum_decl = llvm::dyn_cast(decl)) { for (clang::EnumConstantDecl *enumerator_decl : enum_decl->enumerators()) { - p = {enumerator_decl, ctx->weak_from_this()}; + p = {enumerator_decl, ctx}; m_persistent_decls.insert(std::make_pair( ConstString(enumerator_decl->getNameAsString()).GetCString(), p)); } diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -853,13 +853,13 @@ return false; // std::wstring::size() is measured in 'characters', not bytes - TypeSystemClang *ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(*valobj.GetTargetSP()); - if (!ast_context) + if (!scratch_ts_sp) return false; auto wchar_t_size = - ast_context->GetBasicType(lldb::eBasicTypeWChar).GetByteSize(nullptr); + scratch_ts_sp->GetBasicType(lldb::eBasicTypeWChar).GetByteSize(nullptr); if (!wchar_t_size) return false; diff --git a/lldb/source/Plugins/Language/ObjC/NSArray.cpp b/lldb/source/Plugins/Language/ObjC/NSArray.cpp --- a/lldb/source/Plugins/Language/ObjC/NSArray.cpp +++ b/lldb/source/Plugins/Language/ObjC/NSArray.cpp @@ -463,12 +463,12 @@ NSArrayMSyntheticFrontEndBase(lldb::ValueObjectSP valobj_sp) : SyntheticChildrenFrontEnd(*valobj_sp), m_exe_ctx_ref(), m_id_type() { if (valobj_sp) { - auto *clang_ast_context = ScratchTypeSystemClang::GetForTarget( + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget( *valobj_sp->GetExecutionContextRef().GetTargetSP()); - if (clang_ast_context) + if (scratch_ts_sp) m_id_type = CompilerType( - clang_ast_context->weak_from_this(), - clang_ast_context->getASTContext().ObjCBuiltinIdTy.getAsOpaquePtr()); + scratch_ts_sp->weak_from_this(), + scratch_ts_sp->getASTContext().ObjCBuiltinIdTy.getAsOpaquePtr()); if (valobj_sp->GetProcessSP()) m_ptr_size = valobj_sp->GetProcessSP()->GetAddressByteSize(); } @@ -609,11 +609,11 @@ if (valobj_sp) { CompilerType type = valobj_sp->GetCompilerType(); if (type) { - auto *clang_ast_context = ScratchTypeSystemClang::GetForTarget( + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget( *valobj_sp->GetExecutionContextRef().GetTargetSP()); - if (clang_ast_context) - m_id_type = clang_ast_context->GetType( - clang_ast_context->getASTContext().ObjCBuiltinIdTy); + if (scratch_ts_sp) + m_id_type = scratch_ts_sp->GetType( + scratch_ts_sp->getASTContext().ObjCBuiltinIdTy); } } } @@ -776,11 +776,10 @@ static const ConstString g_zero("[0]"); if (idx == 0) { - auto *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(*m_backend.GetTargetSP()); - if (clang_ast_context) { - CompilerType id_type( - clang_ast_context->GetBasicType(lldb::eBasicTypeObjCID)); + if (scratch_ts_sp) { + CompilerType id_type(scratch_ts_sp->GetBasicType(lldb::eBasicTypeObjCID)); return m_backend.GetSyntheticChildAtOffset( m_backend.GetProcessSP()->GetAddressByteSize(), id_type, true, g_zero); diff --git a/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp b/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp --- a/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp +++ b/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp @@ -66,18 +66,17 @@ static CompilerType GetLLDBNSPairType(TargetSP target_sp) { CompilerType compiler_type; - TypeSystemClang *target_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(*target_sp); - if (target_ast_context) { + if (scratch_ts_sp) { ConstString g_lldb_autogen_nspair("__lldb_autogen_nspair"); - compiler_type = - target_ast_context->GetTypeForIdentifier( - g_lldb_autogen_nspair); + compiler_type = scratch_ts_sp->GetTypeForIdentifier( + g_lldb_autogen_nspair); if (!compiler_type) { - compiler_type = target_ast_context->CreateRecordType( + compiler_type = scratch_ts_sp->CreateRecordType( nullptr, OptionalClangModuleID(), lldb::eAccessPublic, g_lldb_autogen_nspair.GetCString(), clang::TTK_Struct, lldb::eLanguageTypeC); @@ -85,7 +84,7 @@ if (compiler_type) { TypeSystemClang::StartTagDeclarationDefinition(compiler_type); CompilerType id_compiler_type = - target_ast_context->GetBasicType(eBasicTypeObjCID); + scratch_ts_sp->GetBasicType(eBasicTypeObjCID); TypeSystemClang::AddFieldToRecordType( compiler_type, "key", id_compiler_type, lldb::eAccessPublic, 0); TypeSystemClang::AddFieldToRecordType( diff --git a/lldb/source/Plugins/Language/ObjC/NSError.cpp b/lldb/source/Plugins/Language/ObjC/NSError.cpp --- a/lldb/source/Plugins/Language/ObjC/NSError.cpp +++ b/lldb/source/Plugins/Language/ObjC/NSError.cpp @@ -83,13 +83,15 @@ } InferiorSizedWord isw(domain_str_value, *process_sp); + TypeSystemClangSP scratch_ts_sp = + ScratchTypeSystemClang::GetForTarget(process_sp->GetTarget()); + if (!scratch_ts_sp) + return false; ValueObjectSP domain_str_sp = ValueObject::CreateValueObjectFromData( "domain_str", isw.GetAsData(process_sp->GetByteOrder()), valobj.GetExecutionContextRef(), - ScratchTypeSystemClang::GetForTarget(process_sp->GetTarget()) - ->GetBasicType(lldb::eBasicTypeVoid) - .GetPointerType()); + scratch_ts_sp->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()); if (!domain_str_sp) return false; @@ -153,11 +155,14 @@ if (userinfo == LLDB_INVALID_ADDRESS || error.Fail()) return false; InferiorSizedWord isw(userinfo, *process_sp); + TypeSystemClangSP scratch_ts_sp = + ScratchTypeSystemClang::GetForTarget(process_sp->GetTarget()); + if (!scratch_ts_sp) + return false; m_child_sp = CreateValueObjectFromData( "_userInfo", isw.GetAsData(process_sp->GetByteOrder()), m_backend.GetExecutionContextRef(), - ScratchTypeSystemClang::GetForTarget(process_sp->GetTarget()) - ->GetBasicType(lldb::eBasicTypeObjCID)); + scratch_ts_sp->GetBasicType(lldb::eBasicTypeObjCID)); return false; } diff --git a/lldb/source/Plugins/Language/ObjC/NSException.cpp b/lldb/source/Plugins/Language/ObjC/NSException.cpp --- a/lldb/source/Plugins/Language/ObjC/NSException.cpp +++ b/lldb/source/Plugins/Language/ObjC/NSException.cpp @@ -69,13 +69,13 @@ InferiorSizedWord userinfo_isw(userinfo, *process_sp); InferiorSizedWord reserved_isw(reserved, *process_sp); - auto *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(process_sp->GetTarget()); - if (!clang_ast_context) + if (!scratch_ts_sp) return false; CompilerType voidstar = - clang_ast_context->GetBasicType(lldb::eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(lldb::eBasicTypeVoid).GetPointerType(); if (name_sp) *name_sp = ValueObject::CreateValueObjectFromData( diff --git a/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp b/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp --- a/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp +++ b/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp @@ -53,7 +53,7 @@ if (!type_system) return false; - TypeSystemClang *ast = ScratchTypeSystemClang::GetForTarget( + auto ast = ScratchTypeSystemClang::GetForTarget( *m_backend.GetExecutionContextRef().GetTargetSP()); if (!ast) return false; diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp --- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp @@ -525,13 +525,13 @@ if (!thread_sp->SafeToCallFunctions()) return {}; - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(m_process->GetTarget()); - if (!clang_ast_context) + if (!scratch_ts_sp) return {}; CompilerType voidstar = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); DiagnosticManager diagnostics; ExecutionContext exe_ctx; diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp @@ -123,14 +123,14 @@ } } else { // If it is not a pointer, see if we can make it into a pointer. - TypeSystemClang *ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(*target); - if (!ast_context) + if (!scratch_ts_sp) return false; - CompilerType opaque_type = ast_context->GetBasicType(eBasicTypeObjCID); + CompilerType opaque_type = scratch_ts_sp->GetBasicType(eBasicTypeObjCID); if (!opaque_type) - opaque_type = ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + opaque_type = scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); // value.SetContext(Value::eContextTypeClangType, opaque_type_ptr); value.SetCompilerType(opaque_type); } @@ -139,11 +139,12 @@ arg_value_list.PushValue(value); // This is the return value: - TypeSystemClang *ast_context = ScratchTypeSystemClang::GetForTarget(*target); - if (!ast_context) + TypeSystemClangSP scratch_ts_sp = + ScratchTypeSystemClang::GetForTarget(*target); + if (!scratch_ts_sp) return false; - CompilerType return_compiler_type = ast_context->GetCStringType(true); + CompilerType return_compiler_type = scratch_ts_sp->GetCStringType(true); Value ret; // ret.SetContext(Value::eContextTypeClangType, return_compiler_type); ret.SetCompilerType(return_compiler_type); @@ -521,12 +522,11 @@ if (!reserved_dict) return FailExceptionParsing("Failed to get synthetic value."); - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(*exception_sp->GetTargetSP()); - if (!clang_ast_context) + if (!scratch_ts_sp) return FailExceptionParsing("Failed to get scratch AST."); - CompilerType objc_id = - clang_ast_context->GetBasicType(lldb::eBasicTypeObjCID); + CompilerType objc_id = scratch_ts_sp->GetBasicType(lldb::eBasicTypeObjCID); ValueObjectSP return_addresses; auto objc_object_from_address = [&exception_sp, &objc_id](uint64_t addr, diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -1627,9 +1627,9 @@ LLDB_LOG(log, "Creating utility function {0}", name); - TypeSystemClang *ast = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(exe_ctx.GetTargetRef()); - if (!ast) + if (!scratch_ts_sp) return {}; auto utility_fn_or_error = exe_ctx.GetTargetRef().CreateUtilityFunction( @@ -1643,9 +1643,9 @@ // Make some types for our arguments. CompilerType clang_uint32_t_type = - ast->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 32); + scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 32); CompilerType clang_void_pointer_type = - ast->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); // Make the runner function for our implementation utility function. ValueList arguments; @@ -1768,9 +1768,9 @@ LLDB_LOG(log, "Creating utility function {0}", g_get_shared_cache_class_info_name); - TypeSystemClang *ast = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(exe_ctx.GetTargetRef()); - if (!ast) + if (!scratch_ts_sp) return {}; // If the inferior objc.dylib has the class_getNameRaw function, use that in @@ -1808,11 +1808,11 @@ // Make some types for our arguments. CompilerType clang_uint32_t_type = - ast->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 32); + scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 32); CompilerType clang_void_pointer_type = - ast->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); CompilerType clang_uint64_t_pointer_type = - ast->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 64) + scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 64) .GetPointerType(); // Next make the function caller for our implementation utility function. @@ -1879,10 +1879,10 @@ return DescriptorMapUpdateResult::Retry(); thread_sp->CalculateExecutionContext(exe_ctx); - TypeSystemClang *ast = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(process->GetTarget()); - if (!ast) + if (!scratch_ts_sp) return DescriptorMapUpdateResult::Fail(); Address function_address; @@ -2002,7 +2002,7 @@ options.SetIsForUtilityExpr(true); CompilerType clang_uint32_t_type = - ast->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 32); + scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 32); Value return_value; return_value.SetValueType(Value::ValueType::Scalar); @@ -2144,10 +2144,10 @@ return DescriptorMapUpdateResult::Retry(); thread_sp->CalculateExecutionContext(exe_ctx); - TypeSystemClang *ast = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(process->GetTarget()); - if (!ast) + if (!scratch_ts_sp) return DescriptorMapUpdateResult::Fail(); Address function_address; @@ -2237,7 +2237,7 @@ options.SetIsForUtilityExpr(true); CompilerType clang_uint32_t_type = - ast->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 32); + scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 32); Value return_value; return_value.SetValueType(Value::ValueType::Scalar); @@ -3251,12 +3251,12 @@ if (!abi) return; - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(process_sp->GetTarget()); - if (!clang_ast_context) + if (!scratch_ts_sp) return; CompilerType voidstar = - clang_ast_context->GetBasicType(lldb::eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(lldb::eBasicTypeVoid).GetPointerType(); ValueList args; Value input_value; diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp @@ -416,15 +416,15 @@ Process *process = exe_ctx.GetProcessPtr(); const ABI *abi = process->GetABI().get(); - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(process->GetTarget()); - if (!clang_ast_context) + if (!scratch_ts_sp) return false; ValueList argument_values; Value input_value; CompilerType clang_void_ptr_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); input_value.SetValueType(Value::ValueType::Scalar); // input_value.SetContext (Value::eContextTypeClangType, @@ -730,13 +730,13 @@ } // Next make the runner function for our implementation utility function. - TypeSystemClang *clang_ast_context = ScratchTypeSystemClang::GetForTarget( + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget( thread.GetProcess()->GetTarget()); - if (!clang_ast_context) + if (!scratch_ts_sp) return LLDB_INVALID_ADDRESS; CompilerType clang_void_ptr_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); Status error; impl_function_caller = m_impl_code->MakeFunctionCaller( @@ -866,15 +866,15 @@ TargetSP target_sp(thread.CalculateTarget()); - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(*target_sp); - if (!clang_ast_context) + if (!scratch_ts_sp) return ret_plan_sp; ValueList argument_values; Value void_ptr_value; CompilerType clang_void_ptr_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); void_ptr_value.SetValueType(Value::ValueType::Scalar); // void_ptr_value.SetContext (Value::eContextTypeClangType, // clang_void_ptr_type); @@ -1089,7 +1089,7 @@ Value flag_value; CompilerType clang_int_type = - clang_ast_context->GetBuiltinTypeForEncodingAndBitSize( + scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize( lldb::eEncodingSint, 32); flag_value.SetValueType(Value::ValueType::Scalar); // flag_value.SetContext (Value::eContextTypeClangType, clang_int_type); diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -627,15 +627,15 @@ FunctionCaller *do_dlopen_function = nullptr; // Fetch the clang types we will need: - TypeSystemClang *ast = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(process->GetTarget()); - if (!ast) + if (!scratch_ts_sp) return nullptr; - CompilerType clang_void_pointer_type - = ast->GetBasicType(eBasicTypeVoid).GetPointerType(); - CompilerType clang_char_pointer_type - = ast->GetBasicType(eBasicTypeChar).GetPointerType(); + CompilerType clang_void_pointer_type = + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); + CompilerType clang_char_pointer_type = + scratch_ts_sp->GetBasicType(eBasicTypeChar).GetPointerType(); // We are passing four arguments, the basename, the list of places to look, // a buffer big enough for all the path + name combos, and @@ -876,15 +876,15 @@ Value return_value; // Fetch the clang types we will need: - TypeSystemClang *ast = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(process->GetTarget()); - if (!ast) { + if (!scratch_ts_sp) { error.SetErrorString("dlopen error: Unable to get TypeSystemClang"); return LLDB_INVALID_IMAGE_TOKEN; } - CompilerType clang_void_pointer_type - = ast->GetBasicType(eBasicTypeVoid).GetPointerType(); + CompilerType clang_void_pointer_type = + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); return_value.SetCompilerType(clang_void_pointer_type); diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp --- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp +++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp @@ -336,19 +336,21 @@ return LLDB_INVALID_IMAGE_TOKEN; } - auto parameter_cleanup = llvm::make_scope_exit([invocation, &context, injected_parameters]() { - invocation->DeallocateFunctionResults(context, injected_parameters); - }); + auto parameter_cleanup = + llvm::make_scope_exit([invocation, &context, injected_parameters]() { + invocation->DeallocateFunctionResults(context, injected_parameters); + }); - TypeSystemClang *ast = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(process->GetTarget()); - if (!ast) { + if (!scratch_ts_sp) { error.SetErrorString("LoadLibrary error: unable to get (clang) type system"); return LLDB_INVALID_IMAGE_TOKEN; } /* Setup Return Type */ - CompilerType VoidPtrTy = ast->GetBasicType(eBasicTypeVoid).GetPointerType(); + CompilerType VoidPtrTy = + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); Value value; value.SetCompilerType(VoidPtrTy); @@ -683,12 +685,15 @@ return nullptr; } - TypeSystemClang *ast = ScratchTypeSystemClang::GetForTarget(target); - if (!ast) + TypeSystemClangSP scratch_ts_sp = + ScratchTypeSystemClang::GetForTarget(target); + if (!scratch_ts_sp) return nullptr; - CompilerType VoidPtrTy = ast->GetBasicType(eBasicTypeVoid).GetPointerType(); - CompilerType WCharPtrTy = ast->GetBasicType(eBasicTypeWChar).GetPointerType(); + CompilerType VoidPtrTy = + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); + CompilerType WCharPtrTy = + scratch_ts_sp->GetBasicType(eBasicTypeWChar).GetPointerType(); ValueList parameters; diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp @@ -221,7 +221,7 @@ lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0); ProcessSP process_sp(thread.CalculateProcess()); TargetSP target_sp(thread.CalculateTarget()); - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(*target_sp); Log *log = GetLog(LLDBLog::SystemRuntime); @@ -261,18 +261,18 @@ // already allocated by lldb in the inferior process. CompilerType clang_void_ptr_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); Value return_buffer_ptr_value; return_buffer_ptr_value.SetValueType(Value::ValueType::Scalar); return_buffer_ptr_value.SetCompilerType(clang_void_ptr_type); - CompilerType clang_int_type = clang_ast_context->GetBasicType(eBasicTypeInt); + CompilerType clang_int_type = scratch_ts_sp->GetBasicType(eBasicTypeInt); Value debug_value; debug_value.SetValueType(Value::ValueType::Scalar); debug_value.SetCompilerType(clang_int_type); CompilerType clang_uint64_type = - clang_ast_context->GetBasicType(eBasicTypeUnsignedLongLong); + scratch_ts_sp->GetBasicType(eBasicTypeUnsignedLongLong); Value item_value; item_value.SetValueType(Value::ValueType::Scalar); item_value.SetCompilerType(clang_uint64_type); diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp @@ -164,10 +164,10 @@ // Next make the runner function for our implementation utility function. Status error; - TypeSystemClang *clang_ast_context = ScratchTypeSystemClang::GetForTarget( + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget( thread.GetProcess()->GetTarget()); CompilerType get_pending_items_return_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); get_pending_items_caller = m_get_pending_items_impl_code->MakeFunctionCaller( get_pending_items_return_type, get_pending_items_arglist, @@ -216,7 +216,7 @@ lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0); ProcessSP process_sp(thread.CalculateProcess()); TargetSP target_sp(thread.CalculateTarget()); - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(*target_sp); Log *log = GetLog(LLDBLog::SystemRuntime); @@ -260,18 +260,18 @@ // already allocated by lldb in the inferior process. CompilerType clang_void_ptr_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); Value return_buffer_ptr_value; return_buffer_ptr_value.SetValueType(Value::ValueType::Scalar); return_buffer_ptr_value.SetCompilerType(clang_void_ptr_type); - CompilerType clang_int_type = clang_ast_context->GetBasicType(eBasicTypeInt); + CompilerType clang_int_type = scratch_ts_sp->GetBasicType(eBasicTypeInt); Value debug_value; debug_value.SetValueType(Value::ValueType::Scalar); debug_value.SetCompilerType(clang_int_type); CompilerType clang_uint64_type = - clang_ast_context->GetBasicType(eBasicTypeUnsignedLongLong); + scratch_ts_sp->GetBasicType(eBasicTypeUnsignedLongLong); Value queue_value; queue_value.SetValueType(Value::ValueType::Scalar); queue_value.SetCompilerType(clang_uint64_type); diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp @@ -180,10 +180,10 @@ } // Next make the runner function for our implementation utility function. - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(thread.GetProcess()->GetTarget()); CompilerType get_queues_return_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); Status error; get_queues_caller = m_get_queues_impl_code_up->MakeFunctionCaller( get_queues_return_type, get_queues_arglist, thread_sp, error); @@ -221,7 +221,7 @@ lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0); ProcessSP process_sp(thread.CalculateProcess()); TargetSP target_sp(thread.CalculateTarget()); - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(*target_sp); Log *log = GetLog(LLDBLog::SystemRuntime); @@ -263,12 +263,12 @@ // already allocated by lldb in the inferior process. CompilerType clang_void_ptr_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); Value return_buffer_ptr_value; return_buffer_ptr_value.SetValueType(Value::ValueType::Scalar); return_buffer_ptr_value.SetCompilerType(clang_void_ptr_type); - CompilerType clang_int_type = clang_ast_context->GetBasicType(eBasicTypeInt); + CompilerType clang_int_type = scratch_ts_sp->GetBasicType(eBasicTypeInt); Value debug_value; debug_value.SetValueType(Value::ValueType::Scalar); debug_value.SetCompilerType(clang_int_type); @@ -278,7 +278,7 @@ page_to_free_value.SetCompilerType(clang_void_ptr_type); CompilerType clang_uint64_type = - clang_ast_context->GetBasicType(eBasicTypeUnsignedLongLong); + scratch_ts_sp->GetBasicType(eBasicTypeUnsignedLongLong); Value page_to_free_size_value; page_to_free_size_value.SetValueType(Value::ValueType::Scalar); page_to_free_size_value.SetCompilerType(clang_uint64_type); diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp @@ -171,10 +171,10 @@ // Also make the FunctionCaller for this UtilityFunction: - TypeSystemClang *clang_ast_context = ScratchTypeSystemClang::GetForTarget( + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget( thread.GetProcess()->GetTarget()); CompilerType get_thread_item_info_return_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); get_thread_item_info_caller = m_get_thread_item_info_impl_code->MakeFunctionCaller( @@ -223,7 +223,7 @@ lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0); ProcessSP process_sp(thread.CalculateProcess()); TargetSP target_sp(thread.CalculateTarget()); - TypeSystemClang *clang_ast_context = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(*target_sp); Log *log = GetLog(LLDBLog::SystemRuntime); @@ -261,18 +261,18 @@ // already allocated by lldb in the inferior process. CompilerType clang_void_ptr_type = - clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType(); Value return_buffer_ptr_value; return_buffer_ptr_value.SetValueType(Value::ValueType::Scalar); return_buffer_ptr_value.SetCompilerType(clang_void_ptr_type); - CompilerType clang_int_type = clang_ast_context->GetBasicType(eBasicTypeInt); + CompilerType clang_int_type = scratch_ts_sp->GetBasicType(eBasicTypeInt); Value debug_value; debug_value.SetValueType(Value::ValueType::Scalar); debug_value.SetCompilerType(clang_int_type); CompilerType clang_uint64_type = - clang_ast_context->GetBasicType(eBasicTypeUnsignedLongLong); + scratch_ts_sp->GetBasicType(eBasicTypeUnsignedLongLong); Value thread_id_value; thread_id_value.SetValueType(Value::ValueType::Scalar); thread_id_value.SetCompilerType(clang_uint64_type); diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp --- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp @@ -414,12 +414,12 @@ } #endif - TypeSystemClang *ast_ctx = + TypeSystemClangSP scratch_ts_sp = ScratchTypeSystemClang::GetForTarget(m_process->GetTarget()); if (m_dispatch_tsd_indexes_addr != LLDB_INVALID_ADDRESS) { CompilerType uint16 = - ast_ctx->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 16); - CompilerType dispatch_tsd_indexes_s = ast_ctx->CreateRecordType( + scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 16); + CompilerType dispatch_tsd_indexes_s = scratch_ts_sp->CreateRecordType( nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "__lldb_dispatch_tsd_indexes_s", clang::TTK_Struct, lldb::eLanguageTypeC); diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -1182,7 +1182,7 @@ /// this parameter is false, this function returns a nullptr. /// \return The scratch type system of the target or a nullptr in case an /// error occurred. - static TypeSystemClang * + static lldb::TypeSystemClangSP GetForTarget(Target &target, std::optional ast_kind = DefaultAST, bool create_on_demand = true); @@ -1194,8 +1194,8 @@ /// \param lang_opts The LangOptions of a clang ASTContext that the caller /// wants to export type information from. This is used to /// find the best matching sub-AST that will be returned. - static TypeSystemClang *GetForTarget(Target &target, - const clang::LangOptions &lang_opts) { + static lldb::TypeSystemClangSP + GetForTarget(Target &target, const clang::LangOptions &lang_opts) { return GetForTarget(target, InferIsolatedASTKindFromLangOpts(lang_opts)); } diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -12,6 +12,7 @@ #include "llvm/Support/FormatVariadic.h" #include +#include #include #include @@ -9922,7 +9923,7 @@ m_scratch_ast_source_up.reset(); } -TypeSystemClang * +TypeSystemClangSP ScratchTypeSystemClang::GetForTarget(Target &target, std::optional ast_kind, bool create_on_demand) { @@ -9933,16 +9934,17 @@ "Couldn't get scratch TypeSystemClang"); return nullptr; } - auto ts = *type_system_or_err; + auto ts_sp = *type_system_or_err; ScratchTypeSystemClang *scratch_ast = - llvm::dyn_cast_or_null(ts.get()); + llvm::dyn_cast_or_null(ts_sp.get()); if (!scratch_ast) return nullptr; // If no dedicated sub-AST was requested, just return the main AST. if (ast_kind == DefaultAST) - return scratch_ast; + return std::static_pointer_cast(ts_sp); // Search the sub-ASTs. - return &scratch_ast->GetIsolatedAST(*ast_kind); + return std::static_pointer_cast( + scratch_ast->GetIsolatedAST(*ast_kind).shared_from_this()); } /// Returns a human-readable name that uniquely identifiers the sub-AST kind.