Search code examples
visual-c++compiler-constructionllvmdebug-information

What are "retainedNodes" in LLVMs debug metadata?


Using the LLVM 8.0.1 library, I try to create the debug info for a function with the following code:

DIFile *Unit = DebugBuilder->createFile(CompileUnit->getFilename(), CompileUnit->getDirectory());
DIScope *FContext(Unit);

DISubprogram *SP = DebugBuilder->createFunction(
    FContext, def->Name, def->Name, Unit, LineNo,
    CreateFunctionType(ft, CompileUnit->getFile()), 0);

func->setSubprogram(SP);

This, however, results in IR like the following:

define i32 @main(i32 %y) !dbg !3 {
entry:
  ret i32 2
}
    ; ...
!3 = !DISubprogram(name: "main", linkageName: "main", scope: !2, file: !2, type: !4, spFlags: 0, retainedNodes: !7)
    ; ...
!7 = <temporary!> !{}

Which, upon calling DebugBuilder->finalize(), throws Assertion failed: !N->isTemporary() && "Expected all forward declarations to be resolved"

I have not found a description of the retainedNodes field in the official reference nor other tutorials, and web searches only lead to uncommented sections of the LLVM source. What is the meaning or purpose of this field? How is a temporary node created there?


Solution

  • I found this solved by adding, before generating the DebugBuilder,

    TheModule->addModuleFlag(llvm::Module::Warning, "CodeView", 1);
    

    ... as explained apparently nowhere in the official documentation.