LLVM IR: find_if, var not captured

494 views Asked by At

So I have following snippet in my code

  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;
    }
 }

In the line 6, I get error as: LoadOperand not captured.

I had tried a dummy (not of LLVM type, just normal C++ code) implementation to see if such thing works, and it did function properly. Now here I am not sure if the error is associated with LLVM or generic C++.

Any suggestions?

1

There are 1 answers

3
Spectral Sequence On BEST ANSWER

The error is referring to the fact that you aren't capturing LoadOperand in the lambda expression in the call to std::find_if. You can capture it by reference with [&LoadOperand] as in this expression:

std::find_if(DataStructureForTrace.begin(), DataStructureForTrace.end(), [&LoadOperand](const std::tuple<Value*, unsigned, unsigned, Value* >& e) {return *(std::get<3>(e)) == *(LoadOperand);});