<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 class="inbox-inbox-copyonly" style="display:inline-block;vertical-align:baseline;width:1px;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 class="inbox-inbox-copyonly" style="font-weight:bold;display:inline-block;vertical-align:baseline;width:1px;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 class="inbox-inbox-Apple-converted-space"> </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">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>