This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo][InstrRef] Avoid a crash from mixed variable location modes
ClosedPublic

Authored by jmorse on Apr 4 2022, 7:53 AM.

Details

Summary

Variable locations now come in two modes, instruction referencing and DBG_VALUE -- I initially assumed that we could use information like the current optimisation level to detect which mode we should use (-O0 uses DBG_VALUE). Unfortunately, it turns out that SelectionDAG fiddles with the optimisation level in the presence of opt-bisect-limit (see the lines in SelectionDAGISel::runOnMachineFunction immediately below my additions), making this not a robust technique. Over in [0] there's a crash observed from this, SelectionDAG produces DBG_VALUEs but the debug-info passes expect to see DBG_INSTR_REFs.

Changing the target options in the middle of a pass is accepted as a horrible hack in the comments in SelectionDAG -- there's not much to do about this, except:

  • Store a flag in MachineFunction indicating what flavour of debug-info it contains,
  • Plumb the original debug-info flavour through SelectionDAG so that the correct one is picked.

This patch implements the latter: the "use instr-ref?" boolean is stored before the target options are edited, then passed down to the instruction emitting functions. This is mildly ugly, but there aren't any good options.

[0] https://github.com/llvm/llvm-project/issues/53937

Diff Detail

Event Timeline

jmorse created this revision.Apr 4 2022, 7:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2022, 7:53 AM
jmorse requested review of this revision.Apr 4 2022, 7:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2022, 7:53 AM
Orlando accepted this revision.Apr 4 2022, 9:53 AM

I wonder if the test IR could be simplified. Would it not be enough to have a function with a single dbg.value and nothing else?

LGTM either way.

This revision is now accepted and ready to land.Apr 4 2022, 9:53 AM
jmorse added a comment.Apr 6 2022, 3:49 AM

Dropping in with the addition of a null-check in SelectionDAGISel::SelectAllBasicBlocks, not all targets actaully create a FastISel instance when createFastISel is called.

This revision was landed with ongoing or failed builds.Apr 6 2022, 3:56 AM
This revision was automatically updated to reflect the committed changes.