diff --git a/backends/p4tools/common/core/abstract_execution_state.cpp b/backends/p4tools/common/core/abstract_execution_state.cpp index fac023cb443..aad8dc3f43c 100644 --- a/backends/p4tools/common/core/abstract_execution_state.cpp +++ b/backends/p4tools/common/core/abstract_execution_state.cpp @@ -158,11 +158,12 @@ std::vector AbstractExecutionState::getFlatFields( for (size_t arrayIndex = 0; arrayIndex < typeStack->getSize(); arrayIndex++) { const auto *newArr = HSIndexToMember::produceStackIndex(stackElementsType, parent, arrayIndex); - BUG_CHECK(stackElementsType->is(), - "Trying to get the flat fields for a non Type_StructLike element : %1%", - stackElementsType); - auto subFields = getFlatFields(newArr, validVector); - flatFields.insert(flatFields.end(), subFields.begin(), subFields.end()); + if (auto str = stackElementsType->to()) { + auto subFields = getFlatFields(newArr, validVector); + flatFields.insert(flatFields.end(), subFields.begin(), subFields.end()); + } else { + flatFields.push_back(newArr); + } } } else { flatFields.push_back(parent); diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2MetadataXfail.cmake b/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2MetadataXfail.cmake index 5803decc815..c110c1d2fc0 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2MetadataXfail.cmake +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2MetadataXfail.cmake @@ -64,6 +64,14 @@ p4tools_add_xfail_reason( loop-3-clause-tricky2.p4 ) +p4tools_add_xfail_reason( + "testgen-p4c-bmv2-metadata" + "Cast failed" + # testgen has issues with arrays + array1.p4 + array2.p4 +) + #################################################################################################### # 3. WONTFIX #################################################################################################### diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2PTFXfail.cmake b/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2PTFXfail.cmake index ff800411663..5bdcfbae3f9 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2PTFXfail.cmake +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2PTFXfail.cmake @@ -108,6 +108,14 @@ p4tools_add_xfail_reason( loop-3-clause-tricky2.p4 ) +p4tools_add_xfail_reason( + "testgen-p4c-bmv2-ptf" + "Cast failed" + # testgen has issues with arrays + array1.p4 + array2.p4 +) + #################################################################################################### # 3. WONTFIX # These are failures that can not be solved by changing P4Testgen diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2ProtobufIrXfail.cmake b/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2ProtobufIrXfail.cmake index 37938f56512..f8316c280fa 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2ProtobufIrXfail.cmake +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2ProtobufIrXfail.cmake @@ -81,6 +81,14 @@ p4tools_add_xfail_reason( loop-3-clause-tricky2.p4 ) +p4tools_add_xfail_reason( + "testgen-p4c-bmv2-protobuf-ir" + "Cast failed" + # testgen has issues with arrays + array1.p4 + array2.p4 +) + #################################################################################################### # 3. WONTFIX #################################################################################################### diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2STFXfail.cmake b/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2STFXfail.cmake index dd146980cab..179825dad3d 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2STFXfail.cmake +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/BMV2STFXfail.cmake @@ -108,6 +108,14 @@ p4tools_add_xfail_reason( loop-3-clause-tricky2.p4 ) +p4tools_add_xfail_reason( + "testgen-p4c-bmv2-stf" + "Cast failed" + # testgen has issues with arrays + array1.p4 + array2.p4 +) + #################################################################################################### # 3. WONTFIX # These are failures that can not be solved by changing P4Testgen diff --git a/frontends/p4/typeChecking/typeCheckExpr.cpp b/frontends/p4/typeChecking/typeCheckExpr.cpp index b711c581a0a..84f8836c0c5 100644 --- a/frontends/p4/typeChecking/typeCheckExpr.cpp +++ b/frontends/p4/typeChecking/typeCheckExpr.cpp @@ -1707,8 +1707,9 @@ const IR::Node *TypeInferenceBase::postorder(const IR::Member *expression) { if (auto *stack = type->to()) { auto parser = findContext(); auto eltype = stack->elementType; - if (!eltype->is() && !eltype->is() /* && - !eltype->is() */) { + if (auto sc = eltype->to()) + eltype = sc->baseType; + if (!eltype->is() && !eltype->is()) { typeError("%1%: '%2%' can only be used on header stacks", expression, member); return expression; } else if (member == IR::Type_Stack::next || member == IR::Type_Stack::last) { diff --git a/frontends/p4/typeChecking/typeCheckTypes.cpp b/frontends/p4/typeChecking/typeCheckTypes.cpp index 9a9cbb7415e..10f934ca114 100644 --- a/frontends/p4/typeChecking/typeCheckTypes.cpp +++ b/frontends/p4/typeChecking/typeCheckTypes.cpp @@ -425,9 +425,12 @@ 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; + 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() ||