p4c icon indicating copy to clipboard operation
p4c copied to clipboard

Def-Use and exit statements

Open fruffy opened this issue 4 years ago • 5 comments

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.

nested_exit_out_param.p4.txt nested_exit_out_param.stf.txt

fruffy avatar May 14 '20 10:05 fruffy

I have labeled this as a duplicate, probably the same fix should address this one - once we have it.

mihaibudiu avatar May 14 '20 20:05 mihaibudiu

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);
    }
}

hesingh avatar May 28 '20 19:05 hesingh

the exit statement should be eliminated before reaching this point.

mihaibudiu avatar May 28 '20 20:05 mihaibudiu

@fruffy Do you know if this bug was fixed by later commits?

jafingerhut avatar Nov 24 '22 15:11 jafingerhut

This bug is still not fixed.

fruffy avatar Nov 24 '22 15:11 fruffy