Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -1023,16 +1023,18 @@ addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer); } - // 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( + if (DISubroutineType *SRT = Sub->getType()) { + // If this is a variadic function, add an unspecified parameter. + DITypeRefArray FnArgs = SRT->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; } Index: llvm/test/DebugInfo/X86/empty-subprogram-die-assert.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/empty-subprogram-die-assert.ll @@ -0,0 +1,18 @@ +; RUN: llc -mtriple=x86_64-pc-linux-gnu -filetype=obj < %s | llvm-dwarfdump -debug-info - | FileCheck %s + +; Check for crash when inspecting DISubroutineType +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("foo") +define void @foo() !dbg !3 { + ret void +} + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug) +!1 = !DIFile(filename: "foo.c", directory: "/tmp") +!2 = !{i32 2, !"Debug Info Version", i32 3} +!3 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0) +!4 = !DISubroutineType(types: !5) +!5 = !{null}