This is an archive of the discontinued LLVM Phabricator instance.

Do not optimize debug locations across section boundaries
ClosedPublic

Authored by pcalixte on Apr 26 2023, 2:19 PM.

Details

Summary

Prevent optimization of DebugLoc across section boundaries, such optimization will yield incorrect source location if memory layout of sections does not strictly match the Asm file.

Diff Detail

Event Timeline

pcalixte created this revision.Apr 26 2023, 2:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2023, 2:19 PM
pcalixte requested review of this revision.Apr 26 2023, 2:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2023, 2:19 PM
Orlando added a subscriber: Orlando.

This seems sensible and the test looks good. I've added other reviewers who might want to take a look.

Please could you add context to the patch (e.g. git diff -U9999)?

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
2049–2050

I think it'd be worth splitting the new condition out to name it - or possibly just adding a comment instead.

bool PrevInstInSameSection = PrevInstBB &&
      PrevInstBB->getSectionIDNum() == MI->getParent()->getSectionIDNum();

if (DL == PrevInstLoc && PrevInstInSameSection)  {

And I'm not sure if I'm reading it right but should the condition be (!PrevInstBB || PrevInstBB->getSectionIDNum() == MI->getParent()->getSectionIDNum()) instead to maintain "first instruction" behaviour when DL is an unspecified location (!DL)?

pcalixte updated this revision to Diff 518338.Apr 30 2023, 11:20 AM

Fixing and naming new condition for clarity (according to review)

Thank you Orlando - you are correct - I have updated the review as you suggested

pcalixte updated this revision to Diff 518477.May 1 2023, 10:01 AM

not change - regenerate diff based on main

dblaikie accepted this revision.May 1 2023, 5:20 PM

Looks OK to me. Not sure if this'll end up having any overlap with D147506

This revision is now accepted and ready to land.May 1 2023, 5:20 PM
pcalixte updated this revision to Diff 518609.May 1 2023, 5:36 PM

same contents - removing extra blanks

MaskRay accepted this revision.May 1 2023, 6:49 PM
MaskRay added a subscriber: MaskRay.
MaskRay added inline comments.
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
5

Nit: It's more common to omit the blank line.

llvm/test/DebugInfo/debuglineinfo-at-section-boundary.ll
1 ↗(On Diff #518609)

Drop -filetype=asm. It's the default and assumed by most `llc invocations.

Drop -asm-verbose=0 as well. There is no difference in the output. The option isn't common to specify.

Prevent optimization of DebugLoc across section boundaries, such optimization will yield incorrect source location if memory layout of sections does not strictly match the Asm file.

Consider adding the .loc 0 4 1 information to the summary (commit message).

pcalixte updated this revision to Diff 519183.May 3 2023, 12:25 PM

DwarfDebug.cpp:
Remove empty line as per review
clang-format

testcase:
remove -filetype=asm and -asm-verbose=0 as per review.
[you may have noticed that the test was failing on Windows/ -basic-block-sections not supported]
I have moved and renamed the testcase to be more in sync with existing testcases for basic-block-sections

pcalixte marked 2 inline comments as done.May 3 2023, 10:15 PM

I do not have commit access, can someone with the proper credentials commit the patch? [if the the latest version looks ok]

This revision was automatically updated to reflect the committed changes.

Sorry I haven't been keeping up, but I have a suggestion for the test.

llvm/test/DebugInfo/X86/basic-block-sections-debug-lineinfo-at-section-boundary.ll
17 ↗(On Diff #520535)

This shows there are two .loc directives, but not that they are in different sections. I know I've seen redundant .loc directives and we even have a downstream patch to filter them out, so I think it would be good for this test to at least verify there's a .section directive between the two .loc directives.