<table><tbody><tr><td class="votecell"><div class="vote">
<span class="vote-count-post "></span><br>
</div>
</td>
<td class="postcell">
<div>
<div class="post-text">
<p>Hello everyone,<br></p><p>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 :</p>
<pre><code>Instruction** ifsInstrArray = new Instruction*[100];
</code></pre>
<p>The problem appears only sometimes (during runOnFunction &&
visiting BasicBlocks and Instructions). Sometimes means, for e.g. : </p>
<pre><code>errs()<<*ifsInstrArray[0]<<"\n"<<*ifsInstrArray[1];
</code></pre>
<p>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</p>
<pre><code>if ( CC->operEquiv(ifsInstrArray[i], ifsInstrArray[j]) )
</code></pre>
<p>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. <br></p><p>Thank you for your answer !</p>
<p>PS: i,j are boundary-ok in my for loops; <code>ifChecker* CC=new ifChecker();</code> in ifChecker class there is: <code>virtual bool operEquiv(Instruction *I1, Instruction *I2);</code></p>
</div></div></td></tr></tbody></table><br clear="all"><br>-- <br><font style="background-color:rgb(255,255,255);color:rgb(153,153,153)">Best regards,</font><br style="background-color:rgb(255,255,255);color:rgb(153,153,153)">
<font style="background-color:rgb(255,255,255);color:rgb(153,153,153)">Alexandru Ionut Diaconescu</font><br>