[llvm-dev] Help with new llvm.debug.value metadata API

Vedant Kumar via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 23 09:32:57 PST 2015

Hi Zvonimir,

> Hi all,
> So I started working on upgrading our tool from LLVM 3.5 to 3.6, and I would appreciate your help with the new metadata API.
> In particular, I currently have the following snippet of code:
> // ci is llvm.debug.value instruction
>     const llvm::MDNode* m1 = dyn_cast<const llvm::MDNode>(ci.getArgOperand(0));
>     const llvm::MDNode* m2 = dyn_cast<const llvm::MDNode>(ci.getArgOperand(2));
>     assert(m1 && "Expected metadata node in first argument to llvm.dbg.value.");
>     assert(m2 && "Expected metadata node in third argument to llvm.dbg.value.");
>     const llvm::MDString* m3 = dyn_cast<const llvm::MDString>(m2->getOperand(2));
>     assert(m3 && "Expected metadata string in the third argument to metadata node.");
>    if (const llvm::Value* V = m1->getOperand(0)) { // this does not compile any more!
>    ... Need Type of Value V here.
>     }
> In LLVM 3.6, the expression in the if condition does not compile any more.

It looks like MDNode::getOperand() returns `const MDOperand &` now, not `Value *`.

> What I basically need in the if body is to access the type (Type) of the variable specified in the llvm.debug.value metadata. How do I access its type using the new metadata API?

I haven't tried this, but I suspect you'd need something like:

  if (auto *VAM = dyn_cast<llvm::ValueAsMetadata>(m1->getOperand(0).get())) {
    // VAM->getType()

This should be documented in:



More information about the llvm-dev mailing list