LLVM:使用空指针操作数创建 CallInst
LLVM: Creating a CallInst with a null pointer operand
我正在尝试使用 LLVM C++ 绑定编写生成以下 IR 的传递
%1 = call i64 @time(i64* null) #3
@time
这里是 C 标准库 time()
函数。
这是我写的代码
void Pass::Insert(BasicBlock *bb, Type *timety, Module *m) {
Type *timetype[1];
timetype[0] = timety;
ArrayRef<Type *> timeTypeAref(timetype, 1);
Value *args[1];
args[0] = ConstantInt::get(timety, 0, false);
ArrayRef<Value *> argsRef(args, 1);
FunctionType *signature = FunctionType::get(timety, false);
Function *timeFunc =
Function::Create(signature, Function::ExternalLinkage, "time", m);
IRBuilder<> Builder(&*(bb->getFirstInsertionPt()));
AllocaInst *a1 = Builder.CreateAlloca(timety, nullptr, Twine("a1"));
CallInst *c1 = Builder.CreateCall(timeFunc, args, Twine("time"));
}
这可以编译,但在 运行
时会导致以下错误
Incorrect number of arguments passed to called function!
%time = call i64 @time(i64 0)
据我了解,我需要传递一个引用 nullptr
的 int64 指针,但我不知道该怎么做。
LLVM 提供了一个 ConstantPointerNull
class 它完全符合我的要求 - 它 returns 一个所需类型的空指针。
所有需要更改的是以args[0] = ...
开头的行
args[0] = ConstantPointerNull::get(PointerType::get(timety, 0));
.
我正在尝试使用 LLVM C++ 绑定编写生成以下 IR 的传递
%1 = call i64 @time(i64* null) #3
@time
这里是 C 标准库 time()
函数。
这是我写的代码
void Pass::Insert(BasicBlock *bb, Type *timety, Module *m) {
Type *timetype[1];
timetype[0] = timety;
ArrayRef<Type *> timeTypeAref(timetype, 1);
Value *args[1];
args[0] = ConstantInt::get(timety, 0, false);
ArrayRef<Value *> argsRef(args, 1);
FunctionType *signature = FunctionType::get(timety, false);
Function *timeFunc =
Function::Create(signature, Function::ExternalLinkage, "time", m);
IRBuilder<> Builder(&*(bb->getFirstInsertionPt()));
AllocaInst *a1 = Builder.CreateAlloca(timety, nullptr, Twine("a1"));
CallInst *c1 = Builder.CreateCall(timeFunc, args, Twine("time"));
}
这可以编译,但在 运行
时会导致以下错误Incorrect number of arguments passed to called function!
%time = call i64 @time(i64 0)
据我了解,我需要传递一个引用 nullptr
的 int64 指针,但我不知道该怎么做。
LLVM 提供了一个 ConstantPointerNull
class 它完全符合我的要求 - 它 returns 一个所需类型的空指针。
所有需要更改的是以args[0] = ...
开头的行
args[0] = ConstantPointerNull::get(PointerType::get(timety, 0));
.