[llvm-dev] DICompositeType to Type

David Blaikie via llvm-dev llvm-dev at lists.llvm.org
Thu Oct 29 12:06:15 PDT 2020


On Thu, Oct 29, 2020 at 6:39 AM Henri Rosten via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Given a DICompositeType, is there a convenient way to map the
> DICompositeType to llvm::Type?
>

No there isn't - that's not usually a thing that folks need to do. What use
case do you have in mind?


>
> As an example:
>
> ```
> class Base {
> public:
>     virtual void base_pure_virtual() = 0;
> };
>
> class Child : public Base {
> public:
>     void base_pure_virtual() {
>         std::cout << __PRETTY_FUNCTION__ << "\n";
>     }
> };
>
> Child child;
> Base *baseptr = &child;
> ```
>
> Relevant IR snippets:
>
> ```
> @child = dso_local global { i8** } { i8** getelementptr inbounds ({ [3 x
> i8*] }, { [3 x i8*] }* @_ZTV5Child, i32 0, inrange i32 0, i32 2) }, align
> 8, !dbg !19
> @baseptr = dso_local global %class.Base* bitcast ({ i8** }* @child to
> %class.Base*), align 8, !dbg !25
> ...
> !914 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "Child",
> file: !22, line: 8, size: 64, flags: DIFlagTypePassByReference |
> DIFlagNonTrivial, elements: !915, vtableHolder: !28, identifier:
> "_ZTS5Child")
> ```
>
> I would like to know the Type of the value assigned to baseptr.
>
> I figured global variable has a link to DIGlobalVariable, which has a
> link to DICompositeType. However, it seems there is no way to get to the
> llvm::Type from DICompositeType. Is this the case or did I overlook
> something?
>
> Alternatively, if there's a simpler way to get the Type of the value
> assigned to baseptr (class.Child*), I would welcome your suggestion.
>

if you have the baseptr llvm::Value* you shuold be able to ask that
llvm::Value for its type directly
https://llvm.org/doxygen/classllvm_1_1Value.html#a6393a2d4fe7e10b28a0dcc35f881567b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201029/83b1dad9/attachment.html>


More information about the llvm-dev mailing list