gpt4 book ai didi

c++ - LLVM 存储操作数必须是指针

转载 作者:行者123 更新时间:2023-11-28 04:18:48 33 4
gpt4 key购买 nike

我正在尝试将全局变量的值存储到自定义 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,但我不知道如何修复我的代码以实现这一点。如何修复此错误?

最佳答案

交换store的操作数:第一个是what,第二个是where。

关于c++ - LLVM 存储操作数必须是指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55953334/

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