Skip to content

Index fat-slice data pointers by slice element #209

Closed

Description

@niklebedenko

Problem

Mutable references and projected assignments through a fat slice can compute the wrong address when the slice element type is itself an array. For example, rows[row][0] on &mut [[f32; 2]] should step by one [f32; 2] row first, then select column 0. The MIR address walker currently classifies the extracted slice data pointer from its pointee type alone, so ptr<[f32; 2]> can be mistaken for a pointer to one array object and the row index writes inside row 0 instead.

Why this matters

Fat slice indexing is standard Rust codegen for mutable slice borrows, slice::get_mut, raw address-taking, and projected assignments. Device code that works with slices of fixed-size vectors or matrix rows can silently write the wrong element instead of failing to compile.

Expected behavior

After dereferencing a fat slice, the extracted data pointer should be indexed as a pointer to slice elements. If the slice element is [T; N], the first index should move by one whole [T; N]; only the next index should select inside that array element.

Acceptance criteria

  • A focused regression with &mut [[f32; 2]] fails on upstream/main by writing row 0 column 1 instead of row 1 column 0.
  • The same regression passes on the patched branch.
  • Runtime Index, forward ConstantIndex, mutable-reference address materialization, and direct projected assignment are covered.
  • Existing scalar-element fat-slice write cases continue to pass.
  • The implementation distinguishes "data pointer extracted from a fat slice" from "ordinary pointer to one array object" before choosing pointer-offset versus array-element-address lowering.

Activity

  1. added
    bug
    miscompile
    codegen
    IR-lowering
    on Jun 16, 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

    IR-loweringbugcodegenmiscompile

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions