Skip to content

An element is stored into once the value is ready - #658

Merged
ASDAlexander77 merged 4 commits into
mainfrom
fix-element-store-after-value
Oct 23, 2026
Merged

ASDAlexander77 merged 4 commits into
mainfrom
fix-element-store-after-value

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Fixes fuzzer repro 6930 (#646), found in a fresh range past the first 1000 programs. It fails on main as well.

a[0] = grow(a);   // grow pushes onto a: the store went into the block the growth gave back

Why

The element's address was taken while the left side was read, before the right side ran. Growing the array moved its elements to a new block, so the store went into the old one, which had been freed. The value was lost under every model, and under rc the program also wrote to a freed block.

Fix

The assignment takes the element's address again once the value is ready. MLIRGen clones the ts.ElementRef after the value is computed, from the array and the index the left side already evaluated. That follows JavaScript order: a right side that assigns the variable itself (a[1] = (a = [5], 9)) still stores into the old array.

Tests

tests/00element_store_after_value.ts covers:

  • a number element
  • an object element
  • a compound assignment (a[0] += grow(a))
  • an element of a field
  • a right side that reassigns the array variable It runs compiled, under JIT, and in the rc/none corpus. It fails on main.

Verification

🤖 Generated with Claude Code

ASDAlexander77 and others added 4 commits October 23, 2026 06:41
`a[0] = f()` with `f` growing `a`: the element's address was taken while
the left side was read, before the right side ran, and growing moved
the elements to a new block - the store went into the one given back.
The value was lost under every model, and under rc a freed block was
written to (fuzzer #646, 6930). The assignment now takes the element's
address again once the value is ready, from the array and the index
the left side evaluated first, as JavaScript has it: a right side that
assigns the variable itself (`a[1] = (a = [5], 9)`) still stores into
the old array.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er-value

# Conflicts:
#	tslang/test/tester/CMakeLists.txt
…er-value

# Conflicts:
#	tslang/test/tester/CMakeLists.txt
@ASDAlexander77
ASDAlexander77 merged commit 4dabb34 into main Oct 23, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-element-store-after-value branch October 23, 2026 09:43
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.

1 participant