I cannot create an llvm ir for regression test.  I test the llvm ir, which causes the uninitialized value in my program, with llc, but cannot reproduce the issue with valgrind.  I think that it is related to the order and types of different ir transformations between llc and my program, or llc goes to the branch to create DataLayout directly from Module, not from copy constructor. Maybe someone familiar with the ir transformation details could come up a test case. <div>

<br></div><div>But if you follows the llvm tutorial at <a href="http://llvm.org/docs/tutorial/LangImpl4.html">http://llvm.org/docs/tutorial/LangImpl4.html</a>  </div><div><pre style="overflow-x:auto;overflow-y:hidden;font-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-size:0.95em;line-height:16px;padding:0.5em;border:1px solid rgb(204,204,204);background-color:rgb(248,248,248)">

<span class="n">OurFPM</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="k" style="color:rgb(0,112,32);font-weight:bold">new</span> <span class="n">DataLayout</span><span class="p">(</span><span class="o" style="color:rgb(102,102,102)">*</span><span class="n">TheExecutionEngine</span><span class="o" style="color:rgb(102,102,102)">-></span><span class="n">getDataLayout</span><span class="p">()));</span></pre>

</div><div>This would put a bomb in your code.  When you were lucky, StackNaturalAlign is given some value and program works; otherwise, lead to undefined behaviors and days to debug...<div><div><br></div><br><div class="gmail_quote">


On Wed, Feb 27, 2013 at 12:05 AM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div>On Tue, Feb 26, 2013 at 8:37 PM, Peng Cheng <<a href="mailto:gm4cheng@gmail.com" target="_blank">gm4cheng@gmail.com</a>> wrote:<br>
> The usual llvm regression tests for a standard constructor bug seems like an<br>
> overkill, leading to many wasteful code exercises, such as ir reading,<br>
> optimization, code generation, ...<br>
<br>
</div>While I'm the last to advocate for indirect testing, this is generally<br>
the attitude in the LLVM project - to exercise from the actual<br>
user-programs. This ensures better coverage (though not necessarily<br>
actually /testing/ all of that, of course) in some ways, worse<br>
coverage in others.<br>
<div><br>
> Are there any other places to place the unit tests for classes in llvm code<br>
> base?  Simply to test whether all the necessary fields are initialized after<br>
> the copy constructor.<br>
<br>
</div>We do have true API-level unit tests as well - just not often written,<br>
usually only for core/generic data structures & the like.<br>
<div><div><br>
><br>
><br>
> On Tue, Feb 26, 2013 at 10:51 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br>
>><br>
>> On Tue, Feb 26, 2013 at 7:34 PM, Peng Cheng <<a href="mailto:gm4cheng@gmail.com" target="_blank">gm4cheng@gmail.com</a>> wrote:<br>
>> > It did not fail on any valgrind bots.  But when I used valgrind to check<br>
>> > my<br>
>> > jit engine based on llvm, I found the bug.<br>
>> ><br>
>> > Could you point to me an example of test case for the valgrind bot?  I<br>
>> > need<br>
>> > to see how the test infrastructure is setup in llvm.<br>
>><br>
>> The current public valgrind bot (<br>
>> <a href="http://lab.llvm.org:8011/builders/clang-x86_64-linux-vg" target="_blank">http://lab.llvm.org:8011/builders/clang-x86_64-linux-vg</a> - there may be<br>
>> others) just runs the usual LLVM/Clang regression tests. So if you can<br>
>> construct a nice small/simple regression test you can add that (&<br>
>> limit the test to only running under valgrind, potentially)<br>
>><br>
>> > On Tue, Feb 26, 2013 at 10:28 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> On Tue, Feb 26, 2013 at 7:15 PM, Peng Cheng <<a href="mailto:gm4cheng@gmail.com" target="_blank">gm4cheng@gmail.com</a>> wrote:<br>
>> >> > The copy constructor of class DataLayout fails to initialize<br>
>> >> > StackNaturalAlign.  It could lead to conditional jump on<br>
>> >> > uninitialized<br>
>> >> > variables in member function exceedsNaturalStackAlignment.<br>
>> >><br>
>> >> Does this fail any valgrind bots? Could you write a test case that<br>
>> >> would fail under valgrind?<br>
>> >><br>
>> >> > See fix in the patch attached.<br>
>> >> ><br>
>> >> > _______________________________________________<br>
>> >> > llvm-commits mailing list<br>
>> >> > <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
>> >> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
>> >> ><br>
>> ><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br>
</div></div>