所以我的代码中有以下片段
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I){
Instruction *Inst = &*I;
if (isa<LoadInst>(Inst)) {
LoadInst *LI = dyn_cast<LoadInst>(Inst);
Value * LoadOperand = LI -> getPointerOperand();
auto it = std::find_if(DataStructureForTrace.begin(), DataStructureForTrace.end(), [](const std::tuple<Value*, unsigned, unsigned, Value* >& e) {return *(std::get<3>(e)) == *(LoadOperand);});
std::get<2>(*it) = 1;
}
}
在第 6 行中,我得到错误:LoadOperand
not captured。
我曾尝试过一个虚拟的(不是 LLVM 类型,只是普通的 C++ 代码)实现来查看这样的东西是否有效,并且它确实运行正常。现在我不确定错误是与 LLVM 还是通用 C++ 相关。
有什么建议吗?
最佳答案
该错误是指您在调用 std::find_if
时没有在 lambda 表达式中捕获 LoadOperand
。您可以使用 [&LoadOperand]
引用来捕获它,如以下表达式所示:
std::find_if(DataStructureForTrace.begin(), DataStructureForTrace.end(), [&LoadOperand](const std::tuple<Value*, unsigned, unsigned, Value* >& e) {return *(std::get<3>(e)) == *(LoadOperand);});
关于c++ - 未捕获 LLVM IR : find_if, var,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41175453/