p4c
p4c copied to clipboard
default_action checking arguments against the action one is not strong enough
Take:
action a(in bit v, in bit v1){}
bit f(inout bit v)
{
v = ~v;
return v;
}
control c()
{
bit tt;
table t
{
actions = { a(v1 = f(tt), v = f(tt)); }
default_action = a(v = f(tt), v1 = f(tt));
}
apply {}
}
Yes the order of the two variables have been swapped on purpose as the order of execution is left to right. The above will have different side effects and the arguments to the action will not be correct. Note the spec says:
Arguments are evaluated from left to right as they appear in the function call expression.
Which I assumed means as written in the code for the call and not reorded because of the argument order of the action's argument. Or is there an area of the spec which needs to be improved such that the order is the order of the arguments of the action/function/extern?
It just looks like the checking is not checking the order here rather than an issue with the spec or otherwise. Take:
extern void log(in bit a);
bit a(in bit v, in bit v1)
{
return v == 1 ? v1 : v;
}
bit f(inout bit v)
{
v = ~v;
return v;
}
bit f1(inout bit v)
{
// v = ~v;
return v;
}
bit g(inout bit v)
{
return a(f(v), f1(v));
}
bit g1(inout bit v)
{
return a(v1 = f1(v), v = f(v));
}
control c() {
apply {
bit v = 1;
bit v1 = g(v);
log(v1);
}
}
control c1() {
apply {
bit v = 1;
bit v1 = g1(v);
log(v1);
}
}
control ct();
package pt(ct c0, ct c1);
pt(c(), c1()) main;
The order p4c does for g and g1 is definitely different. (not the best testcase but it shows there could be a difference between the orders).
How are you testing this to decide that the result is incorrect?
Anyways here is another testcase:
extern bit ext();
control c()
{
bit<2> tt;
action a(in bit v1, in bit v2) { tt = v1++v2; }
table t
{
actions = { a(v1 = ext(), v2 = ext()); }
default_action = a(v2 = ext(), v1 = ext());
}
apply {}
}
the order of execution of which argument is done first makes a difference, especially with externs.
But what is the error you are observing?