Skip to content

Bug: constant-folded left shift 1 << (1 << 30) OOMs the compiler #422

Description

@anon-researchers-123

Expected behavior

A shift count larger than the field bit-width should be rejected with a diagnostic
(there is an unused BitOverFlowInShift error variant for this), not turned into an
unbounded allocation.

The bug

A constant-folded left shift with a large shift count allocates a BigInt whose size is
the shift count in bits, with no upper bound, so the compiler hangs and eventually OOMs.

template T() {
    var v = 1 << (1 << 30);   // ~1**9-bit intermediate; hangs/OOMs
}
component main = T();

1 << (1 << 30) builds a ~1-billion-bit intermediate; 1 << (1 << 31) and up
OOM-kill the process on a typical CI runner.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions