Skip to content

overaligned pointer to packed struct always gives align(1) for fields #1994

Description

@andrewrk

This test fails:

const S = packed struct {
    a: u32,
    b: u32,
};
test "overaligned pointer to packed struct" {
    var foo: S align(4) = undefined;
    const ptr: *align(4) S = &foo;
    const ptr_to_b: *u32 = &ptr.b;
}

But Zig should know that if you have a pointer aligned to 4 bytes and then you add 4 bytes to it, it will still be 4 byte aligned.

Related: #1528

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions