Skip to content

Packed struct containing a pointer causing build failure on Windows #24186

@mrtnmat

Description

@mrtnmat

Zig Version

0.14.1

Steps to Reproduce and Observed Behavior

const Test = packed struct {
    ptr: *usize,
    fn init() Test {
        return Test{
            .ptr = @ptrFromInt(0x04000000),
        };
    }
};

var t: Test = undefined;

pub fn main() void {
    t = Test.init();
}

This code fails to compile on Windows 11 but compiles just fine on Mac, same 0.14.1 version of the compiler.
The error seems to be caused by the packed attribute, without it there's no issue.

Error message:

C:\Users\<username>\scoop\apps\zig\0.14.1\zig.exe build-exe -ODebug -Mroot=C:\Users\<username>\Desktop\zigbug\src\main.zig --cache-dir C:\Users\<username>\Desktop\zigbug\.zig-cache --global-cache-dir C:\Users\<username>\AppData\Local\zig --name bug_example --zig-lib-dir C:\Users\<username>\scoop\apps\zig\0.14.1\lib\ --listen=-
install
└─ install bug_example
   └─ zig build-exe bug_example Debug native failure
error: the following command exited with error code 3:
C:\Users\<username>\scoop\apps\zig\0.14.1\zig.exe build-exe -ODebug -Mroot=C:\Users\<username>\Desktop\zigbug\src\main.zig --cache-dir C:\Users\<username>\Desktop\zigbug\.zig-cache --global-cache-dir C:\Users\<username>\AppData\Local\zig --name bug_example --zig-lib-dir C:\Users\<username>\scoop\apps\zig\0.14.1\lib\ --listen=-
Build Summary: 0/3 steps succeeded; 1 failed
install transitive failure
└─ install bug_example transitive failure
   └─ zig build-exe bug_example Debug native failure
error: the following build command failed with exit code 1:
C:\Users\<username>\Desktop\zigbug\.zig-cache\o\7321ba064b3b2d7568f2014a47a4a1a5\build.exe C:\Users\<username>\scoop\apps\zig\0.14.1\zig.exe C:\Users\<username>\scoop\apps\zig\0.14.1\lib C:\Users\<username>\Desktop\zigbug C:\Users\<username>\Desktop\zigbug\.zig-cache C:\Users\<username>\AppData\Local\zig --seed 0xf239d964 -Zc045b5e11bd18639 --verbose

Expected Behavior

Successful compile on Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions