Skip to content

Commit 7247c11

Browse files
authored
Improved check of entries in key-less tables (#5310)
Signed-off-by: Denis Matousek <[email protected]>
1 parent 264178b commit 7247c11

File tree

11 files changed

+165
-1
lines changed

11 files changed

+165
-1
lines changed

frontends/p4/entryPriorities.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ const IR::Node *EntryPriorities::preorder(IR::EntriesList *entries) {
7070
// check to see if priorities are required or allowed
7171
bool requiresPriorities = false;
7272
auto key = table->getKey();
73+
if (!key || key->keyElements.empty()) {
74+
return entries;
75+
}
7376
for (auto element : key->keyElements) {
7477
if (requiresPriority(element)) {
7578
requiresPriorities = true;

midend/checkTableEntries.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ bool P4::CheckTableEntries::ternary_covers(const IR::Expression *k1, const IR::E
5959

6060
bool P4::CheckTableEntries::preorder(const IR::P4Table *tbl) {
6161
auto *entries = tbl->getEntries();
62-
if (!entries) return false;
62+
if (!entries || entries->entries.empty()) return false;
6363
auto *key = tbl->getKey();
6464
BUG_CHECK(key, "%1% table has entries and no key", tbl);
6565
std::vector<bool> ternary_keys;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2025 Altera Corporation
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
control c() {
17+
action a() {}
18+
table t {
19+
actions = { a; }
20+
default_action = a;
21+
entries = { _ : a; }
22+
}
23+
apply {
24+
t.apply();
25+
}
26+
}
27+
28+
control cc();
29+
package top(cc p);
30+
31+
top(c()) main;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
control c() {
2+
action a() {
3+
}
4+
table t {
5+
actions = {
6+
a;
7+
}
8+
default_action = a;
9+
entries = {
10+
default : a;
11+
}
12+
}
13+
apply {
14+
t.apply();
15+
}
16+
}
17+
18+
control cc();
19+
package top(cc p);
20+
top(c()) main;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
entries-keyless.p4(18): [--Werror=type-error] error: Entries cannot be specified for a table with no key t
2+
table t {
3+
^
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2025 Altera Corporation
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
control c() {
17+
action a() {}
18+
table t {
19+
actions = { a; }
20+
default_action = a;
21+
entries = {}
22+
}
23+
apply {
24+
t.apply();
25+
}
26+
}
27+
28+
control cc();
29+
package top(cc p);
30+
31+
top(c()) main;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
control c() {
2+
action a() {
3+
}
4+
table t {
5+
actions = {
6+
a();
7+
}
8+
default_action = a();
9+
entries = {
10+
}
11+
}
12+
apply {
13+
t.apply();
14+
}
15+
}
16+
17+
control cc();
18+
package top(cc p);
19+
top(c()) main;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
control c() {
2+
@name("c.a") action a() {
3+
}
4+
@name("c.t") table t_0 {
5+
actions = {
6+
a();
7+
}
8+
default_action = a();
9+
entries = {
10+
}
11+
}
12+
apply {
13+
t_0.apply();
14+
}
15+
}
16+
17+
control cc();
18+
package top(cc p);
19+
top(c()) main;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
control c() {
2+
@name("c.a") action a() {
3+
}
4+
@name("c.t") table t_0 {
5+
actions = {
6+
a();
7+
}
8+
default_action = a();
9+
entries = {
10+
}
11+
}
12+
apply {
13+
t_0.apply();
14+
}
15+
}
16+
17+
control cc();
18+
package top(cc p);
19+
top(c()) main;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
control c() {
2+
action a() {
3+
}
4+
table t {
5+
actions = {
6+
a;
7+
}
8+
default_action = a;
9+
entries = {
10+
}
11+
}
12+
apply {
13+
t.apply();
14+
}
15+
}
16+
17+
control cc();
18+
package top(cc p);
19+
top(c()) main;

0 commit comments

Comments
 (0)