I have the following LLVM code. The strange thing is that the si variable of type StoreInst becomes null(0) immediately after it is allocated with new instruction outside the if block, whereas I have declared it at an outer scope. What is going on here?
Value *OldVal = NULL;
StoreInst* si = NULL;
if ( ... )
{
if ( ... )
{
....
if ( ... )
{
...
StoreInst* si = new StoreInst(...);
errs() << "si = " << si << "\n"; // Get some address here
}
errs() << "-->SI = " << si << "\n"; // Here I get NULL, why?
}
...
}
I get an output like this,
si = 0x1822ba0
-->SI = 0x0
StoreInst* si = new StoreInst(...);– You hidden the previos namesihereWhen the scope is ended
}– you see the value of another pointerHere is an example of what you did:
I’ve used
intin the example for simplicity. Actually it can be any type