Skip to content

Commit

Permalink
[lldb] Remove some uses of getPointerElementType()
Browse files Browse the repository at this point in the history
While in the area, remove some uses of getPointerElementType()
that have obvious replacements.
  • Loading branch information
nikic committed Feb 14, 2022
1 parent e01f624 commit ad1feef
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
16 changes: 1 addition & 15 deletions lldb/source/Expression/IRInterpreter.cpp
Expand Up @@ -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();
Expand Down
10 changes: 4 additions & 6 deletions lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
Expand Up @@ -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);
Expand Down

0 comments on commit ad1feef

Please sign in to comment.