p4c
p4c copied to clipboard
Result of extern function call used in switch expression is incorrectly marked as a compile-time constant
Compiling
#include <core.p4>
extern void foo();
extern void bar();
extern bit<8> baz();
action a(){}
action b(){}
control c() {
table t {
actions = { a ; b; }
}
apply {
switch(baz()) {
1 : { foo(); }
4 : { bar(); }
}
t.apply();
}
}
control C();
package top(C c);
top(c()) main;
results in the following warning:
t.p4(13): [--Wwarn=mismatch] warning: baz(): constant expression in switch
switch(baz()) {
^^^^^
I'm not sure if the warning is the only observable problem. Classifying the result of the extern function call as a compile-time constant could have a less benign effect somewhere else.