[PATCH] D113741: [RFC][DwarfDebug][AsmPrinter] Support emitting function-local declaration for a lexical block

Kristina Bessonova via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 12 01:21:14 PST 2021


krisb created this revision.
krisb added reviewers: dblaikie, aprantl, probinson.
Herald added subscribers: asavonic, kerbowa, hiraditya, jgravelle-google, sbc100, nhaehnle, jvesely, nemanjai, dschuff, jholewinski.
krisb requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

This is another attempt to make function-local declarations
(like static variables, structs/classes and other) be correctly emitted
within a lexical (bracketed) block.

Some ideas were taken from previous attempts [0] and [1].

The patch postpones emission of global variables, imported entities,
records and other till DwarfDebug::endModule() waiting for all local
context being created and stored to a map. Since DWARF specification
doesn't define debug entity ordering, this shouldn't be an issue.

Having these entities emitted in DwarfDebug::endModule() might also contribute
to more accurate debug information as IR can be changed after
DwarfDebug::beginModule() and those changes get missed if to emit debug
info in DwarfDebug::beginModule().

Workarounds and limitations:

- To simplify handling of abstract/out-of-line definitions, the patch preliminary gathers functions with inlined instances, so we don't need to put known out-of-line concrete scope DIEs to the map. But the way this information gathered doesn't guarantee that the corresponded abstract/inlined LexicalScope will be created even if the function was marked as 'has-inlined-instances'. In this case DwarfCompileUnit::getOrCreateContext() falls back to concrete out-of-line subprogram DIE.

- Since we skip lexical blocks if we couldn't find non-scope children for them, we need a way to force emission of blocks that have static locals or local type declarations but don't have local variables. As a workaround, I collect such scopes by collectLocalScopesWithDeclsFromCU() and store them to a set. This set is used later to check whether we need to emit a lexical block. It, however, lacks information about used records and typedefs because there is no access to them from a CU. In this case, we will put the entity to a first available parent scope (with subprogram as a bound).

This patch partially reverts [2] in favor of collecting information
about inlined instances, but it's possible to keep the idea from [2] instead.

Fixes:

- https://bugs.llvm.org/show_bug.cgi?id=19238
- https://bugs.llvm.org/show_bug.cgi?id=44695 (need to be closed as duplicate).

I also checked [3] which caused D15976 <https://reviews.llvm.org/D15976> to be reverted, with this version
the reproducer from the ticket compiled without issues.

[0] https://reviews.llvm.org/D11180
[1] https://reviews.llvm.org/D15976
[2] https://reviews.llvm.org/D112337
[3] https://bugs.llvm.org/show_bug.cgi?id=27579


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113741

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
  llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
  llvm/test/CodeGen/ARM/2011-01-19-MergedGlobalDbg.ll
  llvm/test/CodeGen/ARM/2011-08-02-MergedGlobalDbg.ll
  llvm/test/DebugInfo/AMDGPU/variable-locations.ll
  llvm/test/DebugInfo/BPF/extern-void.ll
  llvm/test/DebugInfo/Generic/DICommonBlock.ll
  llvm/test/DebugInfo/Generic/debug-info-qualifiers.ll
  llvm/test/DebugInfo/Generic/debug-names-linkage-name.ll
  llvm/test/DebugInfo/Generic/enum-types.ll
  llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
  llvm/test/DebugInfo/Generic/imported-name-inlined.ll
  llvm/test/DebugInfo/Generic/incorrect-variable-debugloc.ll
  llvm/test/DebugInfo/Generic/inlined-local-type.ll
  llvm/test/DebugInfo/Generic/inlined-static-var.ll
  llvm/test/DebugInfo/Generic/lexical_block_static.ll
  llvm/test/DebugInfo/Generic/lexical_block_types.ll
  llvm/test/DebugInfo/Generic/namespace.ll
  llvm/test/DebugInfo/Generic/varargs.ll
  llvm/test/DebugInfo/MIR/AArch64/implicit-def-dead-scope.mir
  llvm/test/DebugInfo/NVPTX/debug-addr-class.ll
  llvm/test/DebugInfo/NVPTX/debug-info.ll
  llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
  llvm/test/DebugInfo/PowerPC/strict-dwarf.ll
  llvm/test/DebugInfo/X86/2011-09-26-GlobalVarContext.ll
  llvm/test/DebugInfo/X86/DW_AT_calling-convention.ll
  llvm/test/DebugInfo/X86/align_cpp11.ll
  llvm/test/DebugInfo/X86/align_objc.ll
  llvm/test/DebugInfo/X86/arange-and-stub.ll
  llvm/test/DebugInfo/X86/containing-type-extension-rust.ll
  llvm/test/DebugInfo/X86/debug-info-access.ll
  llvm/test/DebugInfo/X86/debug-info-blocks.ll
  llvm/test/DebugInfo/X86/debug-info-static-member.ll
  llvm/test/DebugInfo/X86/dwarf-aranges.ll
  llvm/test/DebugInfo/X86/dwarf-linkage-names.ll
  llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
  llvm/test/DebugInfo/X86/generate-odr-hash.ll
  llvm/test/DebugInfo/X86/gnu-public-names.ll
  llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
  llvm/test/DebugInfo/X86/linkage-name.ll
  llvm/test/DebugInfo/X86/namelist1.ll
  llvm/test/DebugInfo/X86/sret.ll
  llvm/test/DebugInfo/X86/string-offsets-multiple-cus.ll
  llvm/test/DebugInfo/X86/string-offsets-table-order.ll
  llvm/test/DebugInfo/X86/template.ll
  llvm/test/DebugInfo/X86/tls.ll
  llvm/test/DebugInfo/X86/vla-global.ll
  llvm/test/DebugInfo/attr-btf_tag.ll
  llvm/test/MC/WebAssembly/debug-info.ll
  llvm/test/MC/WebAssembly/debug-info64.ll
  llvm/test/MC/WebAssembly/dwarfdump.ll
  llvm/test/MC/WebAssembly/dwarfdump64.ll



More information about the llvm-commits mailing list