Skip to content

Infinite RAM usage while compiling certain switch statement #8352

@sareneFactorial

Description

@sareneFactorial

Here is a reproduction, simplified as much as I could:

pub fn main() anyerror!void {
    crashing_function(foo); // has to be inside its own function, or else compilation seems to succeed
}

pub fn crashing_function(i: fn()void) void {
    switch(i) { 
        foo => {}, // from my testing, the results can be anything, still hangs
        bar => {},
        baz => {},
        qux => {},
        // four functions/cases seems to be the minimum to get this behavior to occur

        else => {}
    }
}

pub fn foo() void {}
pub fn bar() void {}
pub fn baz() void {}
pub fn qux() void {}

Tested on zig 0.7.1 on Arch Linux x86_64.

Upon compilation of this code, the compiler seems to hang and continually use more and more memory. I've only been able to test it for a few seconds before it got to about 9GB of memory used, and I had to kill the process to avoid running out of memory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions