Skip to content

Commit

Permalink
Report errors for duplicate objects with the same name; fixes #1932 (#…
Browse files Browse the repository at this point in the history
…1934)

* Report errors for duplicate objects with the same name; fixes #1932
* Do not allow two actions with the same name in the same scope
  • Loading branch information
Mihai Budiu authored Jun 21, 2019
1 parent 522fd89 commit 8eb631f
Show file tree
Hide file tree
Showing 46 changed files with 219 additions and 91 deletions.
3 changes: 2 additions & 1 deletion frontends/p4/validateParsedProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ void ValidateParsedProgram::postorder(const IR::P4Program* program) {
cstring name = decl->getName();
auto existing = declarations.getDeclaration(name);
if (existing != nullptr) {
if (!existing->is<IR::IFunctional>() || !decl->is<IR::IFunctional>()) {
if (!existing->is<IR::IFunctional>() || !decl->is<IR::IFunctional>()
|| typeid(*existing) != typeid(*decl) || decl->is<IR::P4Action>()) {
::error(ErrorType::ERR_DUPLICATE, "%1% duplicates %2%.",
decl->getName(), existing->getName());
}
Expand Down
8 changes: 4 additions & 4 deletions testdata/p4_16_errors/issue1580.p4
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ control egress(inout headers_t hdr, inout user_metadata_t meta,
apply { }
}

control verify_checksum(inout headers_t hdr, inout user_metadata_t meta) {
control verifyChecksum(inout headers_t hdr, inout user_metadata_t meta) {
apply { }
}

control compute_checksum(inout headers_t hdr, inout user_metadata_t meta) {
control computeChecksum(inout headers_t hdr, inout user_metadata_t meta) {
apply { }
}

V1Switch(myParser(), verify_checksum(), ingress(), egress(),
compute_checksum(), MyDeparser()) main;
V1Switch(myParser(), verifyChecksum(), ingress(), egress(),
computeChecksum(), MyDeparser()) main;
21 changes: 21 additions & 0 deletions testdata/p4_16_errors/issue1932-1.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <core.p4>
#include <v1model.p4>

header h1_t { bit<8> f1; }
struct headers_t { h1_t h1; }
struct metadata_t { }

control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) {
action foo (in bit<8> x, out bit<8> y) { y = (x >> 2); }
action foo (inout bit<8> x) { x = (x >> 3); }
apply {
foo(hdr.h1.f1);
foo(hdr.h1.f1, hdr.h1.f1);
}
}
parser parserImpl(packet_in packet, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { state start { transition accept; } }
control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { apply { } }
control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { apply { } }
control updateChecksum(inout headers_t hdr, inout metadata_t meta) { apply { } }
control deparserImpl(packet_out packet, in headers_t hdr) { apply { } }
V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main;
22 changes: 22 additions & 0 deletions testdata/p4_16_errors/issue1932-2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <core.p4>
#include <v1model.p4>

header h1_t { bit<8> f1; }
struct headers_t { h1_t h1; }
struct metadata_t { }

action foo (in bit<8> x, out bit<8> y) { y = (x >> 2); }
action foo (inout bit<8> x) { x = (x >> 3); }

control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) {
apply {
foo(hdr.h1.f1);
foo(hdr.h1.f1, hdr.h1.f1);
}
}
parser parserImpl(packet_in packet, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { state start { transition accept; } }
control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { apply { } }
control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { apply { } }
control updateChecksum(inout headers_t hdr, inout metadata_t meta) { apply { } }
control deparserImpl(packet_out packet, in headers_t hdr) { apply { } }
V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main;
2 changes: 2 additions & 0 deletions testdata/p4_16_errors/issue1932.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
control foo (in bit<8> x, out bit<8> y) { apply { y = x + 7; } }
bool foo() { return true; }
6 changes: 3 additions & 3 deletions testdata/p4_16_errors_outputs/issue1580.p4
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ control egress(inout headers_t hdr, inout user_metadata_t meta, inout standard_m
}
}

control verify_checksum(inout headers_t hdr, inout user_metadata_t meta) {
control verifyChecksum(inout headers_t hdr, inout user_metadata_t meta) {
apply {
}
}

control compute_checksum(inout headers_t hdr, inout user_metadata_t meta) {
control computeChecksum(inout headers_t hdr, inout user_metadata_t meta) {
apply {
}
}

V1Switch(myParser(), verify_checksum(), ingress(), egress(), compute_checksum(), MyDeparser()) main;
V1Switch(myParser(), verifyChecksum(), ingress(), egress(), computeChecksum(), MyDeparser()) main;

7 changes: 7 additions & 0 deletions testdata/p4_16_errors_outputs/issue1932-1.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
issue1932-1.p4(10): [--Werror=legacy] error: foo: Duplicates declaration foo
action foo (inout bit<8> x) { x = (x >> 3); }
^^^
issue1932-1.p4(9)
action foo (in bit<8> x, out bit<8> y) { y = (x >> 2); }
^^^
error: 1 errors encountered, aborting compilation
55 changes: 55 additions & 0 deletions testdata/p4_16_errors_outputs/issue1932-2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <core.p4>
#include <v1model.p4>

header h1_t {
bit<8> f1;
}

struct headers_t {
h1_t h1;
}

struct metadata_t {
}

action foo(in bit<8> x, out bit<8> y) {
y = x >> 2;
}
action foo(inout bit<8> x) {
x = x >> 3;
}
control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) {
apply {
foo(hdr.h1.f1);
foo(hdr.h1.f1, hdr.h1.f1);
}
}

parser parserImpl(packet_in packet, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) {
state start {
transition accept;
}
}

control verifyChecksum(inout headers_t hdr, inout metadata_t meta) {
apply {
}
}

control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control updateChecksum(inout headers_t hdr, inout metadata_t meta) {
apply {
}
}

control deparserImpl(packet_out packet, in headers_t hdr) {
apply {
}
}

V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main;

6 changes: 6 additions & 0 deletions testdata/p4_16_errors_outputs/issue1932-2.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
issue1932-2.p4(9): [--Werror=duplicate] error: foo duplicates foo.
action foo (inout bit<8> x) { x = (x >> 3); }
^^^
issue1932-2.p4(8)
action foo (in bit<8> x, out bit<8> y) { y = (x >> 2); }
^^^
9 changes: 9 additions & 0 deletions testdata/p4_16_errors_outputs/issue1932.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
control foo(in bit<8> x, out bit<8> y) {
apply {
y = x + 7;
}
}

bool foo() {
return true;
}
6 changes: 6 additions & 0 deletions testdata/p4_16_errors_outputs/issue1932.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
issue1932.p4(2): [--Werror=duplicate] error: foo duplicates foo.
bool foo() { return true; }
^^^
issue1932.p4(1)
control foo (in bit<8> x, out bit<8> y) { apply { y = x + 7; } }
^^^
4 changes: 2 additions & 2 deletions testdata/p4_16_samples/issue1642-bmv2.p4
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ control deparser(packet_out b, in parsed_packet_t hdr) {
apply { }
}

control verify_checksum(inout parsed_packet_t hdr,
control verifyChecksum(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata) {
apply { }
}
Expand All @@ -62,5 +62,5 @@ control compute_checksum(inout parsed_packet_t hdr,
apply { }
}

V1Switch(parse(), verify_checksum(), ingress(), egress(),
V1Switch(parse(), verifyChecksum(), ingress(), egress(),
compute_checksum(), deparser()) main;
4 changes: 2 additions & 2 deletions testdata/p4_16_samples/issue1653-bmv2.p4
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ control deparser(packet_out b, in parsed_packet_t h) {
apply { }
}

control verify_checksum(inout parsed_packet_t hdr,
control verifyChecksum(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata) {
apply { }
}
Expand All @@ -69,5 +69,5 @@ control compute_checksum(inout parsed_packet_t hdr,
apply { }
}

V1Switch(parse(), verify_checksum(), ingress(), egress(),
V1Switch(parse(), verifyChecksum(), ingress(), egress(),
compute_checksum(), deparser()) main;
19 changes: 9 additions & 10 deletions testdata/p4_16_samples/issue1653-complex-bmv2.p4
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct alt_t {
int<8> hashRes;
bool useHash;
EthTypes type;
bit<7> pad;
bit<7> pad;
};

struct row_t {
Expand All @@ -52,7 +52,7 @@ struct local_metadata_t {

struct parsed_packet_t {
bitvec_hdr bvh0;
bitvec_hdr bvh1;
bitvec_hdr bvh1;
};

parser parse(packet_in pk, out parsed_packet_t h,
Expand All @@ -72,9 +72,9 @@ control ingress(inout parsed_packet_t h,

action do_act() {
h.bvh1.row.alt1.valid = 0;
local_metadata.row0.alt0.valid = 0;
local_metadata.row0.alt0.valid = 0;
}

table tns {
key = {
h.bvh1.row.alt1.valid : exact;
Expand All @@ -84,15 +84,15 @@ control ingress(inout parsed_packet_t h,
do_act;
}
}

apply {

tns.apply();

// Copy another header's data to local variable.
bh.row.alt0.useHash = h.bvh0.row.alt0.useHash;
bh.row.alt1.type = EthTypes.IPv4;
h.bvh0.row.alt1.type = bh.row.alt1.type;
h.bvh0.row.alt1.type = bh.row.alt1.type;

local_metadata.row0.alt0.useHash = true;
clone3(CloneType.I2E, 0, local_metadata.row0);
Expand All @@ -108,11 +108,11 @@ control egress(inout parsed_packet_t hdr,
control deparser(packet_out b, in parsed_packet_t h) {
apply {
b.emit(h.bvh0);
b.emit(h.bvh1);
b.emit(h.bvh1);
}
}

control verify_checksum(inout parsed_packet_t hdr,
control verifyChecksum(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata) {
apply { }
}
Expand All @@ -122,6 +122,5 @@ control compute_checksum(inout parsed_packet_t hdr,
apply { }
}

V1Switch(parse(), verify_checksum(), ingress(), egress(),
V1Switch(parse(), verifyChecksum(), ingress(), egress(),
compute_checksum(), deparser()) main;

4 changes: 2 additions & 2 deletions testdata/p4_16_samples/issue1660-bmv2.p4
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ control deparser(packet_out b, in parsed_packet_t h) {
apply { }
}

control verify_checksum(inout parsed_packet_t hdr,
control verifyChecksum(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata) {
apply { }
}
Expand All @@ -42,5 +42,5 @@ control compute_checksum(inout parsed_packet_t hdr,
apply { }
}

V1Switch(parse(), verify_checksum(), ingress(), egress(),
V1Switch(parse(), verifyChecksum(), ingress(), egress(),
compute_checksum(), deparser()) main;
4 changes: 2 additions & 2 deletions testdata/p4_16_samples/issue1670-bmv2.p4
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ control deparser(packet_out b, in parsed_packet_t h) {
apply { }
}

control verify_checksum(inout parsed_packet_t hdr,
control verifyChecksum(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata) {
apply { }
}
Expand All @@ -50,5 +50,5 @@ control compute_checksum(inout parsed_packet_t hdr,
apply { }
}

V1Switch(parse(), verify_checksum(), ingress(), egress(),
V1Switch(parse(), verifyChecksum(), ingress(), egress(),
compute_checksum(), deparser()) main;
14 changes: 7 additions & 7 deletions testdata/p4_16_samples/issue383-bmv2.p4
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ struct local_metadata_t {

struct parsed_packet_t {
bitvec_hdr bvh0;
bitvec_hdr bvh1;
bitvec_hdr bvh1;
};

struct tst_t {
row_t row0;
row_t row1;
col_t col;
col_t col;
bitvec_hdr bvh0;
bitvec_hdr bvh1;
}
Expand All @@ -76,9 +76,9 @@ control ingress(inout parsed_packet_t h,

action do_act() {
h.bvh1.row.alt1.valid = 0;
local_metadata.col.bvh.row.alt0.valid = 0;
local_metadata.col.bvh.row.alt0.valid = 0;
}

table tns {
key = {
h.bvh1.row.alt1.valid : exact;
Expand All @@ -88,7 +88,7 @@ control ingress(inout parsed_packet_t h,
do_act;
}
}

apply {

tns.apply();
Expand Down Expand Up @@ -128,7 +128,7 @@ control deparser(packet_out b, in parsed_packet_t h) {
}
}

control verify_checksum(inout parsed_packet_t hdr,
control verifyChecksum(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata) {
apply { }
}
Expand All @@ -138,5 +138,5 @@ control compute_checksum(inout parsed_packet_t hdr,
apply { }
}

V1Switch(parse(), verify_checksum(), ingress(), egress(),
V1Switch(parse(), verifyChecksum(), ingress(), egress(),
compute_checksum(), deparser()) main;
4 changes: 2 additions & 2 deletions testdata/p4_16_samples/issue562-bmv2.p4
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ control deparser(packet_out b, in parsed_packet_t hdr) {
apply { }
}

control verify_checksum(inout parsed_packet_t hdr,
control verifyChecksum(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata) {
apply { }
}
Expand All @@ -55,5 +55,5 @@ control compute_checksum(inout parsed_packet_t hdr,
apply { }
}

V1Switch(parse(), verify_checksum(), ingress(), egress(),
V1Switch(parse(), verifyChecksum(), ingress(), egress(),
compute_checksum(), deparser()) main;
Loading

0 comments on commit 8eb631f

Please sign in to comment.