[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.
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 2320276..e9ba1bf 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -179,7 +179,7 @@
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 @@
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 @@
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();