Skip to content

Commit

Permalink
Validate value_set element types (p4lang#3351)
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <[email protected]>
  • Loading branch information
Mihai Budiu authored and github-sajan committed May 26, 2022
1 parent b757ea9 commit 2cc379c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions frontends/p4/typeChecking/typeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,15 @@ const IR::Node* TypeInference::postorder(IR::P4ValueSet* decl) {
if (errs)
return nullptr;
}
if (!canon->is<IR::Type_Newtype>() &&
!canon->is<IR::Type_Bits>() &&
!canon->is<IR::Type_SerEnum>() &&
!canon->is<IR::Type_Boolean>() &&
!canon->is<IR::Type_Enum>() &&
!canon->is<IR::Type_Struct>() &&
!canon->is<IR::Type_Tuple>())
typeError("%1%: Illegal type for value_set element type", decl->elementType);

auto tt = new IR::Type_Set(canon);
setType(getOriginal(), tt);
setType(decl, tt);
Expand Down
9 changes: 9 additions & 0 deletions testdata/p4_16_errors/issue3346.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parser MyParser1(in bit<6> v) {
value_set<int>(4) myvs;
state start {
transition select(v) {
myvs: accept;
_: reject;
}
}
}
10 changes: 10 additions & 0 deletions testdata/p4_16_errors_outputs/issue3346.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parser MyParser1(in bit<6> v) {
value_set<int>(4) myvs;
state start {
transition select(v) {
myvs: accept;
default: reject;
}
}
}

3 changes: 3 additions & 0 deletions testdata/p4_16_errors_outputs/issue3346.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
issue3346.p4(2): [--Werror=type-error] error: int: Illegal type for value_set element type
value_set<int>(4) myvs;
^^^

0 comments on commit 2cc379c

Please sign in to comment.