0

I'm looking at DIBuilder::createLabel() in the LLVM docs here. It says:

The optimizer may remove labels. If there is an interest to preserve label info in such situation then append it to the list of retained nodes of the DISubprogram.

How does one do this?

I've found the getRetainedNodes method of DISubprogram which appears to return a MDTupleTypedArrayWrapper, but I can't see how I should add to this.

Maybe it is immutable?

Student
  • 805
  • 1
  • 8
  • 11
Edd Barrett
  • 3,425
  • 2
  • 29
  • 48

1 Answers1

0

I think this is a documentation bug. If we look at the implementation:

DILabel *DIBuilder::createLabel(                                                
    DIScope *Scope, StringRef Name, DIFile *File,                               
    unsigned LineNo, bool AlwaysPreserve) {                                     
  DIScope *Context = getNonCompileUnitScope(Scope);                             

  auto *Node =                                                                  
      DILabel::get(VMContext, cast_or_null<DILocalScope>(Context), Name,        
                   File, LineNo);                                               

  if (AlwaysPreserve) {                                                         
    /// The optimizer may remove labels. If there is an interest                
    /// to preserve label info in such situation then append it to              
    /// the list of retained nodes of the DISubprogram.                         
    DISubprogram *Fn = getDISubprogram(Scope);                                  
    assert(Fn && "Missing subprogram for label");                               
    PreservedLabels[Fn].emplace_back(Node);                                     
  }                                                                             
  return Node;                                                                  
}

The position of the doc comment implies that this is something the function will do for us if we pass alwaysPreserve=True, but when you see this doc comment on the doxygen page, it looks like it's something you have to do yourself!

Edd Barrett
  • 3,425
  • 2
  • 29
  • 48