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

unreachable: /deps/zig/src/codegen.cpp:gen_const_val_ptr:6010 #2431

Closed
daurnimator opened this issue May 5, 2019 · 5 comments · Fixed by #4010
Closed

unreachable: /deps/zig/src/codegen.cpp:gen_const_val_ptr:6010 #2431

daurnimator opened this issue May 5, 2019 · 5 comments · Fixed by #4010
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@daurnimator
Copy link
Collaborator

─── Output/messages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────
unreachable: /deps/zig/src/codegen.cpp:gen_const_val_ptr:6010

Program received signal SIGABRT, Aborted.
__restore_sigs (set=set@entry=0x7fffffffad20) at ./arch/x86_64/syscall_arch.h:40
40	./arch/x86_64/syscall_arch.h: No such file or directory.
─── Assembly ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
0x00007ffff65efab1 __restore_sigs+14 xor    %edx,%edx
0x00007ffff65efab3 __restore_sigs+16 mov    $0x2,%edi
0x00007ffff65efab8 __restore_sigs+21 syscall 
0x00007ffff65efaba __restore_sigs+23 retq   
─── Expressions ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
─── History ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
─── Memory ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
─── Registers ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   rax 0x0000000000000000    rbx 0x0000000000000006    rcx 0x00007ffff65efaba    rdx 0x0000000000000000    rsi 0x00007fffffffad20
   rdi 0x0000000000000002    rbp 0x00007fffffffad20    rsp 0x00007fffffffad08     r8 0x0000000000000038     r9 0x00007fffffffae88
   r10 0x0000000000000008    r11 0x0000000000000246    r12 0x00007ffffa666b18    r13 0x00007ffffa666ea0    r14 0x00007ffff8044500
   r15 0x00007ffff8193a80    rip 0x00007ffff65efaba eflags [ PF ZF IF ]           cs 0x00000033             ss 0x0000002b        
    ds 0x00000000             es 0x00000000             fs 0x00000000             gs 0x00000000        
─── Source ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Cannot display "/home/buildozer/aports/main/musl/src/musl-1.1.21/./arch/x86_64/syscall_arch.h" ([Errno 2] No such file or directory: '/home/buildozer/aports/main/musl/src/musl-1.1.21/./arch/x86_64/syscall_arch.h')
─── Stack ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[0] from 0x00007ffff65efaba in __restore_sigs+23 at ./arch/x86_64/syscall_arch.h:40
arg set = 0x7fffffffad20
[1] from 0x00007ffff65efb17 in raise+68 at src/signal/raise.c:11
arg sig = 6
[+]
─── Threads ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[1] id 21175 name zig from 0x00007ffff65efaba in __restore_sigs+23 at ./arch/x86_64/syscall_arch.h:40
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
>>> bt
#0  __restore_sigs (set=set@entry=0x7fffffffad20) at ./arch/x86_64/syscall_arch.h:40
#1  0x00007ffff65efb17 in raise (sig=sig@entry=6) at src/signal/raise.c:11
#2  0x00007ffff65ea974 in abort () at src/exit/abort.c:13
#3  0x00007ffff2600b79 in std.os.abort () at /deps/zig/std/os.zig:200
#4  0x00007ffff25fe926 in std.debug.panicExtra () at /deps/zig/std/debug.zig:190
#5  0x00007ffff25fe8c8 in std.special.panic (msg=...) at /deps/zig/std/special/panic.zig:27
#6  0x00007ffff264862c in std.debug.readILeb128 () at /deps/zig/std/debug.zig:2334
#7  0x00007ffff263f01d in std.debug.parseFormValueConstant () at /deps/zig/std/debug.zig:1463
#8  0x00007ffff263d1b8 in std.debug.parseFormValue () at /deps/zig/std/debug.zig:1507
#9  0x00007ffff26393a4 in std.debug.parseDie1 (di=0x7fffffffc2c0) at /deps/zig/std/debug.zig:1599
#10 0x00007ffff2636953 in std.debug.scanAllFunctions (di=0x7fffffffc2c0) at /deps/zig/std/debug.zig:2033
#11 0x00007ffff26347d5 in std.debug.openDwarfDebugInfo (di=0x7fffffffc2c0) at /deps/zig/std/debug.zig:972
#12 0x00007ffff263117d in std.debug.openElfDebugInfo (allocator=0x7ffff7f7f318 <debug_info_arena_allocator>) at /deps/zig/std/debug.zig:998
#13 0x00007ffff263074b in std.debug.openSelfDebugInfoLinux (allocator=0x7ffff7f7f318 <debug_info_arena_allocator>) at /deps/zig/std/debug.zig:1014
#14 0x00007ffff263055d in std.debug.openSelfDebugInfo (allocator=0x7ffff7f7f318 <debug_info_arena_allocator>) at /deps/zig/std/debug.zig:777
#15 0x00007ffff2609241 in std.debug.getSelfDebugInfo () at /deps/zig/std/debug.zig:68
#16 0x00007ffff2601111 in std.debug.dumpCurrentStackTrace (start_addr=...) at /deps/zig/std/debug.zig:83
#17 0x00007ffff25fe9c8 in std.debug.panicExtra () at /deps/zig/std/debug.zig:197
#18 0x00007ffff25fe8c8 in std.special.panic (msg=...) at /deps/zig/std/special/panic.zig:27
#19 0x00007ffff25feaba in stage2_panic (ptr=0x0) at stage1.zig:16
#20 0x00007ffff2430958 in zig_panic(char const*, ...) ()
#21 0x00007ffff242d853 in gen_const_val_ptr(CodeGen*, ConstExprValue*, char const*) [clone .isra.168] [clone .cold.281] ()
#22 0x00007ffff2518553 in gen_const_val(CodeGen*, ConstExprValue*, char const*) [clone .constprop.222] ()
#23 0x00007ffff2519913 in render_const_val(CodeGen*, ConstExprValue*, char const*) ()
#24 0x00007ffff25199b6 in ir_llvm_value(CodeGen*, IrInstruction*) ()
#25 0x00007ffff2521748 in ir_render_bin_op(CodeGen*, IrExecutable*, IrInstructionBinOp*) [clone .isra.198] ()
#26 0x00007ffff252465b in ir_render_instruction(CodeGen*, IrExecutable*, IrInstruction*) [clone .isra.205] ()
#27 0x00007ffff25268a5 in do_code_gen(CodeGen*) ()
#28 0x00007ffff2529fe0 in codegen_build_and_link(CodeGen*) ()
#29 0x00007ffff2453540 in main ()

I think it's being caused by the following snippet:

fn setSize(self: *Chunk, bucketlen: usize) void {
    const rbit_start = @ptrCast([*]u8, self) + @sizeOf(Chunk);
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label May 5, 2019
@andrewrk andrewrk added this to the 0.5.0 milestone May 5, 2019
@Rocknest
Copy link
Contributor

Rocknest commented May 5, 2019

57ec183 didn't fix double panic caused by std.debug.readILeb128 () at /deps/zig/std/debug.zig:2334 :(

@daurnimator
Copy link
Collaborator Author

daurnimator commented May 11, 2019

I attempted to isolate this and got to:

const std = @import("std");

const some_cond = false;
const My_Vla_Struct = struct {
    x: if (some_cond) i32 else void,

    const Self = @This();

    pub fn usefulMethod(self: *Self) void {
        // ...
    }

    // object is followed by variable length array
};
const ListType = std.TailQueue(My_Vla_Struct);

fn newNode(allocator: *std.mem.Allocator, extra_size: usize) !*ListType.Node {
    const node_ptr = try allocator.alignedAlloc(u8, @alignOf(ListType.Node), @sizeOf(ListType.Node) + extra_size);
    return @ptrCast(*ListType.Node, node_ptr.ptr);
}

test "vla" {
    const node = try newNode(std.debug.global_allocator, 10);
    // const vla_ptr = @ptrCast([*]u8, &node.data); // zig: /build/zig/src/zig-0.4.0/src/codegen.cpp:6083: LLVMOpaqueValue* gen_const_val(CodeGen*, ConstExprValue*, const char*): Assertion `type_has_bits(type_entry)' failed.
    // const vla_ptr = @ptrToInt(&node.data); // error: pointer to size 0 type has no address
    const data = &node.data;
    data.usefulMethod();
    // const vla_ptr = @ptrToInt(data); // error: pointer to size 0 type has no address
    // const vla_ptr = @ptrCast([*]u8, data); // unreachable: /build/zig/src/zig-0.4.0/src/codegen.cpp:gen_const_val_ptr:5956
}

Related to #173

@andrewrk
Copy link
Member

andrewrk commented Sep 3, 2019

Fixed in master. I'm pretty sure this is covered by another test case.

@andrewrk andrewrk closed this as completed Sep 3, 2019
@daurnimator
Copy link
Collaborator Author

daurnimator commented Sep 3, 2019

The reduced test case above (uncomment the commented lines) still hit compiler bugs for me

@andrewrk
Copy link
Member

andrewrk commented Sep 3, 2019

Oops, my mistake. Good catch.

@andrewrk andrewrk reopened this Sep 3, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Sep 20, 2019
@daurnimator daurnimator added the stage1 The process of building from source via WebAssembly and the C backend. label Dec 22, 2019
LemonBoy added a commit to LemonBoy/zig that referenced this issue Dec 30, 2019
LemonBoy added a commit to LemonBoy/zig that referenced this issue Dec 30, 2019
andrewrk pushed a commit that referenced this issue Dec 30, 2019
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

Successfully merging a pull request may close this issue.

3 participants