You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[v; N] with N > 64 and a non-Copy v byte-copies one evaluation N times (§2.3), and the fill codegen initializes only N/sizeof(T) elements: segfault / garbage (#1049) #1814
Found while closing #1478 (campaign fallout; same construct).
Repro (main 9993935, ~/.local/bin/with cffa4a40; same on the fix-lang branch)
fn main:
let s = "ab" ++ "c"
let big = [s.clone(); 65]
print(f"{big[0]} {big[64]}")
with check → ok; with run → rc=139 (SIGSEGV), no output past the first line. N=64 → abc abc, rc 0. N=3 under --debug-alloc: correct (MIR calls clone three times, aggregate([move _4, move _6, move _8])), leak count 0.
Copy case: let big = [7; 100]; print(f"{big[0]} {big[99]}") → 7 37486657 — the tail is uninitialized (#1049, open since 2026-09-04, still reproduces).
Root cause
src/MirLower.w (lang branch line 16526, array literal lowering):
if is_fill and (elem_count > 64 or self.sema.is_copy_frozen(self.expr_type(first_node)) != 0):
let fill_op = self.lower_expr(first_node)
let fill_rv = self.body.new_rvalue(RvalueKind.RK_ARRAY_FILL, fill_op, elem_count, 0)
Over 64 elements a non-Copy value takes the one-evaluation fill rvalue: one s.clone() result placed in N slots is N owners of one buffer (§2.3: transport is not duplication; never a second live value unless Copy). The comment says "over 64 copies the fill rvalue stands, as before" — i.e. the element-per-statement expansion was only avoided for size, and the fill was reused for a type it is not valid for. Separately, the RK_ARRAY_FILL codegen for N > 64 initializes N/sizeof(T) elements (#1049), and a [T; N>64] copy copies element-count bytes (#1050).
Expected
A non-Copy fill evaluates the value once per element at every N (§4.3a, the written form), lowered as a loop over the element places rather than N expanded statements; each element owns its own value.
Activity
MirLower/Sema/MirCore: a non-Copy `[v; N]` evaluates v once per eleme…
MirLower/Sema/MirCore: a non-Copy `[v; N]` evaluates v once per eleme…
MirLower/Sema/MirCore: a non-Copy `[v; N]` evaluates v once per eleme…
MirLower/Sema/MirCore: a non-Copy `[v; N]` evaluates v once per eleme…
MirLower/Sema/MirCore: a non-Copy `[v; N]` evaluates v once per eleme…
Spec v7.7 (D75): once parameters, fills, distinct casts, payload disc…