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

Compiler bug in constant folding #401

Closed
jnfoster opened this issue Mar 27, 2017 · 0 comments
Closed

Compiler bug in constant folding #401

jnfoster opened this issue Mar 27, 2017 · 0 comments

Comments

@jnfoster
Copy link
Contributor

Program:

#include <v1model.p4>

header h_t {
  bit<8> f;
}

struct my_packet {
  h_t h;
}

struct my_metadata {

}

parser MyParser(packet_in b, out my_packet p, inout my_metadata m, inout standard_metadata_t s) {
  state start {
    transition accept;
  }
}

control MyVerifyChecksum(in my_packet hdr, inout my_metadata meta) {
  apply { }
}

control MyIngress(inout my_packet p, inout my_metadata m, inout standard_metadata_t s) {
  apply { 
    bit<1> b = (bit<1>) { 0 };
  }
}

control MyEgress(inout my_packet p, inout my_metadata m, inout standard_metadata_t s) {
  apply { }
}

control MyComputeChecksum(inout my_packet p, inout my_metadata m) {
  apply { }
}

control MyDeparser(packet_out b, in my_packet p) {
  apply { }
}

/* Instantiate */
MyParser() p;
MyVerifyChecksum() vck;
MyIngress() i;
MyEgress() e;
MyComputeChecksum() cck;
MyDeparser() dp;

V1Switch(p, vck, i, e, cck, dp) main;

Error:

terminate called after throwing an instance of 'Util::CompilerBug'
  what():  COMPILER BUG: ../frontends/common/constantFolding.cpp:631
/home/vagrant/min.p4(27): {0};: expected a boolean literal
    bit<1> b = (bit<1>) { 0 };
                        ^^^^^

Aborted (core dumped)
jnfoster added a commit that referenced this issue Mar 28, 2017
The case for IR::Cast had a bug where it assumed that a constant was either a boolean or numeric literal. This pull request adds an extra case to handle list literals as well as a test case (`issue401.p4`). Fixes #401.
hanw pushed a commit to hanw/p4c that referenced this issue Apr 4, 2017
The case for IR::Cast had a bug where it assumed that a constant was either a boolean or numeric literal. This pull request adds an extra case to handle list literals as well as a test case (`issue401.p4`). Fixes p4lang#401.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant