Skip to content

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

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

Closed
weber-martin opened this issue Jul 14, 2022 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@weber-martin
Copy link

weber-martin commented Jul 14, 2022

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

@weber-martin weber-martin added the bug Observed behavior contradicts documented or intended behavior label Jul 14, 2022
@weber-martin weber-martin changed the title too long integer literal (> 65k) trips compiler (memory, CPU use explosion) maximum sized integer literal (u65535) trips compiler (memory, CPU use explosion) Jul 14, 2022
@weber-martin
Copy link
Author

weber-martin commented Jul 14, 2022

I believe this really has to do with consuming the literal; computing the same value via (wrapping) arithmetic works just fine:

    const maxbit: u65535 = 0;
    const maxbit_pattern = maxbit -% 1;
    assert(maxbit_pattern ^ 0 == maxbit_pattern);
    assert((maxbit_pattern - 1) & 1 == 0);
    assert((maxbit_pattern +% 1) & maxbit_pattern == 0);

@Vexu Vexu added the stage1 The process of building from source via WebAssembly and the C backend. label Jul 14, 2022
@Vexu Vexu added this to the 0.12.0 milestone Jul 14, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 16, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 17, 2022
wooster0 added a commit to wooster0/zig that referenced this issue May 28, 2023
wooster0 added a commit to wooster0/zig that referenced this issue May 28, 2023
wooster0 added a commit to wooster0/zig that referenced this issue May 28, 2023
wooster0 added a commit to wooster0/zig that referenced this issue May 28, 2023
wooster0 added a commit to wooster0/zig that referenced this issue May 28, 2023
wooster0 added a commit to wooster0/zig that referenced this issue May 28, 2023
wooster0 added a commit to wooster0/zig that referenced this issue May 28, 2023
wooster0 added a commit to wooster0/zig that referenced this issue May 29, 2023
wooster0 added a commit to wooster0/zig that referenced this issue May 29, 2023
wooster0 added a commit to wooster0/zig that referenced this issue May 29, 2023
wooster0 added a commit to wooster0/zig that referenced this issue May 29, 2023
wooster0 added a commit to wooster0/zig that referenced this issue May 29, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 2, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 6, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 13, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 15, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 15, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 15, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 15, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 15, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 15, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 15, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 15, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 15, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 15, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 17, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 18, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 19, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 19, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 20, 2023
wooster0 added a commit to wooster0/zig that referenced this issue Jun 27, 2023
@andrewrk andrewrk modified the milestones: 0.14.0, 0.11.0 Jul 3, 2023
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 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 stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

3 participants