Skip to content

Fails to reject invalid bitslice range, on constants #5302

Open
@jaehyun1ee

Description

@jaehyun1ee

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    p4-specTopics related to the P4 specification (https://github.com/p4lang/p4-spec/).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions