diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -5084,7 +5084,8 @@ used for call site debug info. The ``retainedNodes:`` field is a list of :ref:`variables ` and :ref:`labels ` that must be retained, even if their IR counterparts are optimized out of the IR. The -``type:`` field must point at an :ref:`DISubroutineType`. +``type:`` field is optional, but if present it must point at a +:ref:`DISubroutineType`. .. _DISubprogramDeclaration: diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -927,15 +927,17 @@ } // If this is a variadic function, add an unspecified parameter. - DITypeRefArray FnArgs = Sub->getType()->getTypeArray(); - - // If we have a single element of null, it is a function that returns void. - // If we have more than one elements and the last one is null, it is a - // variadic function. - if (FnArgs.size() > 1 && !FnArgs[FnArgs.size() - 1] && - !includeMinimalInlineScopes()) - ScopeDIE.addChild( - DIE::get(DIEValueAllocator, dwarf::DW_TAG_unspecified_parameters)); + if (DISubroutineType *FnType = Sub->getType()) { + DITypeRefArray FnArgs = FnType->getTypeArray(); + + // If we have a single element of null, it is a function that returns void. + // If we have more than one elements and the last one is null, it is a + // variadic function. + if (FnArgs.size() > 1 && !FnArgs[FnArgs.size() - 1] && + !includeMinimalInlineScopes()) + ScopeDIE.addChild( + DIE::get(DIEValueAllocator, dwarf::DW_TAG_unspecified_parameters)); + } return ScopeDIE; } diff --git a/llvm/test/CodeGen/Generic/disubprogram-no-type.ll b/llvm/test/CodeGen/Generic/disubprogram-no-type.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/Generic/disubprogram-no-type.ll @@ -0,0 +1,16 @@ +; RUN: llc %s -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s + +; Confirm we don't ICE when generating DWARF debug information for a +; DISubprogram that is missing a `type:` + +; CHECK-NOT: DW_AT_type + +define i32 @f(i32 %0) !dbg !3 { ret i32 %0 } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2} + +!0 = distinct !DICompileUnit(language: 0, file: !1, emissionKind: FullDebug) +!1 = !DIFile(filename: "-", directory: "") +!2 = !{i32 2, !"Debug Info Version", i32 3} +!3 = distinct !DISubprogram(file: !1, unit: !0)