Skip to content

Fix #5042: Allow non-constant args for directionless action params in tables#5465

Open
devalgupta404 wants to merge 2 commits intop4lang:mainfrom
devalgupta404:issue-5042
Open

Fix #5042: Allow non-constant args for directionless action params in tables#5465
devalgupta404 wants to merge 2 commits intop4lang:mainfrom
devalgupta404:issue-5042

Conversation

@devalgupta404
Copy link

Summary

Fixes #5042

Per P4 Spec Section 6.8, directionless action parameters should behave as in when values are provided by the P4 program, and need not be compile-time known values.

The Problem

The compiler incorrectly rejected valid P4 code:

action a(bit<8> data) { hdr.h.f = data; }                                                                                                                                      
table t {                                                                                                                                                                      
    actions = { a; }                                                                                                                                                           
    default_action = a(meta.x);  // ERROR: action argument must be a compile-time constant                                                                                     
}                                                                                                                                                                              

The Fix

Removed the incorrect compile-time constant check for directionless parameters in actionCall() when used in table default_action or entries.

File: frontends/p4/typeChecking/typeCheckExpr.cpp:1895-1898

Testing

Before fix:
$ ./build/p4test testdata/p4_16_samples/issue5042.p4
error: meta.x: action argument must be a compile-time constant

After fix:
$ ./build/p4test testdata/p4_16_samples/issue5042.p4
$ echo $?
0

Regression test:
$ ctest -R "p4_16_samples" -j4
96% tests passed, 1529 of 1598
All 1301 p4 label tests passed. The 69 failures are pre-existing ebpf/ubpf backend issues unrelated to this change.

@fruffy fruffy added core Topics concerning the core segments of the compiler (frontend, midend, parser) p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/). labels Jan 21, 2026
Signed-off-by: devalgupta404 <devalgupta4@gmail.com>
Signed-off-by: devalgupta404 <devalgupta4@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Topics concerning the core segments of the compiler (frontend, midend, parser) p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Directionless action arguments provided by the P4 program should behave like in

2 participants