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/Clang/ClangASTSource.cpp | |
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/Clang/ClangASTSource.cpp')
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
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)); } |