Skip to content

Casted multiplication inside action incorrectly triggers "could not evaluate at compilation time" error #5340

Open
@zhh2001

Description

@zhh2001

Hi,

The following P4 code causes a compilation error, even though it's inside an action block and should be evaluated at runtime:

    action flow_control(
        ID_t                     id,
        threshold_t              threshold,
        factor_t       factor
    ) {
            threshold_t base_threshold;
            base_threshold = threshold * ((threshold_t) factor);
        }
    }

Compilation error:

/home/p4/P4Sentinel/p4src/ingress.p4(110): [--Werror=invalid] error: threshold * (bit<64>)factor: could not evaluate expression at compilation time

However, if the cast is removed or the expression is split into two lines (i.e., casting to a temp variable), the compiler accepts it. This suggests a possible issue in constant folding or expression analysis during parsing.

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionThis is a topic requesting clarification.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions