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

Compiler Seg faults when using a switch on an undefined u0 works with u1 #1563

Closed
winksaville opened this issue Sep 19, 2018 · 2 comments
Closed
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@winksaville
Copy link
Contributor

Here is with u0:

/// Compiler Seg faults:
/// #0  0x00007f4479d32bf0 in llvm::Value::getContext() const () from /usr/lib/libLLVM-6.0.so
/// #1  0x00007f4479cd07f0 in llvm::SwitchInst::SwitchInst(llvm::Value*, llvm::BasicBlock*, unsigned int, llvm::Instruction*) () from /usr/lib/libLLVM-6.0.so
/// #2  0x00007f4479c61845 in LLVMBuildSwitch () from /usr/lib/libLLVM-6.0.so
/// #3  0x000055e869c63221 in ir_render_switch_br (g=0x55e86ad49660, executable=0x55e86adbe0f0, instruction=0x55e86afb4380) at ../src/codegen.cpp:3872
/// #4  0x000055e869c68ef8 in ir_render_instruction (g=0x55e86ad49660, executable=0x55e86adbe0f0, instruction=0x55e86afb4380) at ../src/codegen.cpp:5245
/// #5  0x000055e869c696d1 in ir_render (g=0x55e86ad49660, fn_entry=0x55e86adbdf90) at ../src/codegen.cpp:5380
/// #6  0x000055e869c6db70 in do_code_gen (g=0x55e86ad49660) at ../src/codegen.cpp:6376
/// #7  0x000055e869c7441d in codegen_build_and_link (g=0x55e86ad49660) at ../src/codegen.cpp:8229
/// #8  0x000055e869ce5739 in main (argc=4, argv=0x7fffdaaa5ee8) at ../src/main.cpp:972
test "undefined.u0" {
    var val: u0 = undefined;
    switch (val) {
        0 => assert(val == 0),
    }
}

Here is u1 that works:

test "undefined.u1.assert.truncate" {
    var val: u1 = undefined;
    switch (val) {
        0 => assert(val == 0),
        else => assert(@truncate(u1, val) == 1),
    }
}
@winksaville
Copy link
Contributor Author

The code is at zig-ux-semantics.

@andrewrk andrewrk added this to the 0.4.0 milestone Sep 19, 2018
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Sep 19, 2018
@winksaville
Copy link
Contributor Author

Here is a slightly simpler case which Seg faults:

test "switch.u0" {
    var val: u0 = 0;
    switch (val) {
        0 => assert(val == 0),
    }
}

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
Projects
None yet
Development

No branches or pull requests

2 participants