c++ - 未捕获 LLVM IR : find_if, var

标签 c++ llvm-ir

所以我的代码中有以下片段

  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/

相关文章:

c++ - 枚举被定义为结构中的 uint8_t 变量

c++ - `std::function` 和之前推导的模板参数的替换失败 - 为什么?

llvm - 如何在 llvm 中构建新的 SDNode?

compiler-construction - Mindustry Game CPU 架构的最简单编译器

llvm - 如何获得给定指令的下一条立即指令?

clang - 如何在 llvm 编译时将 DWARF 信息转储到文件中?

c++ - LLVM 错误 : Broken function found, 编译中止!在 removeFromParent() 之后

c++ - 非标准条件排序算法STL c++

c++ - 如何按条件打印位图?

c++ - DDX_Control 和 DDX_Check 正在崩溃