Skip to content

Compiler bug: assertion when returning a type from a block #3376

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

Closed
tgschultz opened this issue Oct 4, 2019 · 1 comment
Closed

Compiler bug: assertion when returning a type from a block #3376

tgschultz opened this issue Oct 4, 2019 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@tgschultz
Copy link
Contributor

pub fn NewType(comptime T: type) type {
    const Padded = blk: {
        if(@sizeOf(T) <= @sizeOf(usize)) break :blk void;
        break :blk T;
    };
    
    return Padded;
}

test "" {
    const T = NewType(usize);
}

If I return directly with the block instead of storing the result in Padded it seems to work fine.

when analyzing /root/git_zig_master/build/blk_return_w_type_bug.zig:2:25: assertion failed. This is a bug in the Zig compiler.
/root/git_zig_master/src-self-hosted/stage1.zig:37:5: 0xbc1c1c in stage2_panic (userland)
    @panic(ptr[0..len]);
    ^
/root/git_zig_master/src/analyze.cpp:8852:0: 0xba1a00 in src_assert (/root/git_zig_master/src/analyze.cpp)
    stage2_panic(msg, strlen(msg));

/root/git_zig_master/src/ir.cpp:8377:0: 0xb02ee3 in ir_assert (/root/git_zig_master/src/ir.cpp)
    src_assert(ok, source_instruction->source_node);

/root/git_zig_master/src/ir.cpp:10715:0: 0xb0bbc3 in ir_start_bb (/root/git_zig_master/src/ir.cpp)
    ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? old_bb->instruction_list.at(0) : nullptr);

/root/git_zig_master/src/ir.cpp:10879:0: 0xb0c461 in ir_inline_bb (/root/git_zig_master/src/ir.cpp)
    ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block);

/root/git_zig_master/src/ir.cpp:16945:0: 0xb2242b in ir_analyze_instruction_br (/root/git_zig_master/src/ir.cpp)
        return ir_inline_bb(ira, &br_instruction->base, old_dest_block);

/root/git_zig_master/src/ir.cpp:25934:0: 0xb443c5 in ir_analyze_instruction_base (/root/git_zig_master/src/ir.cpp)
            return ir_analyze_instruction_br(ira, (IrInstructionBr *)instruction);

/root/git_zig_master/src/ir.cpp:26233:0: 0xb4522a in ir_analyze (/root/git_zig_master/src/ir.cpp)
        IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);

/root/git_zig_master/src/ir.cpp:11024:0: 0xb0cad0 in ir_eval_const_value (/root/git_zig_master/src/ir.cpp)
    ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node);

/root/git_zig_master/src/ir.cpp:16145:0: 0xb1f179 in ir_analyze_fn_call (/root/git_zig_master/src/ir.cpp)
            result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type,

/root/git_zig_master/src/ir.cpp:16361:0: 0xb1ffb2 in ir_analyze_fn_call (/root/git_zig_master/src/ir.cpp)
                        true, FnInlineAuto);

/root/git_zig_master/src/ir.cpp:16632:0: 0xb21204 in ir_analyze_instruction_call (/root/git_zig_master/src/ir.cpp)
                fn_ref, nullptr, is_comptime, call_instruction->fn_inline);

/root/git_zig_master/src/ir.cpp:25932:0: 0xb443ad in ir_analyze_instruction_base (/root/git_zig_master/src/ir.cpp)
            return ir_analyze_instruction_call(ira, (IrInstructionCallSrc *)instruction);

/root/git_zig_master/src/ir.cpp:26233:0: 0xb4522a in ir_analyze (/root/git_zig_master/src/ir.cpp)
        IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);

/root/git_zig_master/src/analyze.cpp:4500:0: 0xb928c8 in analyze_fn_ir (/root/git_zig_master/src/analyze.cpp)
            &fn->analyzed_executable, fn_type_id->return_type, return_type_node);

/root/git_zig_master/src/analyze.cpp:4599:0: 0xb92e30 in analyze_fn_body (/root/git_zig_master/src/analyze.cpp)
    analyze_fn_ir(g, fn_table_entry, return_type_node);

/root/git_zig_master/src/analyze.cpp:4733:0: 0xb937e9 in semantic_analyze (/root/git_zig_master/src/analyze.cpp)
            analyze_fn_body(g, fn_entry);

/root/git_zig_master/src/codegen.cpp:9348:0: 0xad4def in gen_root_source (/root/git_zig_master/src/codegen.cpp)
        semantic_analyze(g);

/root/git_zig_master/src/codegen.cpp:10310:0: 0xad8824 in codegen_build_and_link (/root/git_zig_master/src/codegen.cpp)
            gen_root_source(g);

/root/git_zig_master/src/main.cpp:1278:0: 0xaad92d in main (/root/git_zig_master/src/main.cpp)
                codegen_build_and_link(g);

???:?:?: 0x7fcddb7f382f in ??? (???)


???:?:?: 0x7d06258d4c544154 in ??? (???)


Segmentation fault
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Oct 9, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Oct 9, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Mar 31, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Aug 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@nektro
Copy link
Contributor

nektro commented Oct 12, 2021

this now fails with

❯ zig test test.zig
./test.zig:3:54: error: cannot store runtime value in type 'type'
        if (@sizeOf(T) <= @sizeOf(usize)) break :blk void;
                                                     ^

Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 29, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Dec 29, 2022
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
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 stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

3 participants