<div dir="ltr">Nick, consider:<div><br></div><div><div>char a[0];</div><div>char b[0];</div><div><br></div></div><div>at run-time:</div><div><div>(gdb) p &a</div><div>$1 = (char (*)[]) 0x60103c</div><div>(gdb) p &b</div><div>$2 = (char (*)[]) 0x60103c</div></div><div><br></div><div>Even if this is not safe at the C or C++ level, this comparison could return equal or not equal depending on what the linker chooses to do.</div><div><br></div><div>Do we have a bug in the constant folder?</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 7, 2014 at 11:16 PM, Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Chengyu Song wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It's difficult to say without a full example, but I'm very suspicious<br>
of those global declarations. I think the compiler would be entirely<br>
justified in assuming you could *never* get from __start_builtin_fw to<br>
__end_builtin_fw, let alone on the first iteration: they're distinct<br>
array objects and by definition (within C99) can't overlap.<br>
</blockquote>
<br>
I think this should be the root cause. Once I changed the declaration to pointers (instead of arrays):<br>
<br>
extern struct builtin_fw* __start_builtin_fw;<br>
extern struct builtin_fw* __end_builtin_fw;<br>
<br>
The generated code will not skip the first comparison.<br>
<br>
Sadly, Linux kernel may contain more such declarations.<br>
</blockquote>
<br></span>
That's a great point. Maybe clang could issue a warning on these, any for loop that declares a pointer to the address of a non-weak object, compares it to a different object, and increments only the pointer (without doing other changes to the pointer inside the loop body). We know that's a buggy pattern. Could you file a feature request for this on <a href="http://llvm.org/bugs" target="_blank">llvm.org/bugs</a> ?<span class="HOEnZb"><font color="#888888"><br>
<br>
Nick</font></span><div class="HOEnZb"><div class="h5"><br>
______________________________<u></u>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div>