[llvm-dev] Type discrepancies in LLVM Bitcode

George Balatsouras via llvm-dev llvm-dev at lists.llvm.org
Tue Jun 14 14:53:23 PDT 2016


Hi everyone,

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.
The LLVM type for class boost::bad_lexical_cast is represented as follows:

%"class.boost::bad_lexical_cast" = type { *%"class.std::bad_alloc"*,
%"class.std::type_info"**​*, %*"class.std::type_info"***​* }

So, it looks like boost::bad_lexical_cast inherits from std::bad_alloc.
However, the associated type info for this class (contained in the same
bitcode file) suggests that the primary base class is std::bad_cast instead:

@_ZTIN5boost16bad_lexical_castE = linkonce_odr constant { i8*, i8*, i8* } {
   i8* bitcast (i8** getelementptr inbounds (i8*, i8**
@_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2) to i8*),
   i8* getelementptr inbounds ([27 x i8], [27 x i8]*
@_ZTSN5boost16bad_lexical_castE, i32 0, i32 0),
   i8* bitcast (i8** *@_ZTISt8bad_cast* to i8*)
}, comdat

$ echo '_ZTISt8bad_cast' | c++filt
typeinfo for std::bad_cast

This seems more reasonable and in accordance to boost source code (
http://www.boost.org/doc/libs/1_58_0/boost/lexical_cast/bad_lexical_cast.hpp
).
Even so, the LLVM type for bad_alloc looks even stranger:

%"class.std::bad_alloc" = type { %"class.boost::system::error_category" }

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?

Thanks,
George
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160614/a08d4736/attachment.html>


More information about the llvm-dev mailing list