diff options
author | Raphael Isemann <teemperor@gmail.com> | 2019-12-21 22:40:52 +0100 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2019-12-21 22:51:35 +0100 |
commit | f9f49d3594bc7584cc5cb96125ca08f2ad97662c (patch) | |
tree | 9055539f626cc2ce798d895434b6092a9123cf3e /lldb/source/Plugins/ExpressionParser | |
parent | bf03e17c570171c7a52117fe63ace89d58f328d5 (diff) | |
download | bcm5719-llvm-f9f49d3594bc7584cc5cb96125ca08f2ad97662c.tar.gz bcm5719-llvm-f9f49d3594bc7584cc5cb96125ca08f2ad97662c.zip |
[lldb][NFC] Return a reference from ClangASTContext::getASTContext and remove dead nullptr checks
ClangASTContext::getASTContext() currently returns a ptr but we have an assert there since a
while that the ASTContext is not a nullptr. This causes that we still have a lot of code
that is doing nullptr checks on the result of getASTContext() which is all unreachable code.
This patch changes the return value to a reference to make it clear this can't be a nullptr
and deletes all the nullptr checks.
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser')
3 files changed, 13 insertions, 34 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp index 6d6830c740d..1caac9e11cb 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp @@ -453,7 +453,7 @@ void ASTResultSynthesizer::CommitPersistentDecls() { ConstString name_cs(name.str().c_str()); Decl *D_scratch = m_target.GetClangASTImporter()->DeportDecl( - ClangASTContext::GetScratch(m_target)->getASTContext(), decl); + &ClangASTContext::GetScratch(m_target)->getASTContext(), decl); if (!D_scratch) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp index e044a4d33b4..ff86f9f818b 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -57,7 +57,7 @@ ClangASTSource::ClangASTSource(const lldb::TargetSP &target, } void ClangASTSource::InstallASTContext(ClangASTContext &clang_ast_context) { - m_ast_context = clang_ast_context.getASTContext(); + m_ast_context = &clang_ast_context.getASTContext(); m_clang_ast_context = &clang_ast_context; m_file_manager = &m_ast_context->getSourceManager().getFileManager(); m_ast_importer_sp->InstallMapCompleter(m_ast_context, *this); @@ -80,14 +80,11 @@ ClangASTSource::~ClangASTSource() { if (!scratch_clang_ast_context) return; - clang::ASTContext *scratch_ast_context = + clang::ASTContext &scratch_ast_context = scratch_clang_ast_context->getASTContext(); - if (!scratch_ast_context) - return; - - if (m_ast_context != scratch_ast_context && m_ast_importer_sp) - m_ast_importer_sp->ForgetSource(scratch_ast_context, m_ast_context); + if (m_ast_context != &scratch_ast_context && m_ast_importer_sp) + m_ast_importer_sp->ForgetSource(&scratch_ast_context, m_ast_context); } void ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer) { @@ -1880,10 +1877,10 @@ clang::NamedDecl *NameSearchContext::AddVarDecl(const CompilerType &type) { IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo(); - clang::ASTContext *ast = lldb_ast->getASTContext(); + clang::ASTContext &ast = lldb_ast->getASTContext(); clang::NamedDecl *Decl = VarDecl::Create( - *ast, const_cast<DeclContext *>(m_decl_context), SourceLocation(), + ast, const_cast<DeclContext *>(m_decl_context), SourceLocation(), SourceLocation(), ii, ClangUtil::GetQualType(type), nullptr, SC_Static); m_decls.push_back(Decl); @@ -1909,7 +1906,7 @@ clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type, QualType qual_type(ClangUtil::GetQualType(type)); - clang::ASTContext *ast = lldb_ast->getASTContext(); + clang::ASTContext &ast = lldb_ast->getASTContext(); const bool isInlineSpecified = false; const bool hasWrittenPrototype = true; @@ -1919,7 +1916,7 @@ clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type, if (extern_c) { context = LinkageSpecDecl::Create( - *ast, context, SourceLocation(), SourceLocation(), + ast, context, SourceLocation(), SourceLocation(), clang::LinkageSpecDecl::LanguageIDs::lang_c, false); } @@ -1931,7 +1928,7 @@ clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type, : m_decl_name; clang::FunctionDecl *func_decl = FunctionDecl::Create( - *ast, context, SourceLocation(), SourceLocation(), decl_name, qual_type, + ast, context, SourceLocation(), SourceLocation(), decl_name, qual_type, nullptr, SC_Extern, isInlineSpecified, hasWrittenPrototype, isConstexprSpecified ? CSK_constexpr : CSK_unspecified); @@ -1952,7 +1949,7 @@ clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type, QualType arg_qual_type(func_proto_type->getParamType(ArgIndex)); parm_var_decls.push_back( - ParmVarDecl::Create(*ast, const_cast<DeclContext *>(context), + ParmVarDecl::Create(ast, const_cast<DeclContext *>(context), SourceLocation(), SourceLocation(), nullptr, arg_qual_type, nullptr, SC_Static, nullptr)); } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp index 23202766892..e9ba1bffd34 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -179,7 +179,7 @@ TypeFromUser ClangExpressionDeclMap::DeportType(ClangASTContext &target, TypeFromParser parser_type) { assert(&target == ClangASTContext::GetScratch(*m_target)); assert((TypeSystem *)&source == parser_type.GetTypeSystem()); - assert(source.getASTContext() == m_ast_context); + assert(&source.getASTContext() == m_ast_context); if (m_ast_importer_sp) { return TypeFromUser(m_ast_importer_sp->DeportType(target, parser_type)); @@ -741,16 +741,7 @@ clang::NamedDecl *ClangExpressionDeclMap::GetPersistentDecl(ConstString name) { if (!target) return nullptr; - ClangASTContext *scratch_clang_ast_context = - ClangASTContext::GetScratch(*target); - - if (!scratch_clang_ast_context) - return nullptr; - - ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext(); - - if (!scratch_ast_context) - return nullptr; + ClangASTContext::GetScratch(*target); return m_parser_vars->m_persistent_vars->GetPersistentDecl(name); } @@ -1528,15 +1519,6 @@ bool ClangExpressionDeclMap::GetVariableValue(VariableSP &var, return false; } - ASTContext *ast = clang_ast->getASTContext(); - - if (!ast) { - if (log) - log->PutCString( - "There is no AST context for the current execution context"); - return false; - } - DWARFExpression &var_location_expr = var->LocationExpression(); Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr(); |