[llvm-dev] Upgrading LLVM API versions, trouble with DIVariable

James Clarke via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 8 18:15:24 PDT 2019


Hi,

On Tue, Oct 08, 2019 at 06:23:04PM +0000, Trevor Martin via llvm-dev wrote:
> Hello,
>
> I am working on upgrading LLVM libraries from 3.0 to 7.0.0 for a project to
> be compatible with an outside project.
>
> I've made good progress but am running into a wall for all things related
> to DIVariables and there creation from existing Metadata objects.
>
> Specifically I've run into 3 issues;
>
> (1)I am trying to create a DIType from the Type of an existing DIVariable
> using getType().
>
> foo (DIVariable& oldDIVar){
>
>     const DIType oldDIType = oldDIVar.getType();
> }
>
> According to the llvm documentation, DIVariable::getType should return a
> DIType*. But I get an error message:

It does these days, but back in 7.x it returned the TypedDINodeRef you
see. It's an ugly API, but you need to use the `resolve` method to get
the actual `T*` out.

> error: no viable conversion from 'llvm::DITypeRef' (aka
> 'TypedDINodeRef<llvm::DIType>') to 'const llvm::DIType *'
>   const DIType *oldDIType = oldDIVar.getType();
>                 ^           ~~~~~~~~~~~~~~~~~~
>
> I've messed around with dereferencing the oldDIVar variable, which points
> to the underlying Metadata of it. I would assume that attempting to create
> a DIType from pure metadata would be fine, since it inherits from the
> metadata class. But I always get the error:
>
>  error: no viable conversion from 'llvm::Metadata' to 'llvm::DIType'
>   DIType oldDIType = *oldDIVar.getType();
>          ^           ~~~~~~~~~~~~~~~~~~~
> /root/llvm-7.0.0/include/llvm/IR/DebugInfoMetadata.h:630:7: note: candidate
> constructor (the implicit copy constructor) not viable: cannot bind base
> class object of type 'llvm::Metadata' to derived class
>       reference 'const llvm::DIType &' for 1st argument
> class DIType : public DIScope {
>
> Am I missing something about inheritance that prevents this?
>
> (2)One of the other errors is similar;
>
>   Unable to convert from MDNode to DIVariable

Out of context it's hard for anyone to work anything out. Clearly you
have an MDNode somewhere where a DIVariable is expected, so you should
work out why that is and what you're meant to do about it? But it sounds
like it's related to (3).

> (3)The final one is strange to me. Once again trying to make a DIVariable
> from and oldDIVar,
> this time calling DbgVariables::getVariables(). I try to call it as such;
>
> DIVariable oldDIVar(*(oldDeclare->getVariable());
>
> But that seems to give an error due to an implicitly deleted copy
> constructor, which completely baffles me.
>
> error: call to implicitly-deleted copy constructor of 'llvm::DIVariable'
>                   DIVariable oldDIVar(*(oldDeclare->getVariable()));

See r234263:

    DebugInfo: Drop dead code for loose DIDescriptor construction API

    Delete `DIDescriptor::is*()` and the various constructors from `MDNode*`
    in `DIDescriptor` subclasses.

    If this just broke your out-of-tree code, you need to make updates along
    the lines of r234255, r234256, r234257 and r234258:

      - Generally, `DIX().isX()` => `isa<MDX>()`.  So, `D.isCompileUnit()`
        should just be `isa<MDCompileUnit>(D)`, modulo checks for null.
          - Exception: `DILexicalBlock` => `MDLexicalBlockBase`.
          - Exception: `DIDerivedType` => `MDDerivedTypeBase`.
          - Exception: `DICompositeType` => `MDCompositeTypeBase`.
          - Exception: `DIVariable` => `MDLocalVariable`.
      - Note that (e.g.) `DICompileUnit` has an implicit constructor from
        `MDCompileUnit*`.

    llvm-svn: 234263

James

> If anyone could provide insight into why creating DIVariables and DITypes
> is failing, and what the implicitly deleted copy constructor is being
> caused by, I'd really appreciate it.
>
> This is my first time using this mailing list, so apologies of I made a
> mistake somewhere.
>
> Regards,
>
> Trevor


More information about the llvm-dev mailing list