diff --git a/frontends/p4/typeChecking/typeChecker.cpp b/frontends/p4/typeChecking/typeChecker.cpp index 292fd842de..7b5eaa0235 100644 --- a/frontends/p4/typeChecking/typeChecker.cpp +++ b/frontends/p4/typeChecking/typeChecker.cpp @@ -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, @@ -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() || rtype->is()) { + typeError("%1%: tables cannot be compared", errorPosition); + return false; + } bool defined = false; if (typeMap->equivalent(ltype, rtype) && diff --git a/testdata/p4_16_errors/issue3589.p4 b/testdata/p4_16_errors/issue3589.p4 new file mode 100644 index 0000000000..660e9921fe --- /dev/null +++ b/testdata/p4_16_errors/issue3589.p4 @@ -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; diff --git a/testdata/p4_16_errors_outputs/issue3589.p4 b/testdata/p4_16_errors_outputs/issue3589.p4 new file mode 100644 index 0000000000..a496c9dd4b --- /dev/null +++ b/testdata/p4_16_errors_outputs/issue3589.p4 @@ -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; + diff --git a/testdata/p4_16_errors_outputs/issue3589.p4-stderr b/testdata/p4_16_errors_outputs/issue3589.p4-stderr new file mode 100644 index 0000000000..4da226eade --- /dev/null +++ b/testdata/p4_16_errors_outputs/issue3589.p4-stderr @@ -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 "" } + ^^^^^^