zig icon indicating copy to clipboard operation
zig copied to clipboard

segfault on incorrect union field default initializer

Open travisstaloch opened this issue 3 years ago • 0 comments

Zig Version

0.10.0-dev.3986+e323cf126

Steps to Reproduce

$ cat /tmp/test.zig 
const S = struct {
    u: union(enum) {
        a: u8,
    } = .{}, // <--        segfault - incomplete initializer
    // } = .{ .a = 0 }, // ok
};
test {
    // these both trigger the segfault
    var s: S = .{};
    _ = s;
    const s2: S = .{};
    _ = s2;
}
$ zig test /tmp/test.zig 
Segmentation fault

Expected Behavior

I would expect an error message about an incorrect field default value.

Actual Behavior

Segfault. I tried to get a backtrace using gdb but the output was garbled:

$ gdb --args zig test /tmp/test.zig
GNU gdb (Debian 10.1-1.7) 10.1.90.20210103-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from zig...
(No debugging symbols found in zig)
(gdb) run
Starting program: .../zig/zig/download/zig-linux-x86_64-0.10.0-dev.3986+e323cf126/zig test /tmp/test.zig
[New LWP 407244]
[New LWP 407245]
[New LWP 407246]
[New LWP 407247]
[New LWP 407248]
[New LWP 407249]
[New LWP 407250]
[New LWP 407251]
[New LWP 407252]
[New LWP 407253]
[New LWP 407254]
[New LWP 407255]

Thread 1 "zig" received signal SIGSEGV, Segmentation fault.
0x0000000006f88910 in ?? ()
(gdb) bt
#0  0x0000000006f88910 in ?? ()
#1  0x0000000006f464cd in ?? ()
#2  0x0000000006f0ae42 in ?? ()
#3  0x0000000006f091dc in ?? ()
#4  0x0000000006fb054c in ?? ()
#5  0x0000000007207856 in ?? ()
#6  0x0000000006f241cc in ?? ()
#7  0x0000000006fdf481 in ?? ()
#8  0x0000000006ebc8bc in ?? ()
#9  0x0000000006ea6f7f in ?? ()
#10 0x0000000006df516c in ?? ()
#11 0x0000000006de4294 in ?? ()
#12 0x0000000006d67d38 in ?? ()
#13 0x00000000076185eb in ?? ()
#14 0x00000000076185c2 in ?? ()
#15 0x0000000000000000 in ?? ()

travisstaloch avatar Sep 13 '22 23:09 travisstaloch