Skip to content

Compiler panic in codegen: index out of bounds: the len is 0 but the index is 0 in dead_storage::reaching_definitions #1876

@jubnzv

Description

@jubnzv

The compiler panics with index out of bounds: the len is 0 but the index is 0 in src/codegen/dead_storage.rs (reaching_definitions) when a Yul for loop's body consists only of a continue. The lowering produces a basic block whose block_vars entry is an empty Vec<ReachingDefs>, and the dataflow code unconditionally indexes [0] into it.

MRE:

contract C {
    function f() public pure {
        assembly {
            for { let i := 0 } lt(i, 1) { i := add(i, 1) } { continue }
        }
    }
}

Reproduce: save as mre.sol, run solang compile --target polkadot mre.sol.

Output:

thread 'main' panicked at src/codegen/dead_storage.rs:NNN:
index out of bounds: the len is 0 but the index is 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior: codegen handles the empty-body / bare-continue Yul for loop without panicking (the loop is a no-op and should compile cleanly).

Reproduces on all three targets that support Yul (polkadot, solana, evm).

Git commit: 901bfb9
Build: release
rustc 1.96.0-nightly (562dee482 2026-03-21)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions