<div dir="ltr"><div>This isn't really devirtualization so much as global opt plus basic constant propagation. My theory is that iostream injects static initializers for std::cout / std::cerr into your TU. LLVM's global opt pass will fail when those are present.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 7, 2015 at 12:03 AM, martin krastev <span dir="ltr"><<a href="mailto:blu.dark@gmail.com" target="_blank">blu.dark@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 dir="ltr">Hello,<div><br></div><div>I've stumbled upon the following behavior in branches/release_35 (as of 218689) under ubuntu 14.04 LTS amd64: whenever I include the (system-wise) gnu iostream header, clang++ stops devirtualizing the following code:</div><div><br></div><div><br></div><div><div>#if BREAKAGE_ENSUES</div><div>#include <iostream></div><div>#endif</div><div><br></div><div>struct Base {</div><div><span style="white-space:pre-wrap"> </span>virtual int foo() const = 0;</div><div>};</div><div><br></div><div>struct A : Base {</div><div><span style="white-space:pre-wrap"> </span>int a;</div><div><br></div><div><span style="white-space:pre-wrap"> </span>A(const int a) </div><div><span style="white-space:pre-wrap"> </span>: a(a) {</div><div><span style="white-space:pre-wrap"> </span>}</div><div><br></div><div><span style="white-space:pre-wrap"> </span>int foo() const {</div><div><span style="white-space:pre-wrap"> </span>return a;</div><div><span style="white-space:pre-wrap"> </span>}</div><div>};</div><div><br></div><div>struct B : Base {</div><div><span style="white-space:pre-wrap"> </span>const Base* b;</div><div><br></div><div><span style="white-space:pre-wrap"> </span>B(const Base* const base)</div><div><span style="white-space:pre-wrap"> </span>: b(base) {</div><div><span style="white-space:pre-wrap"> </span>}</div><div><br></div><div><span style="white-space:pre-wrap"> </span>int foo() const {</div><div><span style="white-space:pre-wrap"> </span>return b->foo();</div><div><span style="white-space:pre-wrap"> </span>}</div><div>};</div><div><br></div><div>const A a(42);</div><div>const B b(&a);</div><div><br></div><div>int main(int, char**) {</div><div><span style="white-space:pre-wrap"> </span>return b.foo();</div><div>}</div></div><div><br></div><div><br></div><div>Is that a known issue, and if not, under what category should I file a ticket for it?</div><div><br></div><div>Best regards,</div><div>Martin</div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">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/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>