-
Notifications
You must be signed in to change notification settings - Fork 475
Description
Seems like we crash when switch case contains a serializable enum value.
Related to p4lang/p4-spec#1369, #5246.
<stdin>(64): [--Wwarn=mismatch] warning: 32w1: constant expression in switch
switch (32w1) {
^^^^
<stdin>(17): [--Wwarn=parser-transition] warning: SelectCase: unreachable case
2: two;
^^^^^^
<stdin>(37): [--Wwarn=parser-transition] warning: accept state in parser p1 is unreachable
parser p1(out bit<32> v) {
^^
Compiler bug triggered, please report this error:
exception type: Util::CompilerBug
error: In file: ../../../p4c/frontends/p4/simplifySwitch.cpp:27
Compiler Bug: <stdin>(66): Unexpected comparison X.B; with 1
X.B: { v = v + 20; }
^^^
<stdin>(64)
switch (32w1) {
^^^^
Modified p4c/testdata/p4_16_samples/issue2617.p4
#include <core.p4>
enum bit<32> X {
A = 0,
B = 1
}
enum E {
A, B, C
}
parser p(out bit<32> v) {
state start {
transition select (32w1) {
0: zero;
1: one;
2: two;
}
}
state zero {
v = 0;
transition accept;
}
state one {
v = 1;
transition accept;
}
state two {
v = 2;
transition reject;
}
}
parser p1(out bit<32> v) {
state start {
transition select (X.A, E.A, 32w0) {
(X.A, E.B, _): zero;
(X.A, E.A, 1): one;
(X.A, _, _): two;
}
}
state zero {
v = 0;
transition accept;
}
state one {
v = 1;
transition accept;
}
state two {
v = 2;
transition reject;
}
}
control c(out bit<32> v) {
apply {
switch (32w1) {
0: { v = 0; }
X.B: { v = v + 20; }
}
}
}
parser _p(out bit<32> v);
control _c(out bit<32> v);
package top(_p _p0, _p p1, _c _c0);
top(p(), p1(), c()) main;