gpt4 book ai didi

c++ - 如何将参数传递给我在 LLVM 传递中使用 CallInst::Create(...) 调用的外部函数?

转载 作者:行者123 更新时间:2023-11-28 05:20:43 30 4
gpt4 key购买 nike

这就是我想要做的:

     if(isa<CallInst>(&(*BI)) )
{
ArrayRef <Value *> arguments('c');
StringRef fname = cast<CallInst>(&(*BI))->getCalledFunction()->getName();
errs()<<fname + " was called\n";
//CallInst *CI = dyn_cast<CallInst>(BI);
if(fname=="pthread_mutex_lock"){
Instruction *newInst = CallInst::Create(hook, arguments, "");
BB->getInstList().insert(BI, newInst);
}

其中“钩子(Hook)”是函数。我得到的错误是:

no matching constructor for initialization of 'ArrayRef' ArrayRef arguments('c');

当我改变 ArrayRef <Value *> arguments('c')ArrayRef <char> arguments('c')错误变为:

no matching function for call to 'Create' Instruction *newInst = CallInst::Create(hook, argume... ^~~~~~~~~~~~~~~~ /.../llvm/IR/Instructions.h:1187:20: note: candidate function not viable: no known conversion from 'ArrayRef' to 'ArrayRef' for 2nd argument static CallInst *Create(Value *Func, ^ /.../llvm/llvm-3.4/include/llvm/IR/Instructions.h:1200:20: note: candidate function not viable: no known conversion from 'ArrayRef' to 'const llvm::Twine' for 2nd argument static CallInst *Create(Value *F, const Twine &NameStr = "", ^ /.../llvm/llvm-3.4/include/llvm/IR/Instructions.h:1204:20: note: candidate function not viable: no known conversion from 'ArrayRef' to 'const llvm::Twine' for 2nd argument static CallInst *Create(Value *F, const Twine &NameStr, ^ /.../llvm/llvm-3.4/include/llvm/IR/Instructions.h:1194:20: note: candidate function not viable: requires 4 arguments, but 3 were provided static CallInst *Create(Value *Func, ^

我不了解如何将参数传递给我在 LLVM 传递中调用的外部函数,因为我是新手。帮助将不胜感激!

最佳答案

CallInst::Create 需要 ArrayRef < Value* > 作为参数

所以现在当你初始化 ArrayRef < Value * > arguments('c') 时,这里没有内置构造函数来将 char 'c' 转换为 Value*

你可以做到

ArrayRef< Value* > arguments(ConstantInt::get(Type::getInt8Ty(llvmContext), 'c'));

或者您可以直接将单个 i8 类型整数传递给 CallInst::Create 调用

Instruction *newInst = CallInst::Create(hook, ArrayRef< Value* >{ConstantInt::get(Type::getInt8Ty(llvmContext), 'c')}, "");

参见 http://llvm.org/docs/doxygen/html/classllvm_1_1CallInst.htmlhttp://llvm.org/docs/doxygen/html/classllvm_1_1ArrayRef.html#details了解更多详情。

关于c++ - 如何将参数传递给我在 LLVM 传递中使用 CallInst::Create(...) 调用的外部函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41563459/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com