[llvm-dev] getting the value back from metadata

Mehdi Amini via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 14 11:07:10 PST 2016


> On Nov 14, 2016, at 9:18 AM, Alon Shaltiel (ashaltie) via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> Hello,
> I’m trying to extract the value out of my MDNode, but for some reason I can’t.
>  
> For example, if one part of the code gets an MDNode that was created as follows:
> Metadata* vals[2] =
>        { ValueAsMetadata::get(&F), ValueAsMetadata::get(ConstantInt::get(context, 135)) };
> MDNode* mdnode = MDNode::get(context, vals);
>  
> Is it possible to extract the value of the constant int (135 in this case)?
>  
> I tried using MetaDataAsValue as follows:
> cast<ConstantInt>(MetadataAsValue::get(context,
>                                  mdnode->getOperand(1)))->getZExtValue()
>  

You should try mdconst::extract<ConstantInt> instead of cast<ConstantInt> (search in the codebase for example if needed).

— 
Mehdi


> 
> 
> 
> but I get NULL… (although when pronting the MetadataAsValue I do see “i32 135”)
>  
> maybe the MDNode should be built in a different manner?
>  
> Thanks!
> Alon
>  
>  
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161114/f41eab9f/attachment.html>


More information about the llvm-dev mailing list