Skip to content

emit-c: a function returning an array returns a pointer to its own dead local, and the call site assigns an array #1775

Closed

Description

@ehartford
fn arr() -> [u16; 2]: [7u16, 9u16]
fn main:
    let a = arr()
    print(a[1])

--emit-c (base 76cf0bf stage1): the function is emitted as uint16_t* arr__N() returning its local _0 (a pointer to a dead stack array), and the call site assigns the result to an array local, which clang refuses: "array type 'uint16_t[2]' is not assignable". The LLVM backend prints 9.

Expected: an array return crosses by value (a struct wrapper, or an out-pointer the caller provides), never as a pointer to the callee's frame. Found while writing #1484 (whose startup initializers store through the global instead for this reason).

Activity

  1. added 2 commits that reference this issue on Sep 28, 2026
    47d8214
    d51840e
  2. added a commit that references this issue on Oct 3, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions