Skip to content

Issue #540 : Preserve backward jump targets - #561

Open
ViktorBystrov72 wants to merge 1 commit into
yuin:masterfrom
ViktorBystrov72:fix/generic-for-jumps
Open

ViktorBystrov72 wants to merge 1 commit into
yuin:masterfrom
ViktorBystrov72:fix/generic-for-jumps

Conversation

@ViktorBystrov72

Copy link
Copy Markdown

Fixes #540.

Changes proposed in this pull request:

  • Stop jump threading at the current or an earlier instruction. Earlier jump operands are already relative offsets; treating them as label IDs can send a generic loop to unrelated bytecode.
  • Add ten execution cases covering lost return values, corrupted outer locals, nontermination, dead branches with locals/breaks/nested loops, and runtime-false/numeric-loop controls. Eight cases fail on current master and pass with the fix.

This revisits the fix proposed in #541, which was closed by its author without review.

Validation:

  • make build and make test
  • go test -count=1 ./... on Go 1.23.12 and Go 1.27.3
  • New regressions with -race -count=20 on Go 1.27.3 and -race -count=10 on Go 1.23.12
  • go test -race -skip '^TestLocalVarFree$' -count=1 ./...

The unfiltered race suite fails the existing finalizer race in TestLocalVarFree; it also reproduces on unchanged master. Standalone go vet ./... reports identical existing self-assignment/unreachable-code diagnostics on both branches. No test skips or generated-source changes are committed.

Stop threading jumps when the target is at or before the current
instruction. Earlier jump operands have already been changed from
label IDs to relative offsets, so looking them up as labels produces
invalid bytecode.

Cover generic loops containing constant-false branches, returns,
outer locals, breaks, nested loops, and unaffected control cases.

Signed-off-by: Виктор Быстров <anatema@bk.ru>
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.

if false then local x end inside a generic for loses the chunk's return value, panics with index out of range, or never finishes

1 participant