Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MoveInitializers and parser loops #2314

Closed
fruffy opened this issue Apr 14, 2020 · 0 comments · Fixed by #2319
Closed

MoveInitializers and parser loops #2314

fruffy opened this issue Apr 14, 2020 · 0 comments · Fixed by #2319
Assignees
Labels
bug This behavior is unintended and should be fixed. fixed This topic is considered to be fixed.

Comments

@fruffy
Copy link
Collaborator

fruffy commented Apr 14, 2020

There seems to be a problem in the way the compiler moves initializers in the parser. I stripped issue281.p4 to the essentials (attached). After MoveInitializers

parser L3(packet_in b, inout h hdr) {
    bit<16> etherType_0 = hdr.ether.etherType;
    state start {
        transition select(etherType_0) {
            16w0x800: h;
            16w0x8100: i;
            default: accept;
        }
    }
    state h {
        b.extract<H>(hdr.h);
        transition accept;
    }
    state i {
        b.extract<I>(hdr.i);
        etherType_0 = hdr.i.etherType;
        transition start;
    }
}

parser MyParser(packet_in b, out h hdr, inout m meta, inout standard_metadata_t std) {
    @name("l3") L3() l3_0;
    state start {
        b.extract<ethernet_t>(hdr.ether);
        l3_0.apply(b, hdr);
        transition accept;
    }
}

turns into

parser L3(packet_in b, inout h hdr) {
    bit<16> etherType_0;
    state start {
        etherType_0 = hdr.ether.etherType;
        transition select(etherType_0) {
            16w0x800: h;
            16w0x8100: i;
            default: accept;
        }
    }
    state h {
        b.extract<H>(hdr.h);
        transition accept;
    }
    state i {
        b.extract<I>(hdr.i);
        etherType_0 = hdr.i.etherType;
        transition start;
    }
}

parser MyParser(packet_in b, out h hdr, inout m meta, inout standard_metadata_t std) {
    @name("l3") L3() l3_0;
    state start {
        b.extract<ethernet_t>(hdr.ether);
        l3_0.apply(b, hdr);
        transition accept;
    }
}

There is a problem with moving etherType_0 = hdr.ether.etherType; into start.
In state i etherType_0 is assigned the value hdr.i.etherType. This is essentially ignored once the parser transitions back to state start because etherType_0 = hdr.ether.etherType; has been moved there.

I unfortunately do not have a stf test for this yet.

issue281_stripped.p4.txt

@mihaibudiu mihaibudiu added the bug This behavior is unintended and should be fixed. label Apr 15, 2020
@mihaibudiu mihaibudiu self-assigned this Apr 15, 2020
@mihaibudiu mihaibudiu added the fixed This topic is considered to be fixed. label Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This behavior is unintended and should be fixed. fixed This topic is considered to be fixed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants