<div dir="ltr">On Fri, Aug 16, 2013 at 3:20 PM, Riyaz Puthiyapurayil <span dir="ltr"><<a href="mailto:Riyaz.Puthiyapurayil@synopsys.com" target="_blank">Riyaz.Puthiyapurayil@synopsys.com</a>></span> wrote:<br><div class="gmail_extra">
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="">Consider the following C code. When it is compiled using clang with ‘ –O’, the assert fires. Gcc seems to do the opposite.
<u></u><u></u></p>
<p class=""><u></u> <u></u></p>
<p class="" style="margin-left:0.5in"><span style="font-family:Consolas">#include <assert.h>                                                                          
<u></u><u></u></span></p>
<p class="" style="margin-left:0.5in"><span style="font-family:Consolas">int main()                                                                      <u></u><u></u></span></p>
<p class="" style="margin-left:0.5in"><span style="font-family:Consolas">{                                                                              
<u></u><u></u></span></p>
<p class="" style="margin-left:0.5in"><span style="font-family:Consolas">    unsigned a;     // uninitialized!                                
<u></u><u></u></span></p>
<p class="" style="margin-left:0.5in"><span style="font-family:Consolas">    unsigned b = a;                                                                                                                                           <u></u><u></u></span></p>

<p class="" style="margin-left:0.5in"><span style="font-family:Consolas">    assert(b == a); // shouldn’t this be always true?                                                                                                                      <u></u><u></u></span></p>

<p class="" style="margin-left:0.5in"><span style="font-family:Consolas">    return 0;                                                                  
<u></u><u></u></span></p>
<p class="" style="margin-left:0.5in"><span style="font-family:Consolas">}          
<u></u><u></u></span></p>
<p class=""><u></u> <u></u></p>
<p class="">Would you consider this a LLVM bug? I think GVN is responsible for this. I don’t know if it falls within the realm of “undefined” or “implementation specific” behavior but there are probably examples of code where one can “correctly” skip
 initialization. The Briggs-Torczon sparse set data structure comes to mind (where you are not comparing two uninitialized variables but an uninitialized variable with an initialized variable—LLVM seems to do the right thing in that case, though).</p>
</div></div></blockquote></div></div><div class="gmail_extra">Loading from an uninitialized variable is undefined behavior.  You might be interested in Chris Lattner's series on undefined behavior at <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html">http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html</a> .</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">-Eli</div></div>