[PATCH] D109597: [DebugInfo] Fix of crash due to DwarfUnit::getOrCreateContextDIE returning NULL

Alok Kumar Sharma via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 10 05:06:25 PDT 2021


alok created this revision.
alok added reviewers: aprantl, djtodoro, jmorse, jini.susan.
alok added a project: debug-info.
Herald added subscribers: pengfei, ormris, hiraditya.
Herald added a reviewer: sscalpone.
alok requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The test program attached with this patch crashes as

  ``````````````````````````````````````````````````````````````````````

command line:  llc llvm/test/DebugInfo/X86/dwarfdump-ContextDICompileUnit.ll
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: bin/llc ../llvm/test/DebugInfo/X86/dwarfdump-ContextDICompileUnit.ll

1. Running pass 'Function Pass Manager' on module '../llvm/test/DebugInfo/X86/dwarfdump-ContextDICompileUnit.ll'.
2. Running pass 'X86 Assembly Printer' on function '@mdl1_sub1_' #0 0x00007f055f76be80 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) llvm/lib/Support/Unix/Signals.inc:565:0 #1 0x00007f055f76bf37 PrintStackTraceSignalHandler(void*) llvm/lib/Support/Unix/Signals.inc:632:0 #2 0x00007f055f769beb llvm::sys::RunSignalHandlers() llvm/lib/Support/Signals.cpp:97:0 #3 0x00007f055f76b801 SignalHandler(int) llvm/lib/Support/Unix/Signals.inc:407:0 #4 0x00007f055d971040 (/lib/x86_64-linux-gnu/libc.so.6+0x3f040) #5 0x00007f056436d62d llvm::IntrusiveBackListBase::push_back(llvm::IntrusiveBackListNode&) llvm/include/llvm/CodeGen/DIE.h:536:0 #6 0x00007f056436ffbb llvm::IntrusiveBackList<llvm::DIE>::push_back(llvm::DIE&) llvm/include/llvm/CodeGen/DIE.h:560:0 #7 0x00007f056436d8ef llvm::DIE::addChild(llvm::DIE*) llvm/include/llvm/CodeGen/DIE.h:850:0 #8 0x00007f05643f1850 llvm::DwarfUnit::createAndAddDIE(llvm::dwarf::Tag, llvm::DIE&, llvm::DINode const*) llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:390:0 #9 0x00007f05643f4dc2 llvm::DwarfUnit::getOrCreateModule(llvm::DIModule const*) llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:1096:0

#10 0x00007f05643f2450 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:549:0
#11 0x00007f05643f50a1 llvm::DwarfUnit::getOrCreateSubprogramDIE(llvm::DISubprogram const*, bool) llvm/lib/CodeGen/AsmPrinterDwarfUnit.cpp:1125:0
#12 0x00007f056436a880 llvm::DwarfCompileUnit::constructCallSiteEntryDIE(llvm::DIE&, llvm::DISubprogram const*, bool, llvm::MCSymbol const*, llvm::MCSymbol const*, unsigned int) llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp:1182:0
#13 0x00007f0564388282 llvm::DwarfDebug::constructCallSiteEntryDIEs(llvm::DISubprogram const&, llvm::DwarfCompileUnit&, llvm::DIE&, llvm::MachineFunction const&) llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:987:0
#14 0x00007f056438e580 llvm::DwarfDebug::endFunctionImpl(llvm::MachineFunction const*) llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:2257:0
#15 0x00007f0564350aa0 llvm::DebugHandlerBase::endFunction(llvm::MachineFunction const*) llvm/lib/CodeGen/AsmPrinterDebugHandlerBase.cpp:410:0
#16 0x00007f05642f4b3f llvm::AsmPrinter::emitFunctionBody() llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1505:0
#17 0x00007f05663d2653 llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) llvm/lib/Target/X86/X86AsmPrinter.cpp:85:0
#18 0x00007f056329e007 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) llvm/lib/CodeGen/MachineFunctionPass.cpp:72:0
#19 0x00007f05621b6082 llvm::FPPassManager::runOnFunction(llvm::Function&) llvm/lib/IR/LegacyPassManager.cpp:1439:0
#20 0x00007f05621b632b llvm::FPPassManager::runOnModule(llvm::Module&) llvm/lib/IR/LegacyPassManager.cpp:1485:0
#21 0x00007f05621b6753 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) llvm/lib/IR/LegacyPassManager.cpp:1554:0
#22 0x00007f05621b1813 llvm::legacy::PassManagerImpl::run(llvm::Module&) llvm/lib/IR/LegacyPassManager.cpp:542:0
#23 0x00007f05621b6fdd llvm::legacy::PassManager::run(llvm::Module&) llvm/lib/IR/LegacyPassManager.cpp:1682:0
#24 0x0000558e5b81985d compileModule(char**, llvm::LLVMContext&) llvm/tools/llc/llc.cpp:690:0
#25 0x0000558e5b81752a main llvm/tools/llc/llc.cpp:388:0
#26 0x00007f055d953bf7 __libc_start_main /build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:344:0
#27 0x0000558e5b81647a _start (bin/llc+0x2947a)

  ``````````````````````````````````````````````````````````````````````

This is due to a missing case in DwarfUnit::getOrCreateContextDIE for DICompileUnit, which is now added to fix the issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109597

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/test/DebugInfo/X86/dwarfdump-ContextDICompileUnit.ll


Index: llvm/test/DebugInfo/X86/dwarfdump-ContextDICompileUnit.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/X86/dwarfdump-ContextDICompileUnit.ll
@@ -0,0 +1,57 @@
+; REQUIRES: x86_64-linux
+
+; RUN: llc %s -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
+
+; CHECK: DW_TAG_compile_unit
+; CHECK: DW_AT_name        ("mod1.f90")
+; CHECK: DW_TAG_module
+; CHECK: DW_AT_name      ("mdl1")
+; CHECK: DW_TAG_subprogram
+; CHECK:  DW_AT_name    ("sub1")
+; CHECK: DW_TAG_module
+; CHECK: DW_AT_name      ("mdl2")
+; CHECK: DW_AT_declaration       (true)
+
+; CHECK: DW_TAG_compile_unit
+; CHECK: DW_AT_name        ("mod2.f90")
+; CHECK: DW_TAG_module
+; CHECK: DW_AT_name      ("mdl2")
+; CHECK: DW_TAG_subprogram
+; CHECK:  DW_AT_name    ("sub2")
+
+; ModuleID = 'dwarfdump_ContextDICompileUnit.f90'
+source_filename = "dwarfdump_ContextDICompileUnit.f90"
+
+define void @mdl1_sub1_(i64* noalias %rx) local_unnamed_addr !dbg !9 {
+L.entry:
+  tail call void @mdl2_sub2_(i64* %rx), !dbg !14
+  ret void, !dbg !15
+}
+
+define void @mdl2_sub2_(i64* noalias nocapture readnone %rx) local_unnamed_addr !dbg !16 {
+L.entry:
+  ret void, !dbg !19
+}
+
+!llvm.dbg.cu = !{!0, !3}
+!llvm.module.flags = !{!5, !6, !7}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !1, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: true, flags: "'+flang -c -O3 -flto -emit-llvm mod1.f90'", runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, nameTableKind: None)
+!1 = !DIFile(filename: "mod1.f90", directory: "/tmp")
+!2 = !{}
+!3 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !4, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: true, flags: "'+flang -c -O3 -flto -emit-llvm mod2.f90'", runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, nameTableKind: None)
+!4 = !DIFile(filename: "mod2.f90", directory: "/tmp")
+!5 = !{i32 2, !"Dwarf Version", i32 4}
+!6 = !{i32 2, !"Debug Info Version", i32 3}
+!7 = !{i32 1, !"ThinLTO", i32 0}
+!9 = distinct !DISubprogram(name: "sub1", scope: !10, file: !1, line: 4, type: !11, scopeLine: 4, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+!10 = !DIModule(scope: !0, name: "mdl1", isDecl: true)
+!11 = !DISubroutineType(types: !12)
+!12 = !{null, !13}
+!13 = !DIBasicType(name: "real", size: 32, align: 32, encoding: DW_ATE_float)
+!14 = !DILocation(line: 7, column: 1, scope: !9)
+!15 = !DILocation(line: 8, column: 1, scope: !9)
+!16 = distinct !DISubprogram(name: "sub2", scope: !17, file: !4, line: 4, type: !11, scopeLine: 4, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !3)
+!17 = !DIModule(scope: !3, name: "mdl2", isDecl: true)
+!18 = !DILocation(line: 6, column: 1, scope: !16)
+!19 = !DILocation(line: 7, column: 1, scope: !16)
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -537,7 +537,7 @@
 }
 
 DIE *DwarfUnit::getOrCreateContextDIE(const DIScope *Context) {
-  if (!Context || isa<DIFile>(Context))
+  if (!Context || isa<DIFile>(Context) || isa<DICompileUnit>(Context))
     return &getUnitDie();
   if (auto *T = dyn_cast<DIType>(Context))
     return getOrCreateTypeDIE(T);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109597.371880.patch
Type: text/x-patch
Size: 3465 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210910/4c733310/attachment.bin>


More information about the llvm-commits mailing list