Alexandru Ionut Diaconescu
2013-Jan-08 12:23 UTC
[LLVMdev] LLVM seg fault : dereference an uninitialized pointer Instruction*
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>
Krzysztof Parzyszek
2013-Jan-08 20:02 UTC
[LLVMdev] LLVM seg fault : dereference an uninitialized pointer Instruction*
On 1/8/2013 6:23 AM, Alexandru Ionut Diaconescu wrote:> 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.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). -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation