Skip to content

Tolk: -O2 compiler crash on beginCell().storeInt(0, 256) with constant arguments #2031

@Gusarich

Description

@Gusarich

With -O2 (the default optimization level), compiling code that contains beginCell().storeInt(0, 256) crashes the compiler with an internal assertion failure in the optimizer. With -O1, the same code compiles successfully.

Reproduction

Create /tmp/tolk_storeint256_o2_crash.tolk:

tolk 1.0

fun onInternalMessage() { return 0; }

@method_id(100)
fun f(): int {
    val c = beginCell().storeInt(0, 256).endCell();
    return c.hash();
}

Compile with -O1 (works):

./artifacts/tolk -O1 /tmp/tolk_storeint256_o2_crash.tolk > /tmp/tolk_storeint256_o1.fif

Compile with -O2 (crashes):

./artifacts/tolk -O2 /tmp/tolk_storeint256_o2_crash.tolk > /tmp/tolk_storeint256_o2.fif

Observed output

The compiler crashes with:

fatal: Assertion failed at tolk/optimize.cpp:62: p_ > 0 && p_ <= l_ && q_ >= 0 && q_ <= optimize_depth && l_ <= optimize_depth

Expected behavior

-O2 should not crash on valid code. It should compile successfully (or emit a regular diagnostic), consistent with -O1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    TolkRelated to Tolk Language / compiler / toolingllm-fuzzing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions