I'm trying to get the pointer to each instruction, which supposedly can be achieved by doing:
Value* ptr = dyn_cast<Value>(&inst);
However, I keep getting a segmentation fault when running the compiled C++ program with cmake. In debug mode, I get the following error message:
opt-11: /usr/lib/llvm-11/include/llvm/IR/User.h:170: llvm::Value* llvm::User::getOperand(unsigned int)
const: Assertion `i < NumUserOperands && "getOperand() out of range!"' failed.
In LLVM doc, here is the block of code that points to the source of the assertion:
Value *getOperand(unsigned i) const {
assert(i < NumUserOperands && "getOperand() out of range!");
return getOperandList()[i];
}
I added empty check to every variable acquired from getOperand() in the program but the error remains. Does anyone know why it's happening and how to fix it?
dyn_cast<>to cast toValuedoesn't make sense.Valueis the root class. If you have anInstruction*you already haveValue*, there's nothing left fordyn_cast<>to do.