diff --git a/frontends/p4/typeChecking/typeCheckTypes.cpp b/frontends/p4/typeChecking/typeCheckTypes.cpp index 10f934ca11..c9b5eb12d2 100644 --- a/frontends/p4/typeChecking/typeCheckTypes.cpp +++ b/frontends/p4/typeChecking/typeCheckTypes.cpp @@ -47,6 +47,7 @@ bool hasVarbitsOrUnions(const TypeMap *typeMap, const IR::Type *type) { bool TypeInferenceBase::onlyBitsOrBitStructs(const IR::Type *type) const { // called for a canonical type + while (auto *st = type->to()) type = st->elementType; if (type->is() || type->is() || type->is()) { return true; } else if (auto ht = type->to()) { @@ -424,18 +425,9 @@ const IR::Node *TypeInferenceBase::postorder(const IR::StructField *field) { const IR::Node *TypeInferenceBase::postorder(const IR::Type_Header *type) { auto canon = setTypeType(type); auto validator = [this](const IR::Type *t) { - while (1) { - if (t->is()) - t = getTypeType(t->to()->type); - else if (auto *st = t->to()) - t = st->elementType; - else - break; - } - return t->is() || t->is() || - (t->is() && onlyBitsOrBitStructs(t)) || t->is() || - t->is() || t->is() || - t->is(); + while (t->is()) t = getTypeType(t->to()->type); + return onlyBitsOrBitStructs(t) || t->is() || + t->is() || t->is(); }; validateFields(canon, validator); return type; diff --git a/testdata/p4_16_samples/array3.p4 b/testdata/p4_16_samples/array3.p4 new file mode 100644 index 0000000000..37549afce7 --- /dev/null +++ b/testdata/p4_16_samples/array3.p4 @@ -0,0 +1,30 @@ +control proto

(inout P pkt); +package top

(proto

p); + +struct S { + bit<16> f1; + bit<8>[16] nested_arr; + bit<16> f2; +} + +header data_t { + S[16] arr; + bit<4> w; + bit<4> x; + bit<4> y; + bit<4> z; +} + +struct headers { + data_t data; +} + + +control c(inout headers hdr) { + apply { + hdr.data.arr[0].nested_arr[1] = + hdr.data.arr[2].nested_arr[3]; + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/array3-first.p4 b/testdata/p4_16_samples_outputs/array3-first.p4 new file mode 100644 index 0000000000..fe5f1f08e5 --- /dev/null +++ b/testdata/p4_16_samples_outputs/array3-first.p4 @@ -0,0 +1,27 @@ +control proto

(inout P pkt); +package top

(proto

p); +struct S { + bit<16> f1; + bit<8>[16] nested_arr; + bit<16> f2; +} + +header data_t { + S[16] arr; + bit<4> w; + bit<4> x; + bit<4> y; + bit<4> z; +} + +struct headers { + data_t data; +} + +control c(inout headers hdr) { + apply { + hdr.data.arr[0].nested_arr[1] = hdr.data.arr[2].nested_arr[3]; + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/array3-frontend.p4 b/testdata/p4_16_samples_outputs/array3-frontend.p4 new file mode 100644 index 0000000000..fe5f1f08e5 --- /dev/null +++ b/testdata/p4_16_samples_outputs/array3-frontend.p4 @@ -0,0 +1,27 @@ +control proto

(inout P pkt); +package top

(proto

p); +struct S { + bit<16> f1; + bit<8>[16] nested_arr; + bit<16> f2; +} + +header data_t { + S[16] arr; + bit<4> w; + bit<4> x; + bit<4> y; + bit<4> z; +} + +struct headers { + data_t data; +} + +control c(inout headers hdr) { + apply { + hdr.data.arr[0].nested_arr[1] = hdr.data.arr[2].nested_arr[3]; + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/array3-midend.p4 b/testdata/p4_16_samples_outputs/array3-midend.p4 new file mode 100644 index 0000000000..58b57571e7 --- /dev/null +++ b/testdata/p4_16_samples_outputs/array3-midend.p4 @@ -0,0 +1,36 @@ +control proto

(inout P pkt); +package top

(proto

p); +struct S { + bit<16> f1; + bit<8>[16] nested_arr; + bit<16> f2; +} + +header data_t { + S[16] arr; + bit<4> w; + bit<4> x; + bit<4> y; + bit<4> z; +} + +struct headers { + data_t data; +} + +control c(inout headers hdr) { + @hidden action array3l25() { + hdr.data.arr[0].nested_arr[1] = hdr.data.arr[2].nested_arr[3]; + } + @hidden table tbl_array3l25 { + actions = { + array3l25(); + } + const default_action = array3l25(); + } + apply { + tbl_array3l25.apply(); + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/array3.p4 b/testdata/p4_16_samples_outputs/array3.p4 new file mode 100644 index 0000000000..c8d032bb31 --- /dev/null +++ b/testdata/p4_16_samples_outputs/array3.p4 @@ -0,0 +1,27 @@ +control proto

(inout P pkt); +package top

(proto

p); +struct S { + bit<16> f1; + bit<8>[16] nested_arr; + bit<16> f2; +} + +header data_t { + S[16] arr; + bit<4> w; + bit<4> x; + bit<4> y; + bit<4> z; +} + +struct headers { + data_t data; +} + +control c(inout headers hdr) { + apply { + hdr.data.arr[0].nested_arr[1] = hdr.data.arr[2].nested_arr[3]; + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/array3.p4-stderr b/testdata/p4_16_samples_outputs/array3.p4-stderr new file mode 100644 index 0000000000..e69de29bb2