Debug info: create temporary forward subprograms before creating the subprogram type

This is for the special case of auto functions returning a nested type, e.g:

  auto foo() {
    struct S {};
    S s;
    return s;
  }
This commit is contained in:
Elie Morisse 2018-08-20 22:50:45 -03:00 committed by Martin Kinkelin
parent 8d26d5f452
commit 02eb4058fa
2 changed files with 18 additions and 1 deletions

View file

@ -914,6 +914,23 @@ ldc::DISubprogram ldc::DIBuilder::EmitSubProgram(FuncDeclaration *fd) {
ldc::DIFile file = CreateFile(fd);
// A special case is `auto foo() { struct S{}; S s; return s; }`
// The return type is a nested struct, so for this particular chicken-and-egg case
// we need to create a temporary subprogram.
irFunc->diSubprogram = DBuilder.createTempFunctionFwdDecl(
GetSymbolScope(fd), // context
fd->toChars(), // name
irFunc->getLLVMFuncName(), // linkage name
file, // file
fd->loc.linnum, // line no
nullptr, // type
fd->protection.kind == Prot::private_, // is local to unit
true, // isdefinition
fd->loc.linnum, // FIXME: scope line
DIFlags::FlagPrototyped, // Flags
isOptimizationEnabled() // isOptimized
);
// Create subroutine type
ldc::DISubroutineType DIFnType = mustEmitFullDebugInfo() ?
CreateFunctionType(static_cast<TypeFunction *>(fd->type)) :