diff options
| author | Adrian Prantl <aprantl@apple.com> | 2020-01-08 14:18:47 -0800 |
|---|---|---|
| committer | Adrian Prantl <aprantl@apple.com> | 2020-01-10 08:52:46 -0800 |
| commit | e9331a56fead1823d528d6412828fb9e16fd62ff (patch) | |
| tree | 0532d62035494c012cd196e24065418c6eed7c62 /lldb/source/Plugins/ExpressionParser | |
| parent | bdd88b7ed3956534a0a71b1ea2bc88c69d48f9b7 (diff) | |
| download | bcm5719-llvm-e9331a56fead1823d528d6412828fb9e16fd62ff.tar.gz bcm5719-llvm-e9331a56fead1823d528d6412828fb9e16fd62ff.zip | |
Add missing nullptr checks.
GetPersistentExpressionStateForLanguage() can return a nullptr if it
cannot construct a typesystem. This patch adds missing nullptr checks
at all uses.
Inspired by rdar://problem/58317195
Differential Revision: https://reviews.llvm.org/D72413
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser')
5 files changed, 36 insertions, 26 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp index 19cab1dafd4..77bb9544ea4 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp @@ -447,8 +447,11 @@ void ASTResultSynthesizer::RecordPersistentDecl(NamedDecl *D) { } void ASTResultSynthesizer::CommitPersistentDecls() { - PersistentExpressionState *state = + auto *state = m_target.GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC); + if (!state) + return; + auto *persistent_vars = llvm::cast<ClangPersistentVariables>(state); ClangASTContext *scratch_ctx = ClangASTContext::GetScratch(m_target); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp index 6634824be01..a302a73cafc 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -126,7 +126,7 @@ void ClangExpressionDeclMap::InstallCodeGenerator( } void ClangExpressionDeclMap::DidParse() { - if (m_parser_vars) { + if (m_parser_vars && m_parser_vars->m_persistent_vars) { for (size_t entity_index = 0, num_entities = m_found_entities.GetSize(); entity_index < num_entities; ++entity_index) { ExpressionVariableSP var_sp( @@ -262,6 +262,9 @@ bool ClangExpressionDeclMap::AddPersistentVariable(const NamedDecl *decl, if (!m_parser_vars->m_target_info.IsValid()) return false; + if (!m_parser_vars->m_persistent_vars) + return false; + ClangExpressionVariable *var = llvm::cast<ClangExpressionVariable>( m_parser_vars->m_persistent_vars ->CreatePersistentVariable( @@ -327,7 +330,7 @@ bool ClangExpressionDeclMap::AddValueToStruct(const NamedDecl *decl, ClangExpressionVariable *var(ClangExpressionVariable::FindVariableInList( m_found_entities, decl, GetParserID())); - if (!var) { + if (!var && m_parser_vars->m_persistent_vars) { var = ClangExpressionVariable::FindVariableInList( *m_parser_vars->m_persistent_vars, decl, GetParserID()); is_persistent_variable = true; @@ -733,6 +736,8 @@ clang::NamedDecl *ClangExpressionDeclMap::GetPersistentDecl(ConstString name) { ClangASTContext::GetScratch(*target); + if (!m_parser_vars->m_persistent_vars) + return nullptr; return m_parser_vars->m_persistent_vars->GetPersistentDecl(name); } @@ -1390,7 +1395,7 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls( return; // No ParserVars means we can't do register or variable lookup. - if (!m_parser_vars) + if (!m_parser_vars || !m_parser_vars->m_persistent_vars) return; ExpressionVariableSP pvar_sp( diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp index ebd2d5c1644..dfd3e0e6e83 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -583,15 +583,16 @@ ClangExpressionParser::ClangExpressionParser( if (ClangModulesDeclVendor *decl_vendor = target_sp->GetClangModulesDeclVendor()) { - ClangPersistentVariables *clang_persistent_vars = - llvm::cast<ClangPersistentVariables>( + if (auto *clang_persistent_vars = llvm::cast<ClangPersistentVariables>( target_sp->GetPersistentExpressionStateForLanguage( - lldb::eLanguageTypeC)); - std::unique_ptr<PPCallbacks> pp_callbacks(new LLDBPreprocessorCallbacks( - *decl_vendor, *clang_persistent_vars, m_compiler->getSourceManager())); - m_pp_callbacks = - static_cast<LLDBPreprocessorCallbacks *>(pp_callbacks.get()); - m_compiler->getPreprocessor().addPPCallbacks(std::move(pp_callbacks)); + lldb::eLanguageTypeC))) { + std::unique_ptr<PPCallbacks> pp_callbacks( + new LLDBPreprocessorCallbacks(*decl_vendor, *clang_persistent_vars, + m_compiler->getSourceManager())); + m_pp_callbacks = + static_cast<LLDBPreprocessorCallbacks *>(pp_callbacks.get()); + m_compiler->getPreprocessor().addPPCallbacks(std::move(pp_callbacks)); + } } // 8. Most of this we get from the CompilerInstance, but we also want to give diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp index 21cb33402e7..7ebb5fee1ec 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp @@ -315,12 +315,10 @@ bool ClangExpressionSourceCode::GetText( } } - if (ClangModulesDeclVendor *decl_vendor = - target->GetClangModulesDeclVendor()) { - ClangPersistentVariables *persistent_vars = - llvm::cast<ClangPersistentVariables>( - target->GetPersistentExpressionStateForLanguage( - lldb::eLanguageTypeC)); + ClangModulesDeclVendor *decl_vendor = target->GetClangModulesDeclVendor(); + auto *persistent_vars = llvm::cast<ClangPersistentVariables>( + target->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC)); + if (decl_vendor && persistent_vars) { const ClangModulesDeclVendor::ModuleVector &hand_imported_modules = persistent_vars->GetHandLoadedClangModules(); ClangModulesDeclVendor::ModuleVector modules_for_macros; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp index c6bed45985e..6698797617a 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -350,11 +350,12 @@ bool ClangUserExpression::SetupPersistentState(DiagnosticManager &diagnostic_man static void SetupDeclVendor(ExecutionContext &exe_ctx, Target *target) { if (ClangModulesDeclVendor *decl_vendor = target->GetClangModulesDeclVendor()) { + auto *persistent_state = llvm::cast<ClangPersistentVariables>( + target->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC)); + if (!persistent_state) + return; const ClangModulesDeclVendor::ModuleVector &hand_imported_modules = - llvm::cast<ClangPersistentVariables>( - target->GetPersistentExpressionStateForLanguage( - lldb::eLanguageTypeC)) - ->GetHandLoadedClangModules(); + persistent_state->GetHandLoadedClangModules(); ClangModulesDeclVendor::ModuleVector modules_for_macros; for (ClangModulesDeclVendor::ModuleID module : hand_imported_modules) { @@ -682,10 +683,12 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager, register_execution_unit = true; } - if (register_execution_unit) - exe_ctx.GetTargetPtr() - ->GetPersistentExpressionStateForLanguage(m_language) - ->RegisterExecutionUnit(m_execution_unit_sp); + if (register_execution_unit) { + if (auto *persistent_state = + exe_ctx.GetTargetPtr()->GetPersistentExpressionStateForLanguage( + m_language)) + persistent_state->RegisterExecutionUnit(m_execution_unit_sp); + } } if (generate_debug_info) { |

