zig
zig copied to clipboard
Compiler segfault on mutually recursive structs
trafficstars
Zig Version
0.12.0
Steps to Reproduce and Observed Behavior
test.zig
const struct_A = struct {
b: struct_B,
};
const struct_B = struct {
a: struct_A,
};
pub fn main() void {
const s: struct_B = undefined;
_ = s;
}
Run with: zig run test.zig
This results in the compiler to segfault:
[1] 59758 segmentation fault (core dumped) zig run test.zig
Expected Behavior
I expected the compiler to throw an error message on mutually recursive structs not being allowed, instead it segfaults.
The segfault happens because of infinite recursion in the compiler. Related #13724.
Back trace:
....
frame #18132: 0x0000000008955669 zig`type.Type.hasRuntimeBitsAdvanced at type.zig:585:64
frame #18133: 0x0000000008955669 zig`type.Type.hasRuntimeBitsAdvanced at type.zig:585:64
frame #18134: 0x0000000008955669 zig`type.Type.hasRuntimeBitsAdvanced at type.zig:585:64
frame #18135: 0x0000000008955669 zig`type.Type.hasRuntimeBitsAdvanced at type.zig:585:64
frame #18136: 0x0000000008955669 zig`type.Type.hasRuntimeBitsAdvanced at type.zig:585:64
frame #18137: 0x000000000851cab3 zig`Sema.typeHasRuntimeBits at Sema.zig:37679:37
frame #18138: 0x0000000009c55225 zig`Sema.addDbgVar at Sema.zig:6747:38
frame #18139: 0x00000000094b2f84 zig`Sema.zirDbgVar at Sema.zig:6727:23
frame #18140: 0x0000000008df6bce zig`Sema.analyzeBodyInner at Sema.zig:1317:35
frame #18141: 0x0000000008816252 zig`Sema.analyzeFnBody at Sema.zig:892:26
Can reproduce on 0.13.0, seems to be fixed on latest master.