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

Cannot compare externs #3834

Merged
merged 1 commit into from
Jan 12, 2023
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
7 changes: 7 additions & 0 deletions frontends/p4/typeChecking/typeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,9 @@ const IR::Node* TypeInference::postorder(IR::Annotation* annotation) {
if (!isCompileTimeConstant(e))
typeError("%1%: structured annotation must be compile-time constant values", e);
auto t = getType(e);
if (!t)
// type error during typechecking
return;
if (!t->is<IR::Type_InfInt>() && !t->is<IR::Type_String>() && !t->is<IR::Type_Boolean>())
typeError("%1%: illegal type for structured annotation; must be int, string or bool",
e);
Expand Down Expand Up @@ -1708,6 +1711,10 @@ bool TypeInference::compare(const IR::Node* errorPosition, const IR::Type* ltype
typeError("%1% and %2%: tables cannot be compared", compare->left, compare->right);
return false;
}
if (ltype->is<IR::Type_Extern>() || rtype->is<IR::Type_Extern>()) {
typeError("%1% and %2%: externs cannot be compared", compare->left, compare->right);
return false;
}

bool defined = false;
if (typeMap->equivalent(ltype, rtype) &&
Expand Down
8 changes: 8 additions & 0 deletions testdata/p4_16_errors/issue3363.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extern e
{
e();
}
e() t;
e() t1;

@myat[t == t1] typedef int b1;
7 changes: 7 additions & 0 deletions testdata/p4_16_errors_outputs/issue3363.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extern e {
e();
}

e() t;
e() t1;
@myat[t == t1] typedef int b1;
6 changes: 6 additions & 0 deletions testdata/p4_16_errors_outputs/issue3363.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
issue3363.p4(8): [--Werror=type-error] error: t and t1: externs cannot be compared
@myat[t == t1] typedef int b1;
^
issue3363.p4(8)
@myat[t == t1] typedef int b1;
^^