I encounter a segfault problem in my LLVM function pass. I think the problem is that I dereference an uninitialized pointer from an array of Instruction* elements which results in undefined behavior. The array is :
<br>Instruction** ifsInstrArray = new Instruction*; <br><br>
The problem appears only sometimes (during runOnFunction && visiting BasicBlocks and Instructions). Sometimes means, for e.g. :
only for ifsInstrArray the segfault appears. I already checked if ifsInstrArray is not NULL. Please note that the above is only a test for my primary segfault problem. The primary segfault problem is : More precisely, I am trying to check if two instructions are equivalent by using
<br>if ( CC->operEquiv(ifsInstrArray[i], ifsInstrArray[j]) )<br><br>
where CC and operEquiv are defined by me. If extra code is needed, please let me know. The seg fault appears here. I think that the problem is related with the “test problem” defined at the beginning of the question. Can you please tell me how can I initialize the ifsInstrArray array? And for its elements I should use the constructor of Instruction (I cannot find it in Instruction.h)? I cannot initialize the elements by assigning NULL.
Thank you for your answer !
PS: i,j are boundary-ok in my for loops;
ifChecker* CC=new ifChecker();in ifChecker class there is:
virtual bool operEquiv(Instruction *I1, Instruction *I2);
LLVM seg fault : dereference an uninitialized pointer Instruction*
You need to make sure that the pointers in the array actually point to instructions. I suspect that your code tries to dereference pointers that have indeterminate values (i.e. are uninitialized).