[LLVMdev] question on difference of bitcode between C and C++
rengolin at systemcall.org
Thu Sep 22 03:29:43 PDT 2011
On 22 September 2011 03:30, Eli Friedman <eli.friedman at gmail.com> wrote:
>> I am trying to find such difference of bitcode between C and C++.
> There isn't any difference in that sense... in IR, a constructor is
> just a function call, a reference is just a pointer, etc.
While Clang (like others) lowers C++ into C semantics and lower that
into IR, there are some changes that exist in C++ and not in C. The IR
has the same features, but some assumptions on the semantics are
I can give you two examples:
1. Classes in C++ are like C structures in IR, but the C++ ABI makes
it difficult to express Base/Derived classes in pure structures.
So, if your pass depends on identifying the same types, you could end
up thinking that the types are different, but they're not. They're
just different struct representations (base vs. derived) of the same
2. Virtual table tables encode offsets in two different ways:
addresses and offsets, and the two representations are normally on the
same global static array in IR. So, while the type of the array is int
(or pointer), it contains addresses and offsets from addresses
bitcasting to the type of the global.
These are not the only C-lowering that C++ front-ends do, but it gives
you a taste of what to expect. As Eli said, most of C++ can be lowered
into C-like structures and the IR is very similar, but some semantic
interpretations are done differently, and the internal IR (that deals
with those objects) is slightly different.
More information about the llvm-dev