Open
Description
In P4, bitslice of [H:L]
should (statically) satisfy the condition : 0 <= L <= H < W
where W
is the length of the source bitstring. P4C rejects their violations, as in the program slice_out_of_bound.p4
in p4_16_errors
.
However, it seems like the constant folding pass happens prior type checking, thereby programs containing invalid bitslice gets past the type checker. For example:
const bool tmp = ((1) != (4w2[7:0]));
extern void sink(in bool b);
control C();
package P(C c);
control CImpl() { apply { g(tmp); } }
P(CImpl()) main;
is not rejected by p4test
. Inspecting the intermediate passes with --top4
option, at -0010-ConstantFolding_0_DoConstantFolding
pass, the ill-typed bitslice is (erroneously) evaluated to:
const bool tmp = true;