Skip to content

regression: compiling a x86-windows app with threads with a 64-bit compiler #19619

Closed

Description

@llogick

Zig Version

0.12.0-dev.3634+3d1652070

Steps to Reproduce and Observed Behavior

> zig build -freference-trace --summary all -Dtarget=x86-windows
install
└─ install zls
   └─ zig build-exe zls Debug x86-windows 2 errors
/home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:92:39: error: @fieldParentPtr increases pointer alignment
            const closure: *@This() = @fieldParentPtr("run_node", run_node);
                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:92:39: note: '*align(4) Thread.Pool.spawn__anon_10636.Closure' has alignment '4'
/home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:92:39: note: '*Thread.Pool.spawn__anon_10636.Closure' has alignment '8'
/home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:92:39: note: use @alignCast to assert pointer alignment
referenced by:
    spawn__anon_10636.Closure: /home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:88:58
    runFn: /home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:92:29
/home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:92:39: error: @fieldParentPtr increases pointer alignment
            const closure: *@This() = @fieldParentPtr("run_node", run_node);
                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:92:39: note: '*align(4) Thread.Pool.spawn__anon_10640.Closure' has alignment '4'
/home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:92:39: note: '*Thread.Pool.spawn__anon_10640.Closure' has alignment '8'
/home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:92:39: note: use @alignCast to assert pointer alignment
referenced by:
    spawn__anon_10640.Closure: /home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:88:58
    runFn: /home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:92:29
error: the following command failed with 2 compilation errors:
/home/rad/lab/zig/build/stage4/bin/zig build-exe -freference-trace=256 -ODebug -target x86-windows -mcpu baseline --dep exe_options --dep tracy --dep known-folders --dep zls -Mroot=/home/rad/lab/zls/npdm/src/main.zig -Mexe_options=/home/rad/lab/zls/npdm/zig-cache/c/cdb97d55e32f50fc9169d1029ec866c5/options.zig -ODebug -target x86-windows -mcpu baseline --dep options -Mtracy=/home/rad/lab/zls/npdm/src/tracy.zig -Mknown-folders=/home/rad/.cache/zig/p/12201314cffeb40c5e4e3da166217d2c74628c74486414aaf97422bcd2279915b9fd/known-folders.zig --dep known-folders --dep diffz --dep tracy --dep build_options --dep version_data -Mzls=/home/rad/lab/zls/npdm/src/zls.zig -Moptions=/home/rad/lab/zls/npdm/zig-cache/c/afa1e7d8563bc1d60b4c78e42a5d2105/options.zig -Mdiffz=/home/rad/.cache/zig/p/12200d71e4b7029ea56a429e24260c6c0e85a3069b0d4ba85eace21a0fd75910aa64/DiffMatchPatch.zig -Mbuild_options=/home/rad/lab/zls/npdm/zig-cache/c/657d1a35550280ee156902394a1ec894/options.zig -Mversion_data=/home/rad/lab/zls/npdm/zig-cache/o/e184a1362fefa6803c3727e5faace999/version_data_master_19824.zig --cache-dir /home/rad/lab/zls/npdm/zig-cache --global-cache-dir /home/rad/.cache/zig --name zls --listen=- 

Expected Behavior

It used to work afaik.

Activity

  1. added
    bugObserved behavior contradicts documented or intended behavior
    on Apr 11, 2024
  2. rohlem commented on Apr 11, 2024

    @rohlem
    Contributor

    If the pointer logic is sound (which it presumably is), the code now needs to assert the required alignment via @alignCast.
    (EDIT: Meaning we forgot to update std in this place.)

  3. Vexu commented on Apr 12, 2024

    @Vexu
    Member

    This was an intentional change in #19470

  4. nektro commented on Apr 12, 2024

    @nektro
    Contributor

    those errors and notes are all in the standard library.

    my confusion is how is a *Thread.Pool.spawn__anon_10636.Closure have an alignment of 8 on 32bit ?

  5. added
    standard libraryThis issue involves writing Zig code for the standard library.
    on Apr 12, 2024
  6. added this to the 0.13.0 milestone on Apr 12, 2024
  7. techatrix commented on Apr 12, 2024

    @techatrix
    Contributor

    Here is a code snippet that triggers the compile error:

    const std = @import("std");
    
    fn getOptional() ?u64 {
        return 0;
    }
    
    fn func(_: u64) void {}
    
    pub fn main() !void {
        var thread_pool: std.Thread.Pool = undefined;
        thread_pool.init(.{ .allocator = std.heap.page_allocator });
        defer thread_pool.deinit();
    
        if (getOptional()) |value| {
            try thread_pool.spawn(func, .{value});
        }
    }

    This doesn't happen if value is just const value: u64 = 0;

  8. added a commit that references this issue on Apr 13, 2024
  9. modified the milestones: 0.14.0, 0.13.0 on May 22, 2024
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

    arch-x8632-bit x86bugObserved behavior contradicts documented or intended behaviorstandard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions