Skip to content

maximum sized integer literal (u65535) trips compiler (memory, CPU use explosion) #12116

@weber-martin

Description

@weber-martin

Zig Version

0.9.1

Steps to Reproduce

create the problematic file with these steps (sorry for including code to generate this, gh issue complains about too long body for this field)

$ cat bomb.zig

const assert = @import("std").debug.assert;

test "integer literals" {
    // reading this 65537 ("0b" + 65535 "1"s) bytes long literal trips the compiler ...
    const literal_maxbit_pattern: u65535 = 0bX;
    assert(literal_maxbit_pattern > 0);
}

$ ones=$(head -c 65535 /dev/zero | tr '\0' '1');
$ sed -i bomb.zig -e "s;X;$ones;"

open something where you can see CPU and memory use (e.g. xosview, top, whatever)
then run the test:
zig test bomb.zig
Watch the resource usage explode.

Expected Behavior

test runs successfully

Actual Behavior

test run runs out of memory

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions