[LLVMdev] Why is "typedef boost::shared_ptr<MyClass> MyClass_ptr" named "struct.boost::MyClass_ptr" by llvm-g++?

Matthijs Kooijman matthijs at stdin.nl
Wed Nov 19 04:03:53 PST 2008


Hi David,

> In the code below, MyNamespace::MyClass_ptr will be named
> "struct.boost::MyClass_ptr" by llvm-g++, and not
> "struct.MyNamespace::MyClass_ptr" as I expected. 
In LLVM IR, types use structural equivalency. That means that types are
equivalent when they are the same type (ie, have the same type of fields,
etc.), regardless of what name they have. Moreover, any given type can have
only a single name.

This means that when there are two typenames for the same (structural) type in
the original sourcecode (which is the case by definition when typedeffing
something), only one of those names will be used on the resulting type in the
IR. Which one of those names is used is pretty arbitrary I think (and if there
happens to be another type that is structurally the same, it might even become
that name).

In short, you should probably not value typenames too much in LLVM IR. If you
really want to keep types apart, you'll have to check their structure.
Alternatively, you might be able to switch on debugging info to get some
higher level (ie, closer to C++) type info, but I'm not so sure this is
useful.

Gr.

Matthijs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20081119/0404425f/attachment.sig>


More information about the llvm-dev mailing list