p4lang / p4c

P4_16 reference compiler
https://p4.org/
Apache License 2.0
671 stars 442 forks source link

what(): COMPILER BUG: ../frontends/p4/typeChecking/typeChecker.h:100 #453

Closed rmiguelc closed 7 years ago

rmiguelc commented 7 years ago

I previously mentioned this on a P4-dev-lists topic: http://lists.p4.org/pipermail/p4-dev_lists.p4.org/2017-March/000858.html

Mihai Budiu disclosed that this was intentional, here. As it turns out, the problem with my code was not the .hit attribute, but tables having parameters. This has been removed from the language and the compiler has already been changed accordingly, but is still printing the bug in epigraph.

Here is the complete P4 code I used on the sandbox test.

#include "./p4include/v1model.p4"

struct Meta {
    bit<1> hasmeta;
}

struct Parsed_packet {
    bit<8> field;
}

parser TopParser(packet_in b, out Parsed_packet p, inout Meta m, inout standard_metadata_t metadata) {
    state start {
        transition accept;
    }
}
control VeryChecksum(in Parsed_packet hdr, inout Meta meta) { apply {} }

control IngressP(inout Parsed_packet hdr,
                      inout Meta meta,
                      inout standard_metadata_t standard_metadata) {

 action Update_face_list(out bit<32> portArray, bit<32> currentVector)
 { portArray = currentVector; }

 table testtable(inout bit<32> portArray) {
        key = { hdr.field : exact; } //hdr.field is bit<8>
        actions = { Update_face_list(portArray); NoAction; }
        default_action = NoAction;
 }

 apply {
        bit<32> var = 0;
        bool match = false;

        match = testtable.apply(var).hit;

        if (match) {
         var = 5;
        }
 }
}

control EgressP(inout Parsed_packet hdr,
                     inout Meta meta,
                     inout standard_metadata_t standard_metadata) { apply {} }

control ChecksumComputer(inout Parsed_packet hdr,
                              inout Meta meta) { apply {} }

control TopDeparser(packet_out b, in Parsed_packet hdr) { apply {} }

V1Switch(TopParser(), VeryChecksum(), IngressP(), EgressP(), ChecksumComputer(), TopDeparser()) main;

Compiling with ./p4test --p4v 16 or ./p4c-bm2-ss --p4v 16 yields the following:

simple_switch.p4(78): error: testtable.apply: Passing 1 arguments when 0 expected match = testtable.apply(var).hit; ------- ^^^^^^^^^^^^^^^^^^^^ terminate called after throwing an instance of 'Util::CompilerBug' what(): COMPILER BUG: ../frontends/p4/typeChecking/typeChecker.h:100 simple_switch.p4(78): Could not find type of testtable.apply(var); match = testtable.apply(var).hit; ------- ^^^^^^^^^^^^^^^^^^^^

(p4c-bm-ss also outputs a Segmentation Fault)

mihaibudiu commented 7 years ago

I cannot reproduce this issue with the latest version of the compiler. The error I get is:

issue453.p4(25):syntax error, unexpected '(', expecting '{'
 table testtable(
                ^
error: 1 errors encountered, aborting compilation

So this program does not even parse.