【发布时间】:2019-05-02 13:14:39
【问题描述】:
我正在尝试将全局变量的值存储到自定义 LLVM Pass 中函数的局部变量中。
全局变量定义为
GlobalVariable* gvar_int32_test = new GlobalVariable(
/*Module=*/ M,
/*Type=*/ IntegerType::get(M.getContext(), 32),
/*isConstant=*/ false,
/*Linkage=*/ GlobalValue::CommonLinkage,
/*Initializer=*/0, // has initializer, specified below
/*Name=*/"global_test_var");
gvar_int32_test->setAlignment(4);
我打算存储的局部变量最初被用作调用指令的存储位置。我尝试使用
来获取这个值Value* localVar = ci->getOperand(0) //ci is the call instruction
使用 IR 构建器,我尝试将存储指令编写为:
StoreInst* strLocIns = builder.CreateStore(gvar_int32_test, localVar, false);
//my intent is to create an instruction that means localvar = globalvar;
同样,在前面的代码中,我尝试将被调用函数的返回指令中的值存储到全局变量中
Value* value = ri->getReturnValue(); //ri is the return instruction
// Some more code, including setting the IR builder insertion point
StoreInst* strIns = builder.CreateStore(value, gvar_int32_test, false);
//here the intention is globalvar = localvar
当我尝试编译包含我的通行证时,我收到错误:
Store operand must be a pointer.
store i32* @global_test_var, i32 %5
我不确定我做错了什么。我传递给 IR 构建器的变量的两个参数都是指针,但是 IR 以某种方式被破坏了。我认为 i32 %5 应该是 i32* %5 以表明 %5 指向 i32,但我不知道如何修复我的代码以实现这一点。如何解决此错误?
【问题讨论】: