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

Tables cannot be compared #3590

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 "" }
^^^^^^