Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stage3: ICE with inlined functions / wrong number of parameters #12433

Closed
Tracked by #180
slimsag opened this issue Aug 12, 2022 · 1 comment
Closed
Tracked by #180

stage3: ICE with inlined functions / wrong number of parameters #12433

slimsag opened this issue Aug 12, 2022 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@slimsag
Copy link
Sponsor Contributor

slimsag commented Aug 12, 2022

Zig Version

0.10.0-dev.3577+b3922289b + stage3 (build/stage3/bin/zig)

Steps to Reproduce

This minimal repro only works when there are a wrong number of arguments, but it also prevents real programs from compiling. I encountered it when trying to build the new mach/gpu package with stage2:

pub inline fn instanceRequestAdapter() void {
}

pub inline fn requestAdapter(
    comptime callback: fn () callconv(.Inline) void,
) void {
    _ = (struct {
        pub fn callback() callconv(.C) void {
            callback();
        }
    }).callback;
    instanceRequestAdapter(undefined); // note wrong number of arguments here
}

inline fn foo() void {}

test {
    requestAdapter(foo);
}

Expected Behavior

Stage1 produces a proper error:

rm -rf ./zig-cache && zig build test            
./src/main.zig:12:27: error: expected 0 argument(s), found 1
    instanceRequestAdapter(undefined); // note wrong number of arguments here
                          ^

Actual Behavior

Stage2 gives an ICE:

% zig build test -fno-stage1
thread 2238175 panic: incorrect alignment
Analyzing /Users/slimsag/Desktop/zigtest/src/main.zig: main.zig:requestAdapter__struct_904.callback
      %19 = dbg_block_begin())
      %20 = dbg_stmt(2, 13)
    > %22 = closure_get(%21) 
      %23 = dbg_stmt(2, 21)
      %25 = dbg_block_end())
      %24 = call(nodiscard .auto, %22, []) 
      %26 = ret_tok(@Zir.Inst.Ref.void_value) 
    For full context, use the command
      zig ast-check -t /Users/slimsag/Desktop/zigtest/src/main.zig


/Users/slimsag/Desktop/zig/build/stage2/lib/zig/std/hash_map.zig:935:13: 0x100f33d93 in header (zig)
            self.available = 0;
            ^
/Users/slimsag/Desktop/zig/build/stage2/lib/zig/std/hash_map.zig:949:31: 0x100f339c3 in capacity (zig)

                              ^
/Users/slimsag/Desktop/zig/build/stage2/lib/zig/std/hash_map.zig:1135:39: 0x1013840e7 in getPtrAdapted__anon_214370 (zig)
            // If you get a compile error on this line, it means that your generic hash
                                      ^
/Users/slimsag/Desktop/zig/build/stage2/lib/zig/std/hash_map.zig:1234:38: 0x1011be85b in getPtrContext (zig)

                                     ^
/Users/slimsag/Desktop/zig/build/stage2/lib/zig/std/hash_map.zig:1231:38: 0x1010345ef in getPtr (zig)
            }
                                     ^
/Users/slimsag/Desktop/zig/src/Sema.zig:13451:34: 0x100e344df in zirClosureGet (zig)
        if (scope.captures.getPtr(inst_data.inst)) |tv| {
                                 ^
/Users/slimsag/Desktop/zig/src/Sema.zig:720:68: 0x100cd1cf7 in analyzeBodyInner (zig)
            .closure_get                  => try sema.zirClosureGet(block, inst),
                                                                   ^
/Users/slimsag/Desktop/zig/src/Sema.zig:604:30: 0x100cd0977 in analyzeBody (zig)
    _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                             ^
/Users/slimsag/Desktop/zig/src/Module.zig:5501:21: 0x100b7817b in analyzeFnBody (zig)
    sema.analyzeBody(&inner_block, fn_info.body) catch |err| switch (err) {
                    ^
/Users/slimsag/Desktop/zig/src/Module.zig:4212:40: 0x1009e1d17 in ensureFuncBodyAnalyzed (zig)
            var air = mod.analyzeFnBody(func, sema_arena) catch |err| switch (err) {
                                       ^
/Users/slimsag/Desktop/zig/src/Compilation.zig:2966:42: 0x1009e076b in processOneJob (zig)
            module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
                                         ^
/Users/slimsag/Desktop/zig/src/Compilation.zig:2898:30: 0x10090ab1f in performAllTheWork (zig)
            try processOneJob(comp, work_item);
                             ^
/Users/slimsag/Desktop/zig/src/Compilation.zig:2238:31: 0x10090808b in update (zig)
    try comp.performAllTheWork(main_progress_node);
                              ^
/Users/slimsag/Desktop/zig/src/main.zig:3327:20: 0x10092aba3 in updateModule (zig)
    try comp.update();
                   ^
/Users/slimsag/Desktop/zig/src/main.zig:3016:17: 0x100753c87 in buildOutputType (zig)
    updateModule(gpa, comp, hook) catch |err| switch (err) {
                ^
/Users/slimsag/Desktop/zig/src/main.zig:236:31: 0x10073115b in mainArgs (zig)
        return buildOutputType(gpa, arena, args, .zig_test);
                              ^
/Users/slimsag/Desktop/zig/src/main.zig:174:20: 0x100730947 in main (zig)
    return mainArgs(gpa, arena, args);
                   ^
/Users/slimsag/Desktop/zig/build/stage2/lib/zig/std/start.zig:574:37: 0x1007321ab in main (zig)
        },
                                    ^
???:?:?: 0x10cfb10f3 in ??? (???)
???:?:?: 0x1b63ffffffffffff in ??? (???)
error: test...
error: The following command terminated unexpectedly:
/Users/slimsag/Desktop/zig/build/stage3/bin/zig test -fno-stage1 /Users/slimsag/Desktop/zigtest/src/main.zig --cache-dir /Users/slimsag/Desktop/zigtest/zig-cache --global-cache-dir /Users/slimsag/.cache/zig --name test --enable-cache 
error: the following build command failed with exit code 6:
/Users/slimsag/Desktop/zigtest/zig-cache/o/e2f58f24df344dd1c10a8ecbac71bfd3/build /Users/slimsag/Desktop/zig/build/stage3/bin/zig /Users/slimsag/Desktop/zigtest /Users/slimsag/Desktop/zigtest/zig-cache /Users/slimsag/.cache/zig test -fno-stage1 -fno-stage1
@slimsag slimsag added the bug Observed behavior contradicts documented or intended behavior label Aug 12, 2022
@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Aug 14, 2022
@Vexu Vexu added this to the 0.10.0 milestone Aug 14, 2022
@slimsag slimsag changed the title stage2: ICE with inlined functions / wrong number of parameters stage3: ICE with inlined functions / wrong number of parameters Aug 16, 2022
@slimsag
Copy link
Sponsor Contributor Author

slimsag commented Aug 16, 2022

Updated to clarify this occurs with stage3 as well.

Vexu added a commit to Vexu/zig that referenced this issue Sep 7, 2022
Previously if a decl failed its capture scope would be deallocated and
set to undefined which would then lead to invalid dereference in
`zirClosureGet`. To avoid this set the capture scope to a special
failed state and fail the current decl with dependency failure if
the failed state is encountered in `zirClosureGet`.

Closes ziglang#12433
Closes ziglang#12530
Closes ziglang#12593
@Vexu Vexu closed this as completed in 99826a2 Sep 8, 2022
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
Previously if a decl failed its capture scope would be deallocated and
set to undefined which would then lead to invalid dereference in
`zirClosureGet`. To avoid this set the capture scope to a special
failed state and fail the current decl with dependency failure if
the failed state is encountered in `zirClosureGet`.

Closes ziglang#12433
Closes ziglang#12530
Closes ziglang#12593
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

2 participants