Skip to content

[DebugInfo] Avoid dropping debug reconstruction blocks#89412

Open
Snowy1803 wants to merge 6 commits into
swiftlang:mainfrom
Snowy1803:cleanup-debug-value-cloning
Open

[DebugInfo] Avoid dropping debug reconstruction blocks#89412
Snowy1803 wants to merge 6 commits into
swiftlang:mainfrom
Snowy1803:cleanup-debug-value-cloning

Conversation

@Snowy1803
Copy link
Copy Markdown
Member

@Snowy1803 Snowy1803 commented May 26, 2026

Auditing everywhere DebugValueInst are cloned, changed, or created by passes, to make sure the debug reconstruction blocks remain correct.

  • Add an assertion that the CapturePromotion, MoveOnlyAddressChecker and MovedAsyncVarDebugInfoPropagator passes, which clone debug values without going through the SILCloner, can't drop debug reconstruction block, as they are run before or instead of optimizations passes that could create them.
  • salvageStoreDebugInfo now supports removing the loads of the operand if there is a debug reconstruction block: for this, stripDeref was added to remove an op_deref or a load depending on if there is a debug reconstruction block, and killOperand was added to remove the operand from a debug value when we cannot recover it.
  • SROA now correctly drops debug info when a debug reconstruction block is present, rather than creating invalid debug info

PhiExpansion is fixed in a separate PR: #89471
salvage struct&tuple is fixed in #89504

@Snowy1803 Snowy1803 force-pushed the cleanup-debug-value-cloning branch 2 times, most recently from 3b131b0 to 075d263 Compare May 26, 2026 16:46
@Snowy1803 Snowy1803 force-pushed the cleanup-debug-value-cloning branch 3 times, most recently from 20f2b5f to f277eaa Compare May 27, 2026 11:20
@Snowy1803
Copy link
Copy Markdown
Member Author

@swift-ci test

@Snowy1803 Snowy1803 marked this pull request as ready for review May 27, 2026 11:35
@Snowy1803
Copy link
Copy Markdown
Member Author

@swift-ci test macOS platform

@Snowy1803
Copy link
Copy Markdown
Member Author

@swift-ci test windows platform

@Snowy1803 Snowy1803 marked this pull request as draft May 27, 2026 17:55
@Snowy1803 Snowy1803 force-pushed the cleanup-debug-value-cloning branch from f277eaa to 19c87fd Compare May 27, 2026 18:39
@Snowy1803 Snowy1803 marked this pull request as ready for review May 27, 2026 18:39
@Snowy1803
Copy link
Copy Markdown
Member Author

@swift-ci test

1 similar comment
@Snowy1803
Copy link
Copy Markdown
Member Author

@swift-ci test

Comment thread lib/SIL/IR/SILInstructions.cpp Outdated
Comment thread lib/SIL/IR/SILInstructions.cpp Outdated
@Snowy1803 Snowy1803 force-pushed the cleanup-debug-value-cloning branch from 19c87fd to 7bb29d3 Compare May 29, 2026 09:29
@Snowy1803
Copy link
Copy Markdown
Member Author

@swift-ci smoke test

Snowy1803 added 6 commits May 29, 2026 13:20
This function drops debug_value operands by making them undef, rather
than deleting them.
The CapturePromotion and MovedAsyncVarDebugInfoPropagator passes clone
debug values without going through the SILCloner, so they don't handle
debug basic blocks. Luckily, they should never see debug basic blocks,
as they are called before or instead of any optimizations that might
create them. Add an assertion to make sure of this.
This new function reverses prependDeref. Mem2reg will call it to remove
the deref from a debug_value. If the debug_value relies on the address
rather than the value behind it, it kills the operand.
When a store was being salvaged, the reconstruction block was dropped,
which could cause invalid debug values to be created. Reconstruction
blocks are now cloned with the debug values, and the uses of the address
removed by stripDeref.

Assisted-by: Claude
If a debug_value on an alloc_stack being SROA'ed has a debug reconstruction
block, for example if the variable represents the pointer value directly, its
value needs to be dropped and marked as unsalvageable.
@Snowy1803 Snowy1803 force-pushed the cleanup-debug-value-cloning branch from 7bb29d3 to fe17812 Compare May 29, 2026 11:21
@Snowy1803
Copy link
Copy Markdown
Member Author

@swift-ci smoke test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants