Skip to content

Valid program with passing asserts can abort with exit 134 while printf-based equivalent exits 0 #59

Closed

Description

@ehartford

Current behavior

A valid program can:

  • pass with check
  • print the correct intermediate values in a printf variant
  • but abort with exit code 134 under with run / with test when those same correct values are checked with assert(...)

There is no compiler diagnostic.

Why this is a bug

The spec says:

  • with run <file> and with test are normal toolchain commands in §18.5 (docs/with-specification.md, around lines 6980-6988).
  • assert(condition: bool) "Panics if false" in std.testing (docs/with-specification.md, around lines 7258-7268).

In the print-based variant below, the program computes:

  • sum=10
  • relu=0,0,0,2,5

So the assert-based variant should exit successfully. An abort with exit 134 and no diagnostic is not valid behavior.

Repro

Project layout:

  • with.toml
  • demo_pair_1.w
  • demo_pair_1_print.w
  • lib/demo/core.w
  • lib/demo/errors.w
  • lib/demo/ir.w
  • lib/demo/ir_text.w
  • lib/demo/cpu_interp.w
  • lib/demo/device.w
  • lib/demo/memory.w
  • lib/demo/view.w
  • lib/demo/program.w
  • lib/demo/stream.w

The lib/demo/*.w files are a neutralized demo.* package reproducing a small CPU interpreter/runtime stack; there is no reference to Crux in the module names or imports.

demo_pair_1.w:

use demo.core
use demo.device
use demo.memory
use demo.program
use demo.stream
use demo.view

fn write_i32(mem: *mut Memory, index: i32, value: i32):
    let ptr = memory_ptr(mem) as *mut i32
    unsafe:
        *(ptr + index as i64) = value

fn read_i32(mem: *mut Memory, index: i32) -> i32:
    let ptr = memory_ptr(mem) as *mut i32
    unsafe: *(ptr + index as i64)

fn reduce_then_relu:
    let count: i32 = 4
    let n = count as Size
    let a_mem = alloc(default_device(), n * 4usize).unwrap()
    let out_mem = alloc(default_device(), 4usize).unwrap()
    write_i32(a_mem, 0, 1)
    write_i32(a_mem, 1, 2)
    write_i32(a_mem, 2, 3)
    write_i32(a_mem, 3, 4)
    write_i32(out_mem, 0, 0)
    var src = program_source("main")
    src.ir_text = "param a in [N] i32\nparam out inout [] i32\n%0 = const i32 0\n%1 = const i32 4\nloop 0 %0 %1 1\nblock_begin 1\n%4 = load out []\n%5 = load a [@0]\n%6 = add %4 %5\nstore out [] %6\nblock_end 1\nreturn\n"
    let prog = compile(default_device(), src).unwrap()
    let entries: Vec[BindEntry] = Vec.new()
    entries.push(bind("a", view_contiguous(a_mem, shape1(n), .Int32)))
    entries.push(bind("out", view_contiguous(out_mem, shape_scalar(), .Int32)))
    let stream = stream_create(default_device())
    let event = dispatch(stream, prog, bindings_from(entries)).unwrap()
    assert(event_is_done(event))
    assert(read_i32(out_mem, 0) == 10)
    event_destroy(event)
    stream_destroy(stream)
    program_destroy(prog)
    free(a_mem)
    free(out_mem)

    let count2: i32 = 5
    let n2 = count2 as Size
    let bytes2 = n2 * 4usize
    let a2 = alloc(default_device(), bytes2).unwrap()
    let out2 = alloc(default_device(), bytes2).unwrap()
    write_i32(a2, 0, -3)
    write_i32(a2, 1, -1)
    write_i32(a2, 2, 0)
    write_i32(a2, 3, 2)
    write_i32(a2, 4, 5)
    var src2 = program_source("main")
    src2.ir_text = "param a in [N] i32\nparam out out [N] i32\n%0 = const i32 0\n%1 = const i32 5\n%2 = const i32 0\nparallel 0 %0 %1 1\nblock_begin 1\n%5 = load a [@0]\n%6 = lt %5 %2\n%7 = select %6 %2 %5\nstore out [@0] %7\nblock_end 1\nreturn\n"
    let prog2 = compile(default_device(), src2).unwrap()
    let entries2: Vec[BindEntry] = Vec.new()
    entries2.push(bind("a", view_contiguous(a2, shape1(n2), .Int32)))
    entries2.push(bind("out", view_contiguous(out2, shape1(n2), .Int32)))
    let stream2 = stream_create(default_device())
    let event2 = dispatch(stream2, prog2, bindings_from(entries2)).unwrap()
    assert(event_is_done(event2))
    assert(read_i32(out2, 0) == 0)
    assert(read_i32(out2, 1) == 0)
    assert(read_i32(out2, 2) == 0)
    assert(read_i32(out2, 3) == 2)
    assert(read_i32(out2, 4) == 5)
    event_destroy(event2)
    stream_destroy(stream2)
    program_destroy(prog2)
    free(a2)
    free(out2)

fn main:
    reduce_then_relu()

demo_pair_1_print.w is the same shape, but it prints the computed values instead of asserting them:

use c_import("stdio.h")
// same imports and helpers as above
// same two dispatches as above
// print the first result and the five relu outputs with printf instead of asserting them

Observed results:

$ with check demo_pair_1.w
ok

$ with run demo_pair_1.w
# no diagnostic
# exit 134

$ with test demo_pair_1.w
# no diagnostic
# exit 134

$ with run demo_pair_1_print.w
sum=10
relu=0,0,0,2,5
# exit 0

Expected behavior

Because the printed values are correct, the assert-based variant should also exit 0.

If an assertion is actually false, the runtime should report that assertion failure clearly. It should not silently abort with exit 134.

Activity

  1. added a commit that references this issue on Jun 8, 2026
    f7e5bb6
  2. added a commit that references this issue on Aug 17, 2026
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