From c54d21c848d350e85cd8f95a725fc12f6fa3ab19 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Tue, 19 Nov 2019 14:47:37 +0100 Subject: [PATCH] [lldb][NFC] Early exit in IRExecutionUnit::GetStaticInitializers --- lldb/source/Expression/IRExecutionUnit.cpp | 50 ++++++++++++---------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index b10628e10cc5..105f875fa1d2 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -977,30 +977,34 @@ IRExecutionUnit::FindSymbol(lldb_private::ConstString name, bool &missing_weak) void IRExecutionUnit::GetStaticInitializers( std::vector &static_initializers) { - if (llvm::GlobalVariable *global_ctors = - m_module->getNamedGlobal("llvm.global_ctors")) { - if (llvm::ConstantArray *ctor_array = llvm::dyn_cast( - global_ctors->getInitializer())) { - for (llvm::Use &ctor_use : ctor_array->operands()) { - if (llvm::ConstantStruct *ctor_struct = - llvm::dyn_cast(ctor_use)) { - lldbassert(ctor_struct->getNumOperands() == - 3); // this is standardized - if (llvm::Function *ctor_function = - llvm::dyn_cast(ctor_struct->getOperand(1))) { - ConstString ctor_function_name_cs(ctor_function->getName().str()); + llvm::GlobalVariable *global_ctors = + m_module->getNamedGlobal("llvm.global_ctors"); + if (!global_ctors) + return; + auto *ctor_array = + llvm::dyn_cast(global_ctors->getInitializer()); + if (!ctor_array) + return; - for (JittedFunction &jitted_function : m_jitted_functions) { - if (ctor_function_name_cs == jitted_function.m_name) { - if (jitted_function.m_remote_addr != LLDB_INVALID_ADDRESS) { - static_initializers.push_back(jitted_function.m_remote_addr); - } - break; - } - } - } - } - } + for (llvm::Use &ctor_use : ctor_array->operands()) { + auto *ctor_struct = llvm::dyn_cast(ctor_use); + if (!ctor_struct) + continue; + // this is standardized + lldbassert(ctor_struct->getNumOperands() == 3); + auto *ctor_function = + llvm::dyn_cast(ctor_struct->getOperand(1)); + if (!ctor_function) + continue; + ConstString ctor_function_name_cs(ctor_function->getName().str()); + + for (JittedFunction &jitted_function : m_jitted_functions) { + if (ctor_function_name_cs != jitted_function.m_name) + continue; + if (jitted_function.m_remote_addr == LLDB_INVALID_ADDRESS) + continue; + static_initializers.push_back(jitted_function.m_remote_addr); + break; } } }