This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Fix of crash due to DwarfUnit::getOrCreateContextDIE returning NULL
Needs ReviewPublic

Authored by alok on Sep 10 2021, 5:06 AM.

Details

Summary

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.

Diff Detail

Event Timeline

alok created this revision.Sep 10 2021, 5:06 AM
alok requested review of this revision.Sep 10 2021, 5:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 10 2021, 5:06 AM
alok edited the summary of this revision. (Show Details)Sep 10 2021, 5:07 AM

is this related to flang only?

alok added a comment.Sep 10 2021, 6:29 AM

is this related to flang only?

This issue was triggered with the Flang. But given the simple IR, not sure if it is limited or not limited to Flang.

dblaikie added inline comments.
llvm/test/DebugInfo/X86/dwarfdump-ContextDICompileUnit.ll
3 ↗(On Diff #371880)

The title of this file seems misleading - if the bug/crash/issue is not in dwarfdump, we wouldn't usually put the word 'dwarfdump' in the test file name (like we don't put opt/llc in the name of tests that use those tools to test some transformation/lowering pass)

3 ↗(On Diff #371880)

Could you include something like the original C or C++ source code (or otherwise) that was used to generate this IR? (if this IR was generated from some flang input - including the instructions of how to recompile/regenerate the IR may be useful for legibility (reading the metadata is a bit painful sometimes, so including some high level description of what's going on can be useful))

It'd be interesting to know/have more details (in this test file, in the patch description, etc) about how the problematic situation arose, and why it hadn't come up until flang/what did flang do differently that triggered this?

alok updated this revision to Diff 373149.Sep 16 2021, 11:35 PM
alok added a reviewer: dblaikie.

Included comments from @dblaikie

alok updated this revision to Diff 373164.Sep 17 2021, 1:18 AM

Minor testcase update.

dblaikie added inline comments.Sep 17 2021, 10:44 AM
llvm/test/DebugInfo/X86/dwarfdump-ContextDICompileUnit.ll
3 ↗(On Diff #371880)

I'm still curious to know more about what was interesting about this debug info IR that's novel in Fortran's use case/doesn't come up in Clang's use case? Can you include more detail in the patch description about what's novel/different in this debug info IR compared to the sort of thing clang typically produces, and why fortran produces it?

(this test case got updated and lost most of the CHECK lines - I'm not sure that's the best direction either - presumably there's some behavior "behind" the crash that's worth testing that was missing/why the crash wasn't found previously. We don't just want llvm to do anything other than crash - we want some particular behavior and should check for that)

ormris removed a subscriber: ormris.Jan 24 2022, 11:44 AM