<div dir="rtl"><div dir="ltr">What happens if built with -O0 ?<br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div dir="ltr">2016-06-15 0:53 GMT+03:00 George Balatsouras via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span>:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px">Hi everyone,</span><div><br></div><div>I've encountered some strange bitcode translation of a dynamic library which uses boost. The library is compiled to LLVM bitcode with clang 3.7.<div>The LLVM type for class <span style="color:rgb(44,45,48);font-family:monospace;line-height:22px;background-color:rgb(249,249,249)">boost::bad_lexical_cast</span> is represented as follows:</div><div><br></div><div><font face="monospace"><span style="color:rgb(44,45,48);line-height:22px;background-color:rgb(249,249,249)">%"class.boost::bad_lexical_cast" = type { <b>%"class.std::bad_alloc"</b>, %"class.std::type_info"*</span><b style="color:rgb(44,45,48);line-height:22px;background-color:rgb(249,249,249)">​<span style="display:inline-block;vertical-align:baseline;width:1px;min-height:0px;color:transparent;float:left;background-repeat:no-repeat">*</span>, %</b><span style="color:rgb(44,45,48);line-height:22px;background-color:rgb(249,249,249)">"class.std::type_info"*<span style="font-weight:bold;display:inline-block;vertical-align:baseline;width:1px;min-height:0px;color:transparent;float:left;background-repeat:no-repeat">*</span><b>​</b></span><span style="color:rgb(44,45,48);line-height:22px;background-color:rgb(249,249,249)"><span> </span>}</span></font><br></div><div><font face="monospace"><span style="color:rgb(44,45,48);font-size:15px;line-height:22px;background-color:rgb(249,249,249)"><br></span></font></div><div>So, it looks like <span style="color:rgb(44,45,48);font-family:monospace;line-height:22px;background-color:rgb(249,249,249)">boost::bad_lexical_cast</span><span style="line-height:18px"> inherits from </span><span style="color:rgb(44,45,48);font-family:monospace;line-height:22px;background-color:rgb(249,249,249)">std::bad_alloc</span><span style="line-height:18px">.</span></div><div><span style="line-height:1.5">However, the associated type info for this class (contained in the same bitcode file) suggests that the primary base class is </span><span style="color:rgb(44,45,48);font-family:monospace;line-height:22px;background-color:rgb(249,249,249)">std::bad_cast</span><span style="line-height:1.5"> instead:</span></div><div><span style="line-height:1.5"><br></span></div><div><font face="monospace">@_ZTIN5boost16bad_lexical_castE = linkonce_odr constant { i8*, i8*, i8* } {</font></div><div><font face="monospace">   i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2) to i8*),</font></div><div><font face="monospace">   i8* getelementptr inbounds ([27 x i8], [27 x i8]* @_ZTSN5boost16bad_lexical_castE, i32 0, i32 0),</font></div><div><font face="monospace">   i8* bitcast (i8** <b>@_ZTISt8bad_cast</b> to i8*) </font></div><div><font face="monospace">}, comdat</font><br></div><div><br></div><div><div><font face="monospace">$ echo '_ZTISt8bad_cast' | c++filt </font></div><div><font face="monospace">typeinfo for std::bad_cast</font></div></div><div><br></div><div><span style="line-height:1.5">This seems more reasonable and in accordance to boost source code (</span><a href="http://www.boost.org/doc/libs/1_58_0/boost/lexical_cast/bad_lexical_cast.hpp" target="_blank">http://www.boost.org/doc/libs/1_58_0/boost/lexical_cast/bad_lexical_cast.hpp</a><span style="line-height:1.5">).</span><br></div><div>Even so, the LLVM type for <span style="color:rgb(44,45,48);font-family:monospace;line-height:22px;background-color:rgb(249,249,249)">bad_alloc</span> looks even stranger:</div><div><br></div><div><span style="color:rgb(44,45,48);line-height:22px;background-color:rgb(249,249,249)"><font face="monospace">%"class.std::bad_alloc" = type { %"class.boost::system::error_category" }<br></font></span><br>How can a class from standard library inherit something from boost, and why is the layout of some class types different from what their typeinfo objects suggest? Is this a bug, or some obscure effect from an optimization pass?</div></div><div><br></div><div>Thanks,</div><div>George</div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>