Skip to content

Assigning packed struct inside another packed struct is miss aligned. #9674

@bpeake13

Description

@bpeake13

I have two packed structs that look something like this:

pub const Inner= packed struct {
    bits: u3,
    more_bits: u6,
};

pub const Outer = packed struct {
    padding: u5,
    inner: Inner,
};

Then when assigning a inner value to outer, the compiler will miss-align the assignment. For example the code:

var r: *volatile Outer = SOME_VALID_ADDRESS;

fn t(inner: Inner) void {
    r.inner = inner;
}

Will result in the first five bits of inner being assigned to padding.

zig version 0.9.0-dev.804+4c9d41730
Arch: Thumb
Model: Arm7tdmi
OS: Freestanding

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions