[lldb] Remove some uses of getPointerElementType()

While in the area, remove some uses of getPointerElementType()
that have obvious replacements.
This commit is contained in:
Nikita Popov 2022-02-14 09:43:59 +01:00
parent e01f624adb
commit ad1feef7b2
3 changed files with 10 additions and 27 deletions

View file

@ -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();

View file

@ -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));

View file

@ -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);