[PATCH] D117486: DebugInfo: Fix null dereference on null DISubroutineType
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 17 06:48:52 PST 2022
arsenm created this revision.
arsenm added a reviewer: debug-info.
Herald added a subscriber: hiraditya.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
No idea what I'm doing or if this is the right fix, a good test, or if
this metadata should fail the verifier. I've had this crashing
testcase sitting around for months so I'm not entirely sure where it
came from, but I think I was manually reducing the metadata.
https://reviews.llvm.org/D117486
Files:
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/test/DebugInfo/X86/empty-subprogram-die-assert.ll
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}
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117486.400534.patch
Type: text/x-patch
Size: 2286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220117/bec494fe/attachment.bin>
More information about the llvm-commits
mailing list