Skip to content

[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

Closed

Description

@ehartford

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

Activity

  1. added
    bug
    on Sep 27, 2026
  2. added 6 commits that reference this issue on Sep 28, 2026
    21af0dc
    3fddbec
    c68e095
    7fdb39b
    0ee7a71
    523d4df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions