p4c icon indicating copy to clipboard operation
p4c copied to clipboard

Crash when `switch` expression is a constant-valued directionless argument

Open kfcripps opened this issue 7 months ago • 1 comments

Building the following P4 program with p4test:

void bar(bit<2> x, out bit<8> y) {
    switch (x) {
        0b01: { y = 2; }
        0b10: { y = 3; }
    }
}

control C(out bit<8> y) {
    action foo() {
        bar(1, y);
    }

    table t {
        actions = { foo; }
        default_action = foo;
    }

    apply {
        t.apply();
    }
}

control proto(out bit<8> y);
package top(proto p);

top(C()) main;

results in:

tmp.p4(2): [--Wwarn=mismatch] warning: x: constant expression in switch
    switch (x) {
            ^
In file: ../../../frontends/p4/simplifySwitch.cpp:34
Compiler Bug: tmp.p4(2): Unexpected expression x;
    switch (x) {
            ^

kfcripps avatar Jun 09 '25 17:06 kfcripps

This is possibly a duplicate of issue https://github.com/p4lang/p4c/issues/5120

kfcripps avatar Jun 09 '25 20:06 kfcripps