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

Check that verify is only used in parsers. #611

Merged
merged 4 commits into from
May 11, 2017
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 @@ -2527,6 +2527,13 @@ const IR::Node* TypeInference::postorder(IR::MethodCallExpression* expression) {
::error("%1%: tables cannot be invoked from actions", expression);
}

// Check that verify is only invoked from parsers.
if (auto ef = mi->to<ExternFunction>()) {
if (ef->method->name == IR::ParserState::verify)
if (!findContext<IR::P4Parser>())
::error("%1%: may only be invoked in parsers", ef->expr);
}

if (mi->is<ExternMethod>())
checkCorelibMethods(mi->to<ExternMethod>());

Expand Down
9 changes: 9 additions & 0 deletions testdata/p4_16_errors/control-verify.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <core.p4>

error { Oops }

control C() {
apply {
verify(8w0 == 8w1, error.Oops);
}
}
11 changes: 11 additions & 0 deletions testdata/p4_16_errors_outputs/control-verify.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error {
Oops
}
#include <core.p4>

control C() {
apply {
verify(8w0 == 8w1, error.Oops);
}
}

3 changes: 3 additions & 0 deletions testdata/p4_16_errors_outputs/control-verify.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
../testdata/p4_16_errors/control-verify.p4(7): error: verify: may only be invoked in parsers
verify(8w0 == 8w1, error.Oops);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^