[PATCH] D147620: [DebugInfo] Keep the CU consistent for operating `DISubprogram`.

DianQK via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 27 05:19:46 PDT 2023


DianQK added a comment.

I re-looked at this IR and the associated code implementation.
I have some discoveries.

>From the perspective of code implementation, I think this IR maybe is OK.
The IR doesn't have member function definitions directly associated with DICompositeTypes. **The elements of `!21` DICompositeType are empty.**
Then I found a C++ example at D58538 <https://reviews.llvm.org/D58538>. `!26` unit is `!10`, and `!1` indirectly references `!26`. It's a similar case. D58786 <https://reviews.llvm.org/D58786> is probably similar (I didn't look much at it).
I think these patches are a workaround with inconsistent scope and unit.

I started debugging why adding a declaration would solve this issue.

See DwarfUnit.cpp#L1163-L1166 <https://github.com/llvm/llvm-project/blob/fe3ed6550ef277f5c47a9ccdbdd466fa225f4a99/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp#L1163-L1166>:

  if (auto *SPDecl = SP->getDeclaration()) {
    if (!Minimal) {
      // Add subprogram definitions to the CU die directly.
      ContextDIE = &getUnitDie();

So for this IR, it just needs to add a declaration (we don't need add `elements` for `!21`):

  -!23 = distinct !DISubprogram(name: "alloc_impl", linkageName: "_ZN5alloc5alloc6Global10alloc_impl17h238d0844851c71a5E", scope: !21, file: !24, line: 170, type: !25, scopeLine: 170, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !1, templateParams: !3, retainedNodes: !3)
  +!23 = distinct !DISubprogram(name: "alloc_impl", linkageName: "_ZN5alloc5alloc6Global10alloc_impl17h238d0844851c71a5E", scope: !21, file: !24, line: 170, type: !25, scopeLine: 170, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !1, declaration: !40, templateParams: !3, retainedNodes: !3)
  ...
  +!39 = !{!40}
  +!40 = !DISubprogram(name: "alloc_impl", linkageName: "_ZN5alloc5alloc6Global10alloc_impl17h238d0844851c71a5E", scope: !21, file: !24, line: 170, type: !25, scopeLine: 170, flags: DIFlagPrototyped, spFlags: 0)

This has nothing to do with members, just a declaration to switch the parent DIE from scope to unit.
So I think this should address in LLVM.

But why is it inconsistent? I think this may be a bug in LTO. I'll continue to debug the DWARF code and take a look at the LTO later.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147620/new/

https://reviews.llvm.org/D147620



More information about the llvm-commits mailing list