Skip to content

Nested bitpacked struct: chained field read (o.inner.a) extracts wrong bits #635

Closed

Description

@ehartford

Summary

A nested @[bitpacked] struct's chained field read returns wrong bits. Intermediate binding is correct, and backing casts are correct — only the two-level chained-read expression mis-shifts/masks.

Repro

@[bitpacked] type Inner { a: u2, b: u2 }
@[bitpacked] type Outer { hi: u4, inner: Inner }
fn main:
    let o = Outer { hi: 0xF, inner: Inner { a: 2, b: 1 } }
    print_i32(o.inner.a as i32)   // prints 3, expected 2
    print_i32(o.inner.b as i32)   // prints 3, expected 1
    let inr = o.inner
    print_i32(inr.a as i32)       // prints 2 (correct)
    print_i32((o as u8) as i32)   // 0xF9 (correct)

Deterministic. Intermediate let inr = o.inner; inr.a → correct; o as u8/o.inner as u8 → correct. So the chained-read shift/mask composition is wrong.

Spec §4.3b

Nested bitpacked field access. Candidate: the codegen path for a two-level bitpacked field projection composes the outer+inner shift/mask incorrectly.

Found

Coverage sweep #484, 2026-07-03. Single-level bitpacked (behav_bitpacked_single) works and is pinned; this nested case is the gap.

Activity

  1. ehartford commented on Jul 5, 2026

    @ehartford
    ContributorAuthor

    Fixed in dd451f8. The nested bitpacked projection loop overwrote the outer field's bit offset with the inner field's instead of accumulating them; o.inner.a now reads 2 (was 3). One site in mir_place_ptr accumulates offsets (existing+this, innermost width); the store RMW path shares the same projection map so nested writes are fixed too. Verified two- and three-level reads + nested writes; single-level unaffected. Fixpoint + full suite green; 3 fixtures.

  2. added a commit that references this issue on Jul 5, 2026
    dd451f8
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