Skip to content
Closed
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
4,827 changes: 2,422 additions & 2,405 deletions frontends/p4/typeChecking/typeCheckExpr.cpp

Large diffs are not rendered by default.

1,923 changes: 973 additions & 950 deletions frontends/p4/typeChecking/typeChecker.cpp

Large diffs are not rendered by default.

1,322 changes: 663 additions & 659 deletions frontends/p4/typeChecking/typeChecker.h

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions testdata/p4_16_samples/issue5653.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* SPDX-FileCopyrightText: 2026
*
* SPDX-License-Identifier: Apache-2.0
*
* Regression test for issue #5653: comparison with {#} literal fails to compile.
*/

#include <core.p4>

header h_t { bit<8> f; }
header h2_t { bit<16> g; }
header_union hu_t { h_t a; h2_t b; }

struct meta_t {
h_t h;
bit<8> f;
}

struct nested_t {
meta_t m;
}

control C(inout meta_t meta, inout nested_t nested, inout hu_t hu) {
action a() {
if (meta.h == {#})
meta.f = 1;
if (meta.h != {#})
meta.f = 2;
meta.h = {#};
if (!meta.h.isValid())
meta.f = 3;
h_t hcast = (h_t){#};
if (hcast == (h_t){#}) {}
if (hu == {#}) {}
if (hu != {#}) {}
hu = {#};
if (nested.m.h == {#})
nested.m.f = 4;
}

table t {
actions = { a; }
default_action = a;
}

apply {
t.apply();
}
}

parser P(inout meta_t meta, inout nested_t nested, inout hu_t hu) {
state start {
meta.h = {#};
if (meta.h == {#}) {
meta.h.setInvalid();
}
transition accept;
}
}

control proto(inout meta_t meta, inout nested_t nested, inout hu_t hu);
parser par(inout meta_t meta, inout nested_t nested, inout hu_t hu);
package top(par p, proto c);

top(P(), C()) main;
76 changes: 76 additions & 0 deletions testdata/p4_16_samples_outputs/issue5653-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <core.p4>

header h_t {
bit<8> f;
}

header h2_t {
bit<16> g;
}

header_union hu_t {
h_t a;
h2_t b;
}

struct meta_t {
h_t h;
bit<8> f;
}

struct nested_t {
meta_t m;
}

control C(inout meta_t meta, inout nested_t nested, inout hu_t hu) {
@name("a") action a_0() {
if (meta.h == (h_t){#}) {
meta.f = 8w1;
}
if (meta.h != (h_t){#}) {
meta.f = 8w2;
}
meta.h = (h_t){#};
if (meta.h.isValid()) {
;
} else {
meta.f = 8w3;
}
@name("hcast") h_t hcast_0 = (h_t){#};
hu = (hu_t){#};
if (nested.m.h == (h_t){#}) {
nested.m.f = 8w4;
}
}
@name("t") table t_0 {
actions = {
a_0();
}
default_action = a_0();
}
apply {
t_0.apply();
}
}

parser P(inout meta_t meta, inout nested_t nested, inout hu_t hu) {
state start {
meta.h = (h_t){#};
transition select(meta.h == (h_t){#}) {
true: start_true;
false: start_join;
}
}
state start_true {
meta.h.setInvalid();
transition start_join;
}
state start_join {
transition accept;
}
}

control proto(inout meta_t meta, inout nested_t nested, inout hu_t hu);
parser par(inout meta_t meta, inout nested_t nested, inout hu_t hu);
package top(par p, proto c);
top(P(), C()) main;
75 changes: 75 additions & 0 deletions testdata/p4_16_samples_outputs/issue5653-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <core.p4>

header h_t {
bit<8> f;
}

header h2_t {
bit<16> g;
}

header_union hu_t {
h_t a;
h2_t b;
}

struct meta_t {
h_t h;
bit<8> f;
}

struct nested_t {
meta_t m;
}

control C(inout meta_t meta, inout nested_t nested, inout hu_t hu) {
@name("C.a") action a_0() {
if (meta.h == (h_t){#}) {
meta.f = 8w1;
}
if (meta.h != (h_t){#}) {
meta.f = 8w2;
}
meta.h = (h_t){#};
if (meta.h.isValid()) {
;
} else {
meta.f = 8w3;
}
hu = (hu_t){#};
if (nested.m.h == (h_t){#}) {
nested.m.f = 8w4;
}
}
@name("C.t") table t {
actions = {
a_0();
}
default_action = a_0();
}
apply {
t.apply();
}
}

parser P(inout meta_t meta, inout nested_t nested, inout hu_t hu) {
state start {
meta.h = (h_t){#};
transition select(meta.h == (h_t){#}) {
true: start_true;
false: start_join;
}
}
state start_true {
meta.h.setInvalid();
transition start_join;
}
state start_join {
transition accept;
}
}

control proto(inout meta_t meta, inout nested_t nested, inout hu_t hu);
parser par(inout meta_t meta, inout nested_t nested, inout hu_t hu);
package top(par p, proto c);
top(P(), C()) main;
109 changes: 109 additions & 0 deletions testdata/p4_16_samples_outputs/issue5653-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <core.p4>

header h_t {
bit<8> f;
}

header h2_t {
bit<16> g;
}

header_union hu_t {
h_t a;
h2_t b;
}

struct meta_t {
h_t h;
bit<8> f;
}

struct nested_t {
meta_t m;
}

control C(inout meta_t meta, inout nested_t nested, inout hu_t hu) {
h_t ih;
h_t ih_0;
h_t ih_1;
h_t ih_2_a;
h2_t ih_2_b;
h_t ih_3;
@name("C.a") action a_0() {
ih.setInvalid();
ih_0.setInvalid();
ih_1.setInvalid();
ih_3.setInvalid();
if (!meta.h.isValid() && !ih.isValid() || meta.h.isValid() && ih.isValid() && meta.h.f == ih.f) {
meta.f = 8w1;
}
if (!meta.h.isValid() && !ih_0.isValid() || meta.h.isValid() && ih_0.isValid() && meta.h.f == ih_0.f) {
;
} else {
meta.f = 8w2;
}
meta.h = ih_1;
if (meta.h.isValid()) {
;
} else {
meta.f = 8w3;
}
if (ih_2_a.isValid()) {
hu.a.setValid();
hu.a = ih_2_a;
hu.b.setInvalid();
} else {
hu.a.setInvalid();
}
if (ih_2_b.isValid()) {
hu.b.setValid();
hu.b = ih_2_b;
hu.a.setInvalid();
} else {
hu.b.setInvalid();
}
if (!nested.m.h.isValid() && !ih_3.isValid() || nested.m.h.isValid() && ih_3.isValid() && nested.m.h.f == ih_3.f) {
nested.m.f = 8w4;
}
}
@name("C.t") table t {
actions = {
a_0();
}
default_action = a_0();
}
apply {
t.apply();
}
}

parser P(inout meta_t meta, inout nested_t nested, inout hu_t hu) {
h_t ih_4;
h_t ih_5;
state start {
ih_4.setInvalid();
ih_5.setInvalid();
meta.h = ih_4;
transition select((bit<1>)(!meta.h.isValid() && !ih_5.isValid() || meta.h.isValid() && ih_5.isValid() && meta.h.f == ih_5.f)) {
1w1: start_true;
1w0: start_join;
default: noMatch;
}
}
state start_true {
meta.h.setInvalid();
transition start_join;
}
state start_join {
transition accept;
}
state noMatch {
verify(false, error.NoMatch);
transition reject;
}
}

control proto(inout meta_t meta, inout nested_t nested, inout hu_t hu);
parser par(inout meta_t meta, inout nested_t nested, inout hu_t hu);
package top(par p, proto c);
top(P(), C()) main;
Loading
Loading