Skip to content

Codegen: index and slice bounds are checked in every build but --release, a fact of its own, not inferred from debug info (#2268) - #2664

Merged
ehartford merged 1 commit into
fix-2270from
fix-2268
Oct 25, 2026
Merged

ehartford merged 1 commit into
fix-2270from
fix-2268

Conversation

@ehartford

@ehartford ehartford commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Root cause: mir_emit_debug_index_bounds_check and
mir_emit_debug_slice_bounds_check (src/CodegenDispatch.w) returned when
self.debug_info == 0. A one-liner and the REPL build with debug info off
(run_one_liner_command, run_repl_line: set_debug_info(false)), as does -g0,
so with -e 'let a = [1, 2]' -e 'print(f"{a[5]}")' read past the end and
exited 0 where the same program in a file panics. §4.3a leaves bounds
unchecked only in release.

release is its own fact: CompilationConfig.release, DriverOptions.release
(--release), passed by the backend to Codegen.release; cli_release_flag
reads --release among the driver's own arguments (run_cli's argc, never
the program's). The checks skip only when it is set.

Test: test/behavior/behav_2268_one_liner_checks_bounds.w (the one-liner
must panic "index out of bounds"; the installed compiler exits 0).

Closes #2268

…ase, a fact of its own, not inferred from debug info (#2268)

Root cause: mir_emit_debug_index_bounds_check and
mir_emit_debug_slice_bounds_check (src/CodegenDispatch.w) returned when
`self.debug_info == 0`. A one-liner and the REPL build with debug info off
(run_one_liner_command, run_repl_line: set_debug_info(false)), as does -g0,
so `with -e 'let a = [1, 2]' -e 'print(f"{a[5]}")'` read past the end and
exited 0 where the same program in a file panics. §4.3a leaves bounds
unchecked only in release.

`release` is its own fact: CompilationConfig.release, DriverOptions.release
(`--release`), passed by the backend to Codegen.release; cli_release_flag
reads `--release` among the driver's own arguments (run_cli's argc, never
the program's). The checks skip only when it is set.

Test: test/behavior/behav_2268_one_liner_checks_bounds.w (the one-liner
must panic "index out of bounds"; the installed compiler exits 0).
@ehartford
ehartford added this pull request to stack #2668 October 25, 2026 22:01
@ehartford ehartford changed the title fix 2268 Codegen: index and slice bounds are checked in every build but --release, a fact of its own, not inferred from debug info (#2268) Oct 25, 2026
@ehartford
ehartford marked this pull request as ready for review October 25, 2026 22:13
@ehartford
ehartford merged commit 63bab59 into main Oct 25, 2026
@ehartford
ehartford deleted the fix-2268 branch October 25, 2026 22:14
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.

One-liners and the REPL have no bounds checks: with -e 'print(f"{[1, 2][5]}")' reads past the end and exits 0

1 participant