Skip to content

Commit

Permalink
Tables cannot be compared (#3590)
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <[email protected]>
  • Loading branch information
Mihai Budiu authored Oct 21, 2022
1 parent 94cc7eb commit 26732f4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
6 changes: 5 additions & 1 deletion frontends/p4/typeChecking/typeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ const IR::Node* TypeInference::postorder(IR::BoolLiteral* expression) {
return expression;
}

// Returns nullptr on error
// Returns false on error
bool TypeInference::compare(const IR::Node* errorPosition,
const IR::Type* ltype,
const IR::Type* rtype,
Expand All @@ -1737,6 +1737,10 @@ bool TypeInference::compare(const IR::Node* errorPosition,
typeError("%1%: cannot be applied to action results", errorPosition);
return false;
}
if (ltype->is<IR::Type_Table>() || rtype->is<IR::Type_Table>()) {
typeError("%1%: tables cannot be compared", errorPosition);
return false;
}

bool defined = false;
if (typeMap->equivalent(ltype, rtype) &&
Expand Down
24 changes: 24 additions & 0 deletions testdata/p4_16_errors/issue3589.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
action NoAction(){}
control eq0()
{
table t {
actions = {NoAction;}
}
apply {
bool b = t == t; // { dg-error "" }
}
}
control ne0()
{
table t {
actions = {NoAction;}
}
apply {
bool b = t != t; // { dg-error "" }
}
}

control c();

package top(c c1, c c2);
top(eq0(), ne0()) main;
28 changes: 28 additions & 0 deletions testdata/p4_16_errors_outputs/issue3589.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
action NoAction() {
}
control eq0() {
table t {
actions = {
NoAction;
}
}
apply {
bool b = t == t;
}
}

control ne0() {
table t {
actions = {
NoAction;
}
}
apply {
bool b = t != t;
}
}

control c();
package top(c c1, c c2);
top(eq0(), ne0()) main;

6 changes: 6 additions & 0 deletions testdata/p4_16_errors_outputs/issue3589.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
issue3589.p4(8): [--Werror=type-error] error: ==: tables cannot be compared
bool b = t == t; // { dg-error "" }
^^^^^^
issue3589.p4(17): [--Werror=type-error] error: !=: tables cannot be compared
bool b = t != t; // { dg-error "" }
^^^^^^

0 comments on commit 26732f4

Please sign in to comment.