p4c icon indicating copy to clipboard operation
p4c copied to clipboard

Crash when `const bit` type initialized with an `enum` value is used in an expression

Open kfcripps opened this issue 1 year ago • 0 comments

#include <core.p4>

enum bit<2> e
{
  e0 = 0,
  e1 = 1,
  e2 = 2,
  e3 = 3
}

const bit<2> c = e.e0;

extern void foo(inout bit<2> a);

control ingress() {
    apply {
        bit<2> x = c + 2;
        foo(x);
    }
}

control Ingress();
package top(Ingress ig);
top(ingress()) main;

results in:

Compiler Bug: tmp.p4(19): At this point in the compilation typechecking should not infer new types anymore, but it did: node e.e0 + 2; changed to (bit<2>)e.e0 + 2;
        bit<2> x = c + 2;
                   ^^^^^
tmp.p4(19)
        bit<2> x = c + 2;
                   ^^^^^

kfcripps avatar Jun 14 '24 04:06 kfcripps