p4c
p4c copied to clipboard
Def-Use and exit statements
Another case, where exit statements combined with out parameters are not correctly handled in respect to the recent spec changes:
After FrontEnd_32_SimplifyDefUse
, the following program:
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("exit_action") action exit_action_0() {
exit;
}
@name("assignment_action") action assignment_action_0(out bit<16> val) {
val = 16w0xbeef;
}
@name("simple_action") action simple_action_0(inout bit<16> val) {
val = 16w0xdead;
exit_action_0();
assignment_action_0(val);
}
apply {
simple_action_0(h.eth_hdr.eth_type);
}
}
is transformed into:
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("exit_action") action exit_action_0() {
exit;
}
@name("assignment_action") action assignment_action_0(out bit<16> val) {
val = 16w0xbeef;
}
@name("simple_action") action simple_action_0(inout bit<16> val) {
;
exit_action_0();
assignment_action_0(val);
}
apply {
simple_action_0(h.eth_hdr.eth_type);
}
}
This disregards the exit call in exit_action_0
.
I have labeled this as a duplicate, probably the same fix should address this one - once we have it.
What should be expected output after FrontEnd_32_SimplifyDefUse
pass with a fix? Is the following output fine because the assignment_action
has its statements removed and thus even if this action is called later to exit_action_0
, the call is a null op.
Or the fix can remove actions altogether. Right now the FrontEnd_32_SimplifyDefUse
does not support removal of any action.
Which choice is preferred?
I generated the following output having hacked p4c FrontEnd_32_SimplifyDefUse
pass.
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("exit_action") action exit_action_0() {
exit;
}
@name("assignment_action") action assignment_action_0(out bit<16> val) {
;
}
@name("simple_action") action simple_action_0(inout bit<16> val) {
;
exit_action_0();
assignment_action_0(val);
}
apply {
simple_action_0(h.eth_hdr.eth_type);
}
}
the exit statement should be eliminated before reaching this point.
@fruffy Do you know if this bug was fixed by later commits?
This bug is still not fixed.