[LLVMdev] LLVM seg fault : dereference an uninitialized pointer Instruction*

Alexandru Ionut Diaconescu alexandruionutdiaconescu at gmail.com
Tue Jan 8 04:23:35 PST 2013


Hello everyone,

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 :

Instruction** ifsInstrArray = new Instruction*[100];

The problem appears only sometimes (during runOnFunction && visiting
BasicBlocks and Instructions). Sometimes means, for e.g. :

errs()<<*ifsInstrArray[0]<<"\n"<<*ifsInstrArray[1];

only for *ifsInstrArray[1] the segfault appears. I already checked if
ifsInstrArray[1] 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

if ( CC->operEquiv(ifsInstrArray[i], ifsInstrArray[j]) )

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


-- 
Best regards,
Alexandru Ionut Diaconescu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130108/18cdaad3/attachment.html>


More information about the llvm-dev mailing list