Skip to content

Commit

Permalink
Add empty block for trailing case(s) with no code. (#4889)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
  • Loading branch information
ChrisDodd authored Sep 3, 2024
1 parent c069b4c commit acef8db
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion frontends/p4/simplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ const IR::Node *DoSimplifyControlFlow::postorder(IR::SwitchStatement *statement)
else
warn(ErrorType::WARN_MISSING, "%1%: fallthrough with no statement", last);
}
statement->cases.erase(it.base(), statement->cases.end());
auto mod = last->clone();
mod->statement = new IR::BlockStatement;
statement->cases.back() = mod;
}
return statement;
}
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_16_samples_outputs/cases-first.p4
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ control ctrl() {
b: {
return;
}
default: {
c: {
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions testdata/p4_16_samples_outputs/issue2617-first.p4
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ control c(out bit<32> v) {
32w1: {
v = 32w1;
}
32w2: {
}
}
switch (E.C) {
E.A: {
Expand Down
4 changes: 4 additions & 0 deletions testdata/p4_16_samples_outputs/issue3619-first.p4
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
control c(in bit<4> v) {
apply {
switch (v) {
default: {
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ control MyIC(inout headers_t hdr, inout user_meta_t b, in psa_ingress_input_meta
16w64: {
tmp = 16w2;
}
16w92: {
}
}
switch (tbl.apply().action_run) {
a1: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ control MyIC(inout headers_t hdr, inout user_meta_t b, in psa_ingress_input_meta
16w64: {
tmp_0 = 16w2;
}
16w92: {
}
}
switch (tbl_0.apply().action_run) {
a1: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ control MyIC(inout headers_t hdr, inout user_meta_t b, in psa_ingress_input_meta
}
@hidden action switch_0_case_1() {
}
@hidden action switch_0_case_2() {
}
@hidden table switch_0_table {
key = {
switch_0_key: exact;
Expand All @@ -132,12 +134,14 @@ control MyIC(inout headers_t hdr, inout user_meta_t b, in psa_ingress_input_meta
switch_0_case();
switch_0_case_0();
switch_0_case_1();
switch_0_case_2();
}
const default_action = switch_0_case_1();
const default_action = switch_0_case_2();
const entries = {
const 16w16 : switch_0_case();
const 16w32 : switch_0_case();
const 16w64 : switch_0_case_0();
const 16w92 : switch_0_case_1();
}
}
@hidden action psaswitchexpressionwithoutdefault124() {
Expand Down Expand Up @@ -188,6 +192,8 @@ control MyIC(inout headers_t hdr, inout user_meta_t b, in psa_ingress_input_meta
}
switch_0_case_1: {
}
switch_0_case_2: {
}
}
switch (tbl_0.apply().action_run) {
a1: {
Expand Down

0 comments on commit acef8db

Please sign in to comment.