This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo][CSInfo] Avoid using clobbered registers as call-site argument locations
ClosedPublic

Authored by jmorse on Jan 9 2023, 5:58 AM.

Details

Summary

As reported in https://github.com/llvm/llvm-project/issues/57444 , when we build call-site information and find a copy from a non-volatile to a parameter register, the non-volatile shouldn't be an argument location if that register is clobbered between the copy and the call. We need to perform that check for clobbering, or incorrect values could appear in the debugger as entry values.

This patch adds a collection of register units defined as we walk back from the call site, and prevents the acceptance of a call-site parameter location if it's going to be clobbered. It's still possible for a subsequent copy to that location to be accepted, if won't be clobbered. The added test checks this using the reproducer from the bug report.

In terms of call-site coverage, I've built stage2 RelWithDebInfo clang with and without this patch, based on rG2b1d45b227bd, and there are roughly 5% fewer DW_AT_call_value attributes produced once this patch is applied, which I think we can reasonably conclude were incorrect locations.

Diff Detail

Event Timeline

jmorse created this revision.Jan 9 2023, 5:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 9 2023, 5:58 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
jmorse requested review of this revision.Jan 9 2023, 5:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 9 2023, 5:58 AM

Looks reasonable to me.

In terms of call-site coverage, I've built stage2 RelWithDebInfo clang with and without this patch, based on rG2b1d45b227bd, and there are roughly 5% fewer DW_AT_call_value attributes produced once this patch is applied, which I think we can reasonably conclude were incorrect locations.

The number refers to x86 target, right?

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
707

nit: Can we make a type alias for the small set?

jmorse updated this revision to Diff 490135.Jan 18 2023, 6:50 AM

Use a type alias instead of SmallSet directly,

@djtodoro wrote:

The number refers to x86 target, right?

That's correct, yes.

djtodoro accepted this revision.Jan 22 2023, 9:11 AM
This revision is now accepted and ready to land.Jan 22 2023, 9:11 AM
This revision was landed with ongoing or failed builds.Jan 23 2023, 4:21 AM
This revision was automatically updated to reflect the committed changes.