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 segfault on mutually recursive structs #19920

Open
MrMugame opened this issue May 9, 2024 · 1 comment
Open

Compiler segfault on mutually recursive structs #19920

MrMugame opened this issue May 9, 2024 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@MrMugame
Copy link

MrMugame commented May 9, 2024

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.

@MrMugame MrMugame added the bug Observed behavior contradicts documented or intended behavior label May 9, 2024
@MrMugame MrMugame changed the title Compiler segfault on mutally recursive structs Compiler segfault on mutually recursive structs May 9, 2024
@Rexicon226
Copy link
Contributor

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

@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label May 10, 2024
@Vexu Vexu added this to the 0.13.0 milestone May 10, 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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

3 participants