From ad1feef7b2097090df0d41ad4c35c688dbe1c34a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 14 Feb 2022 09:43:59 +0100 Subject: [PATCH] [lldb] Remove some uses of getPointerElementType() While in the area, remove some uses of getPointerElementType() that have obvious replacements. --- lldb/source/Expression/IRInterpreter.cpp | 16 +--------------- .../Plugins/ExpressionParser/Clang/IRForTarget.cpp | 10 ++++------ .../RenderScriptRuntime/RenderScriptx86ABIFixups.cpp | 11 +++++------ 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/lldb/source/Expression/IRInterpreter.cpp b/lldb/source/Expression/IRInterpreter.cpp index 338d387..42da0e1 100644 --- a/lldb/source/Expression/IRInterpreter.cpp +++ b/lldb/source/Expression/IRInterpreter.cpp @@ -1376,21 +1376,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb_private::DiagnosticManager diagnostics; lldb_private::EvaluateExpressionOptions options; - // We generally receive a function pointer which we must dereference - llvm::Type *prototype = val->getType(); - if (!prototype->isPointerTy()) { - error.SetErrorToGenericError(); - error.SetErrorString("call need function pointer"); - return false; - } - - // Dereference the function pointer - prototype = prototype->getPointerElementType(); - if (!(prototype->isFunctionTy() || prototype->isFunctionVarArg())) { - error.SetErrorToGenericError(); - error.SetErrorString("call need function pointer"); - return false; - } + llvm::FunctionType *prototype = call_inst->getFunctionType(); // Find number of arguments const int numArgs = call_inst->arg_size(); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp index fee1a2a..10d1e99 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp @@ -328,9 +328,8 @@ bool IRForTarget::CreateResultVariable(llvm::Function &llvm_function) { // Construct a new result global and set up its metadata GlobalVariable *new_result_global = new GlobalVariable( - (*m_module), result_global->getValueType(), - false, /* not constant */ - GlobalValue::ExternalLinkage, nullptr, /* no initializer */ + (*m_module), result_global->getValueType(), false, /* not constant */ + GlobalValue::ExternalLinkage, nullptr, /* no initializer */ m_result_name.GetCString()); // It's too late in compilation to create a new VarDecl for this, but we @@ -1106,9 +1105,8 @@ bool IRForTarget::RewritePersistentAlloc(llvm::Instruction *persistent_alloc) { // Now, since the variable is a pointer variable, we will drop in a load of // that pointer variable. - LoadInst *persistent_load = - new LoadInst(persistent_global->getType()->getPointerElementType(), - persistent_global, "", alloc); + LoadInst *persistent_load = new LoadInst(persistent_global->getValueType(), + persistent_global, "", alloc); LLDB_LOG(log, "Replacing \"{0}\" with \"{1}\"", PrintValue(alloc), PrintValue(persistent_load)); diff --git a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp index 0233271..f5c3c13 100644 --- a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp +++ b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp @@ -187,18 +187,17 @@ static bool fixupX86StructRetCalls(llvm::Module &module) { (new llvm::StoreInst(new_func_cast, new_func_ptr, call_inst)) ->setName("new_func_ptr_load_cast"); // load the new function address ready for a jump - llvm::LoadInst *new_func_addr_load = - new llvm::LoadInst(new_func_ptr->getType()->getPointerElementType(), - new_func_ptr, "load_func_pointer", call_inst); + llvm::LoadInst *new_func_addr_load = new llvm::LoadInst( + new_func_ptr_type, new_func_ptr, "load_func_pointer", call_inst); // and create a callinstruction from it llvm::CallInst *new_call_inst = llvm::CallInst::Create(new_func_type, new_func_addr_load, new_call_args, "new_func_call", call_inst); new_call_inst->setCallingConv(call_inst->getCallingConv()); new_call_inst->setTailCall(call_inst->isTailCall()); - llvm::LoadInst *lldb_save_result_address = new llvm::LoadInst( - return_value_alloc->getType()->getPointerElementType(), - return_value_alloc, "save_return_val", call_inst); + llvm::LoadInst *lldb_save_result_address = + new llvm::LoadInst(func->getReturnType(), return_value_alloc, + "save_return_val", call_inst); // Now remove the old broken call call_inst->replaceAllUsesWith(lldb_save_result_address); -- 2.7.4