[lldb] Remove some uses of getPointerElementType()
authorNikita Popov <npopov@redhat.com>
Mon, 14 Feb 2022 08:43:59 +0000 (09:43 +0100)
committerNikita Popov <npopov@redhat.com>
Mon, 14 Feb 2022 08:44:37 +0000 (09:44 +0100)
While in the area, remove some uses of getPointerElementType()
that have obvious replacements.

lldb/source/Expression/IRInterpreter.cpp
lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp

index 338d387..42da0e1 100644 (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();
index fee1a2a..10d1e99 100644 (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));
index 0233271..f5c3c13 100644 (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);