fix(codegen): prevent index out of bounds in dead_storage reaching_definitions#1888
Open
ArshLabs wants to merge 1 commit intohyperledger-solang:mainfrom
Open
fix(codegen): prevent index out of bounds in dead_storage reaching_definitions#1888ArshLabs wants to merge 1 commit intohyperledger-solang:mainfrom
ArshLabs wants to merge 1 commit intohyperledger-solang:mainfrom
Conversation
…finitions Signed-off-by: Arshdeep Singh <arshdeep.ssingh777@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What panics and where
solang compile --target polkadotpanics with:The panic is in
apply_transfers()at the line:resis built by iterating overtransfersin the first pass (lines 343–371). When a basic block has zero instructions — which happens with a Yulforloop whose body contains onlycontinue—transfersis empty,resis never pushed to, and indexingres[0]panics.Root cause: two cooperating bugs
Bug 1 —
dead_storage.rs:apply_transfers()does not guard against an emptytransfers/resbefore indexingres[0]. The fix is a four-line early-return that records the current reaching-definition set for the block and returns without touching*vars, which is the correct semantic: an empty block has no transfers, so the outgoing state equals the incoming state.Bug 2 —
sema/yul/for_loop.rs:resolve_for_loop()computed post-block reachability purely from whether the body block fell through (resolved_exec_block.1). A body that ends with a reachablecontinuealways reaches the post block but never falls through, so post-block reachability was incorrectly set tofalse. Codegen then skipped the post block's instructions entirely, producing an empty basic block with zero instructions — the direct trigger for Bug 1. The fix adds a helper (block_ends_with_reachable_continue) that walks the body's last reachable statement and ORs its result into the post-block reachability flag.Changes
src/codegen/dead_storage.rs— guardapply_transfers()against empty transfers/res.src/sema/yul/for_loop.rs— fix post-block reachability when body ends with a reachablecontinue; addblock_ends_with_reachable_continueandstatement_ends_with_reachable_continuehelpers.tests/polkadot_tests/yul.rs— regression testcontinue_only_for_bodythat reproduces the MRE from the issue.Minimum reproducer
Before this fix: compiler panics. After this fix: compiles cleanly.
Fixes #1876