This is an archive of the discontinued LLVM Phabricator instance.

[DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)

Authored by dzhidzhoev on Feb 14 2023, 6:23 AM.




Fixed PR51501 (tests from D112337).

This patch proposes two changes that get squashed to this single patch due to
their close dependencies:

  1. Reuse of DISubprogram's 'retainedNodes' to track other function-local entities together with local variables and labels (this patch cares about function-local import while D144006 and D144008 use the same approach for local types and static variables). So, effectively this patch moves ownership of tracking local import from DICompileUnit's 'imports' field to DISubprogram's 'retainedNodes' and adjusts DWARF emitter for the new layout. The old layout is considered unsupported (DwarfDebug would assert on such debug metadata).

    DICompileUnit's 'imports' field is supposed to track global imported declarations as it does before.

    This addresses various FIXMEs and simplifies the next part of the patch.
  1. Postpone emission of function-local imported entities from DwarfDebug::endFunctionImpl() to DwarfDebug::endModule(). While in DwarfDebug::endFunctionImpl() we do not have all the information about a parent subprogram or a referring subprogram (whether a subprogram inlined or not), so we can't guarantee we emit an imported entity correctly and place it in a proper subprogram tree. So now, we just gather needed details about the import itself and its parent entity (either a Subprogram or a LexicalBlock) during processing in DwarfDebug::endFunctionImpl(), but all the real work is done in DwarfDebug::endModule() when we have all the required information to make proper emission.

Diff Detail

Event Timeline

krisb created this revision.Feb 14 2023, 6:23 AM
Herald added a project: Restricted Project. · View Herald Transcript
krisb published this revision for review.Feb 17 2023, 6:29 AM
krisb edited the summary of this revision. (Show Details)
krisb added reviewers: dblaikie, jmmartinez, ellis.
krisb added projects: Restricted Project, debug-info.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2023, 6:30 AM

I've added just a few minor remarks.


NIT: You could avoid writing the for loop


Nit: lookup returns the value in the map or returns a default value.


I'd be tempted to match the offset of the abstract subprogram and of the imported declaration too.
At least for me, it makes clear the intention of the test without running it.

What do you think ?

krisb updated this revision to Diff 499848.Feb 23 2023, 7:16 AM
krisb marked 2 inline comments as done.

Apply review comments.


Good point, thank you!

ykhatav added a subscriber: ykhatav.Mar 3 2023, 8:56 AM
jmmartinez accepted this revision.Mar 10 2023, 6:09 AM
This revision is now accepted and ready to land.Mar 10 2023, 6:09 AM
krisb updated this revision to Diff 504605.Mar 13 2023, 5:30 AM


This comment was removed by dzhidzhoev.

Fixed split-dwarf-local-import*.ll tests.

dzhidzhoev updated this revision to Diff 529098.Jun 6 2023, 5:10 PM

Added AutoUpdater, moving function-local imported entities belonging to DICompileUnit to a corresponding DISubprogram.

This revision was landed with ongoing or failed builds.Jun 15 2023, 5:29 AM
This revision was automatically updated to reflect the committed changes.