diff --git a/frontends/common/constantFolding.cpp b/frontends/common/constantFolding.cpp index 58e93a9bb8..3791f00e78 100644 --- a/frontends/common/constantFolding.cpp +++ b/frontends/common/constantFolding.cpp @@ -836,6 +836,13 @@ const IR::Node *DoConstantFolding::postorder(IR::Cast *e) { } else if (auto arg = expr->to()) { int v = arg->value ? 1 : 0; return new IR::Constant(e->srcInfo, type, v, 10); + } else if (expr->is()) { + auto ei = EnumInstance::resolve(expr, typeMap); + if (ei == nullptr) + return e; + if (auto se = ei->to()) { + return se->value; + } } else { return e; } diff --git a/frontends/p4/commonInlining.h b/frontends/p4/commonInlining.h index b12c113038..a9e55aa2f9 100644 --- a/frontends/p4/commonInlining.h +++ b/frontends/p4/commonInlining.h @@ -169,8 +169,9 @@ class InlineDriver : public Visitor { public: InlineDriver( InlineList* toInline, AbstractInliner *inliner) : - toInline(toInline), inliner(inliner) - { CHECK_NULL(toInline); CHECK_NULL(inliner); setName("InlineDriver"); } + toInline(toInline), inliner(inliner) { + CHECK_NULL(toInline); CHECK_NULL(inliner); + setName((cstring("InlineDriver_") + cstring(inliner->name())).c_str()); } const IR::Node* apply_visitor(const IR::Node *program, const char * = 0) override { LOG2("InlineDriver"); toInline->analyze(); diff --git a/frontends/p4/enumInstance.cpp b/frontends/p4/enumInstance.cpp index ac6a34f2ae..07ccecc009 100644 --- a/frontends/p4/enumInstance.cpp +++ b/frontends/p4/enumInstance.cpp @@ -20,6 +20,7 @@ namespace P4 { // static EnumInstance* EnumInstance::resolve(const IR::Expression* expression, const P4::TypeMap* typeMap) { + CHECK_NULL(typeMap); if (!expression->is()) return nullptr; auto member = expression->to(); diff --git a/testdata/p4_14_samples_outputs/copy_to_cpu-first.p4 b/testdata/p4_14_samples_outputs/copy_to_cpu-first.p4 index 16b808e65a..ebc7e12d84 100644 --- a/testdata/p4_14_samples_outputs/copy_to_cpu-first.p4 +++ b/testdata/p4_14_samples_outputs/copy_to_cpu-first.p4 @@ -78,7 +78,7 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { @name(".do_copy_to_cpu") action do_copy_to_cpu() { - clone_preserving_field_list(CloneType.I2E, 32w250, (bit<8>)FieldLists.copy_to_cpu_fields); + clone_preserving_field_list(CloneType.I2E, 32w250, 8w1); } @name(".copy_to_cpu") table copy_to_cpu { actions = { diff --git a/testdata/p4_14_samples_outputs/copy_to_cpu-frontend.p4 b/testdata/p4_14_samples_outputs/copy_to_cpu-frontend.p4 index 98df884031..c6d7bec449 100644 --- a/testdata/p4_14_samples_outputs/copy_to_cpu-frontend.p4 +++ b/testdata/p4_14_samples_outputs/copy_to_cpu-frontend.p4 @@ -2,11 +2,6 @@ #define V1MODEL_VERSION 20200408 #include -enum bit<8> FieldLists { - none = 8w0, - copy_to_cpu_fields = 8w1 -} - struct intrinsic_metadata_t { bit<4> mcast_grp; bit<4> egress_rid; @@ -86,7 +81,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ @noWarn("unused") @name(".NoAction") action NoAction_3() { } @name(".do_copy_to_cpu") action do_copy_to_cpu() { - clone_preserving_field_list(CloneType.I2E, 32w250, (bit<8>)FieldLists.copy_to_cpu_fields); + clone_preserving_field_list(CloneType.I2E, 32w250, 8w1); } @name(".copy_to_cpu") table copy_to_cpu_0 { actions = { diff --git a/testdata/p4_14_samples_outputs/p414-special-ops-2-bmv2-first.p4 b/testdata/p4_14_samples_outputs/p414-special-ops-2-bmv2-first.p4 index ab613d8c3e..bb9a896a78 100644 --- a/testdata/p4_14_samples_outputs/p414-special-ops-2-bmv2-first.p4 +++ b/testdata/p4_14_samples_outputs/p414-special-ops-2-bmv2-first.p4 @@ -66,13 +66,13 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710633; meta.mymeta.f1 = meta.mymeta.f1 + 8w23; meta.mymeta.clone_e2e_count = meta.mymeta.clone_e2e_count + 8w1; - clone_preserving_field_list(CloneType.E2E, 32w1, (bit<8>)FieldLists.clone_e2e_FL); + clone_preserving_field_list(CloneType.E2E, 32w1, 8w1); } @name(".do_recirculate") action do_recirculate() { hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710637; meta.mymeta.f1 = meta.mymeta.f1 + 8w19; meta.mymeta.recirculate_count = meta.mymeta.recirculate_count + 8w1; - recirculate_preserving_field_list((bit<8>)FieldLists.recirculate_FL); + recirculate_preserving_field_list(8w2); } @name("._nop") action _nop() { } @@ -230,7 +230,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710639; meta.mymeta.f1 = meta.mymeta.f1 + 8w17; meta.mymeta.resubmit_count = meta.mymeta.resubmit_count + 8w1; - resubmit_preserving_field_list((bit<8>)FieldLists.resubmit_FL); + resubmit_preserving_field_list(8w3); } @name("._nop") action _nop() { } diff --git a/testdata/p4_14_samples_outputs/p414-special-ops-2-bmv2-frontend.p4 b/testdata/p4_14_samples_outputs/p414-special-ops-2-bmv2-frontend.p4 index e1139f965b..253b19e597 100644 --- a/testdata/p4_14_samples_outputs/p414-special-ops-2-bmv2-frontend.p4 +++ b/testdata/p4_14_samples_outputs/p414-special-ops-2-bmv2-frontend.p4 @@ -66,13 +66,13 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710633; meta.mymeta.f1 = meta.mymeta.f1 + 8w23; meta.mymeta.clone_e2e_count = meta.mymeta.clone_e2e_count + 8w1; - clone_preserving_field_list(CloneType.E2E, 32w1, (bit<8>)FieldLists.clone_e2e_FL); + clone_preserving_field_list(CloneType.E2E, 32w1, 8w1); } @name(".do_recirculate") action do_recirculate() { hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710637; meta.mymeta.f1 = meta.mymeta.f1 + 8w19; meta.mymeta.recirculate_count = meta.mymeta.recirculate_count + 8w1; - recirculate_preserving_field_list((bit<8>)FieldLists.recirculate_FL); + recirculate_preserving_field_list(8w2); } @name("._nop") action _nop() { } @@ -259,7 +259,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710639; meta.mymeta.f1 = meta.mymeta.f1 + 8w17; meta.mymeta.resubmit_count = meta.mymeta.resubmit_count + 8w1; - resubmit_preserving_field_list((bit<8>)FieldLists.resubmit_FL); + resubmit_preserving_field_list(8w3); } @name("._nop") action _nop_3() { } diff --git a/testdata/p4_14_samples_outputs/p414-special-ops-3-bmv2-first.p4 b/testdata/p4_14_samples_outputs/p414-special-ops-3-bmv2-first.p4 index d402c47863..3587d0aa82 100644 --- a/testdata/p4_14_samples_outputs/p414-special-ops-3-bmv2-first.p4 +++ b/testdata/p4_14_samples_outputs/p414-special-ops-3-bmv2-first.p4 @@ -65,13 +65,13 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710633; meta.mymeta.f1 = meta.mymeta.f1 + 8w23; meta.mymeta.clone_e2e_count = meta.mymeta.clone_e2e_count + 8w1; - clone_preserving_field_list(CloneType.E2E, 32w1, (bit<8>)FieldLists.clone_e2e_FL); + clone_preserving_field_list(CloneType.E2E, 32w1, 8w1); } @name(".do_recirculate") action do_recirculate() { hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710637; meta.mymeta.f1 = meta.mymeta.f1 + 8w19; meta.mymeta.recirculate_count = meta.mymeta.recirculate_count + 8w1; - recirculate_preserving_field_list((bit<8>)FieldLists.recirculate_FL); + recirculate_preserving_field_list(8w2); } @name("._nop") action _nop() { } @@ -242,7 +242,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710639; meta.mymeta.f1 = meta.mymeta.f1 + 8w17; meta.mymeta.resubmit_count = meta.mymeta.resubmit_count + 8w1; - resubmit_preserving_field_list((bit<8>)FieldLists.resubmit_FL); + resubmit_preserving_field_list(8w3); } @name("._nop") action _nop() { } diff --git a/testdata/p4_14_samples_outputs/p414-special-ops-3-bmv2-frontend.p4 b/testdata/p4_14_samples_outputs/p414-special-ops-3-bmv2-frontend.p4 index ed247b7ff9..dcb84967a2 100644 --- a/testdata/p4_14_samples_outputs/p414-special-ops-3-bmv2-frontend.p4 +++ b/testdata/p4_14_samples_outputs/p414-special-ops-3-bmv2-frontend.p4 @@ -65,13 +65,13 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710633; meta.mymeta.f1 = meta.mymeta.f1 + 8w23; meta.mymeta.clone_e2e_count = meta.mymeta.clone_e2e_count + 8w1; - clone_preserving_field_list(CloneType.E2E, 32w1, (bit<8>)FieldLists.clone_e2e_FL); + clone_preserving_field_list(CloneType.E2E, 32w1, 8w1); } @name(".do_recirculate") action do_recirculate() { hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710637; meta.mymeta.f1 = meta.mymeta.f1 + 8w19; meta.mymeta.recirculate_count = meta.mymeta.recirculate_count + 8w1; - recirculate_preserving_field_list((bit<8>)FieldLists.recirculate_FL); + recirculate_preserving_field_list(8w2); } @name("._nop") action _nop() { } @@ -271,7 +271,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710639; meta.mymeta.f1 = meta.mymeta.f1 + 8w17; meta.mymeta.resubmit_count = meta.mymeta.resubmit_count + 8w1; - resubmit_preserving_field_list((bit<8>)FieldLists.resubmit_FL); + resubmit_preserving_field_list(8w3); } @name("._nop") action _nop_3() { } diff --git a/testdata/p4_14_samples_outputs/p414-special-ops-first.p4 b/testdata/p4_14_samples_outputs/p414-special-ops-first.p4 index 0d70e3177a..43d608328f 100644 --- a/testdata/p4_14_samples_outputs/p414-special-ops-first.p4 +++ b/testdata/p4_14_samples_outputs/p414-special-ops-first.p4 @@ -65,13 +65,13 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710633; meta.mymeta.f1 = meta.mymeta.f1 + 8w23; meta.mymeta.clone_e2e_count = meta.mymeta.clone_e2e_count + 8w1; - clone_preserving_field_list(CloneType.E2E, 32w1, (bit<8>)FieldLists.clone_e2e_FL); + clone_preserving_field_list(CloneType.E2E, 32w1, 8w1); } @name(".do_recirculate") action do_recirculate() { hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710637; meta.mymeta.f1 = meta.mymeta.f1 + 8w19; meta.mymeta.recirculate_count = meta.mymeta.recirculate_count + 8w1; - recirculate_preserving_field_list((bit<8>)FieldLists.recirculate_FL); + recirculate_preserving_field_list(8w2); } @name("._nop") action _nop() { } @@ -229,7 +229,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710639; meta.mymeta.f1 = meta.mymeta.f1 + 8w17; meta.mymeta.resubmit_count = meta.mymeta.resubmit_count + 8w1; - resubmit_preserving_field_list((bit<8>)FieldLists.resubmit_FL); + resubmit_preserving_field_list(8w3); } @name("._nop") action _nop() { } diff --git a/testdata/p4_14_samples_outputs/p414-special-ops-frontend.p4 b/testdata/p4_14_samples_outputs/p414-special-ops-frontend.p4 index 5e3334e770..0a5aaef7a5 100644 --- a/testdata/p4_14_samples_outputs/p414-special-ops-frontend.p4 +++ b/testdata/p4_14_samples_outputs/p414-special-ops-frontend.p4 @@ -65,13 +65,13 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710633; meta.mymeta.f1 = meta.mymeta.f1 + 8w23; meta.mymeta.clone_e2e_count = meta.mymeta.clone_e2e_count + 8w1; - clone_preserving_field_list(CloneType.E2E, 32w1, (bit<8>)FieldLists.clone_e2e_FL); + clone_preserving_field_list(CloneType.E2E, 32w1, 8w1); } @name(".do_recirculate") action do_recirculate() { hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710637; meta.mymeta.f1 = meta.mymeta.f1 + 8w19; meta.mymeta.recirculate_count = meta.mymeta.recirculate_count + 8w1; - recirculate_preserving_field_list((bit<8>)FieldLists.recirculate_FL); + recirculate_preserving_field_list(8w2); } @name("._nop") action _nop() { } @@ -258,7 +258,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ hdr.ethernet.srcAddr = hdr.ethernet.srcAddr + 48w281474976710639; meta.mymeta.f1 = meta.mymeta.f1 + 8w17; meta.mymeta.resubmit_count = meta.mymeta.resubmit_count + 8w1; - resubmit_preserving_field_list((bit<8>)FieldLists.resubmit_FL); + resubmit_preserving_field_list(8w3); } @name("._nop") action _nop_3() { } diff --git a/testdata/p4_14_samples_outputs/packet_redirect-first.p4 b/testdata/p4_14_samples_outputs/packet_redirect-first.p4 index 5ec2cee806..f74595e6fa 100644 --- a/testdata/p4_14_samples_outputs/packet_redirect-first.p4 +++ b/testdata/p4_14_samples_outputs/packet_redirect-first.p4 @@ -53,10 +53,10 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t @name("._nop") action _nop() { } @name("._recirculate") action _recirculate() { - recirculate_preserving_field_list((bit<8>)FieldLists.redirect_FL); + recirculate_preserving_field_list(8w1); } @name("._clone_e2e") action _clone_e2e(bit<32> mirror_id) { - clone_preserving_field_list(CloneType.E2E, mirror_id, (bit<8>)FieldLists.redirect_FL); + clone_preserving_field_list(CloneType.E2E, mirror_id, 8w1); } @name(".t_egress") table t_egress { actions = { @@ -88,10 +88,10 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ standard_metadata.mcast_grp = mgrp; } @name("._resubmit") action _resubmit() { - resubmit_preserving_field_list((bit<8>)FieldLists.redirect_FL); + resubmit_preserving_field_list(8w1); } @name("._clone_i2e") action _clone_i2e(bit<32> mirror_id) { - clone_preserving_field_list(CloneType.I2E, mirror_id, (bit<8>)FieldLists.redirect_FL); + clone_preserving_field_list(CloneType.I2E, mirror_id, 8w1); } @name(".t_ingress_1") table t_ingress_1 { actions = { diff --git a/testdata/p4_14_samples_outputs/packet_redirect-frontend.p4 b/testdata/p4_14_samples_outputs/packet_redirect-frontend.p4 index 514c1d44c7..f8f29e5eff 100644 --- a/testdata/p4_14_samples_outputs/packet_redirect-frontend.p4 +++ b/testdata/p4_14_samples_outputs/packet_redirect-frontend.p4 @@ -55,10 +55,10 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t @name("._nop") action _nop() { } @name("._recirculate") action _recirculate() { - recirculate_preserving_field_list((bit<8>)FieldLists.redirect_FL); + recirculate_preserving_field_list(8w1); } @name("._clone_e2e") action _clone_e2e(@name("mirror_id") bit<32> mirror_id) { - clone_preserving_field_list(CloneType.E2E, mirror_id, (bit<8>)FieldLists.redirect_FL); + clone_preserving_field_list(CloneType.E2E, mirror_id, 8w1); } @name(".t_egress") table t_egress_0 { actions = { @@ -96,10 +96,10 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ standard_metadata.mcast_grp = mgrp; } @name("._resubmit") action _resubmit() { - resubmit_preserving_field_list((bit<8>)FieldLists.redirect_FL); + resubmit_preserving_field_list(8w1); } @name("._clone_i2e") action _clone_i2e(@name("mirror_id") bit<32> mirror_id_2) { - clone_preserving_field_list(CloneType.I2E, mirror_id_2, (bit<8>)FieldLists.redirect_FL); + clone_preserving_field_list(CloneType.I2E, mirror_id_2, 8w1); } @name(".t_ingress_1") table t_ingress { actions = { diff --git a/testdata/p4_14_samples_outputs/resubmit-first.p4 b/testdata/p4_14_samples_outputs/resubmit-first.p4 index 905b9a029a..292ba594f8 100644 --- a/testdata/p4_14_samples_outputs/resubmit-first.p4 +++ b/testdata/p4_14_samples_outputs/resubmit-first.p4 @@ -56,7 +56,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ } @name("._resubmit") action _resubmit() { meta.mymeta.f1 = 8w1; - resubmit_preserving_field_list((bit<8>)FieldLists.resubmit_FL); + resubmit_preserving_field_list(8w1); } @name(".t_ingress_1") table t_ingress_1 { actions = { diff --git a/testdata/p4_14_samples_outputs/resubmit-frontend.p4 b/testdata/p4_14_samples_outputs/resubmit-frontend.p4 index 713627d25f..20c2653dcd 100644 --- a/testdata/p4_14_samples_outputs/resubmit-frontend.p4 +++ b/testdata/p4_14_samples_outputs/resubmit-frontend.p4 @@ -62,7 +62,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ } @name("._resubmit") action _resubmit() { meta.mymeta.f1 = 8w1; - resubmit_preserving_field_list((bit<8>)FieldLists.resubmit_FL); + resubmit_preserving_field_list(8w1); } @name(".t_ingress_1") table t_ingress { actions = { diff --git a/testdata/p4_14_samples_outputs/simple_nat-first.p4 b/testdata/p4_14_samples_outputs/simple_nat-first.p4 index 6b1c902d62..57e31446f4 100644 --- a/testdata/p4_14_samples_outputs/simple_nat-first.p4 +++ b/testdata/p4_14_samples_outputs/simple_nat-first.p4 @@ -186,7 +186,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ hdr.ipv4.ttl = hdr.ipv4.ttl + 8w255; } @name(".nat_miss_int_to_ext") action nat_miss_int_to_ext() { - clone_preserving_field_list(CloneType.I2E, 32w250, (bit<8>)FieldLists.copy_to_cpu_fields); + clone_preserving_field_list(CloneType.I2E, 32w250, 8w1); } @name(".nat_miss_ext_to_int") action nat_miss_ext_to_int() { meta.meta.do_forward = 1w0; diff --git a/testdata/p4_14_samples_outputs/simple_nat-frontend.p4 b/testdata/p4_14_samples_outputs/simple_nat-frontend.p4 index 24ad10a644..676670fecd 100644 --- a/testdata/p4_14_samples_outputs/simple_nat-frontend.p4 +++ b/testdata/p4_14_samples_outputs/simple_nat-frontend.p4 @@ -2,11 +2,6 @@ #define V1MODEL_VERSION 20200408 #include -enum bit<8> FieldLists { - none = 8w0, - copy_to_cpu_fields = 8w1 -} - struct intrinsic_metadata_t { bit<4> mcast_grp; bit<4> egress_rid; @@ -211,7 +206,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ hdr.ipv4.ttl = hdr.ipv4.ttl + 8w255; } @name(".nat_miss_int_to_ext") action nat_miss_int_to_ext() { - clone_preserving_field_list(CloneType.I2E, 32w250, (bit<8>)FieldLists.copy_to_cpu_fields); + clone_preserving_field_list(CloneType.I2E, 32w250, 8w1); } @name(".nat_miss_ext_to_int") action nat_miss_ext_to_int() { meta.meta.do_forward = 1w0; diff --git a/testdata/p4_14_samples_outputs/switch_20160512/switch-first.p4 b/testdata/p4_14_samples_outputs/switch_20160512/switch-first.p4 index 70cbb65dd5..8e31f9693b 100644 --- a/testdata/p4_14_samples_outputs/switch_20160512/switch-first.p4 +++ b/testdata/p4_14_samples_outputs/switch_20160512/switch-first.p4 @@ -2979,7 +2979,7 @@ control process_egress_acl(inout headers hdr, inout metadata meta, inout standar } @name(".egress_mirror") action egress_mirror(bit<32> session_id) { meta.i2e_metadata.mirror_session_id = (bit<16>)session_id; - clone_preserving_field_list(CloneType.E2E, session_id, (bit<8>)FieldLists.e2e_mirror_info); + clone_preserving_field_list(CloneType.E2E, session_id, 8w3); } @name(".egress_mirror_drop") action egress_mirror_drop(bit<32> session_id) { egress_mirror(session_id); @@ -2987,7 +2987,7 @@ control process_egress_acl(inout headers hdr, inout metadata meta, inout standar } @name(".egress_copy_to_cpu") action egress_copy_to_cpu(bit<16> reason_code) { meta.fabric_metadata.reason_code = reason_code; - clone_preserving_field_list(CloneType.E2E, 32w250, (bit<8>)FieldLists.cpu_info); + clone_preserving_field_list(CloneType.E2E, 32w250, 8w2); } @name(".egress_redirect_to_cpu") action egress_redirect_to_cpu(bit<16> reason_code) { egress_copy_to_cpu(reason_code); @@ -3511,7 +3511,7 @@ control process_int_endpoint(inout headers hdr, inout metadata meta, inout stand @name(".int_sink") action int_sink(bit<32> mirror_id) { meta.int_metadata_i2e.sink = 1w1; meta.i2e_metadata.mirror_session_id = (bit<16>)mirror_id; - clone_preserving_field_list(CloneType.I2E, mirror_id, (bit<8>)FieldLists.int_i2e_mirror_info); + clone_preserving_field_list(CloneType.I2E, mirror_id, 8w4); hdr.int_header.setInvalid(); hdr.int_val[0].setInvalid(); hdr.int_val[1].setInvalid(); @@ -4302,7 +4302,7 @@ control process_ingress_sflow(inout headers hdr, inout metadata meta, inout stan @name(".sflow_ing_pkt_to_cpu") action sflow_ing_pkt_to_cpu(bit<32> sflow_i2e_mirror_id, bit<16> reason_code) { meta.fabric_metadata.reason_code = reason_code; meta.i2e_metadata.mirror_session_id = (bit<16>)sflow_i2e_mirror_id; - clone_preserving_field_list(CloneType.I2E, sflow_i2e_mirror_id, (bit<8>)FieldLists.sflow_cpu_info); + clone_preserving_field_list(CloneType.I2E, sflow_i2e_mirror_id, 8w6); } @name(".sflow_ing_session_enable") action sflow_ing_session_enable(bit<32> rate_thr, bit<16> session_id) { meta.ingress_metadata.sflow_take_sample = rate_thr |+| meta.ingress_metadata.sflow_take_sample; @@ -4315,7 +4315,7 @@ control process_ingress_sflow(inout headers hdr, inout metadata meta, inout stan sflow_ingress_session_pkt_counter.count(); meta.fabric_metadata.reason_code = reason_code; meta.i2e_metadata.mirror_session_id = (bit<16>)sflow_i2e_mirror_id; - clone_preserving_field_list(CloneType.I2E, sflow_i2e_mirror_id, (bit<8>)FieldLists.sflow_cpu_info); + clone_preserving_field_list(CloneType.I2E, sflow_i2e_mirror_id, 8w6); } @name(".sflow_ing_take_sample") table sflow_ing_take_sample { actions = { @@ -4533,7 +4533,7 @@ control process_mac_acl(inout headers hdr, inout metadata meta, inout standard_m @name(".acl_mirror") action acl_mirror(bit<32> session_id, bit<14> acl_stats_index, bit<16> acl_meter_index) { meta.i2e_metadata.mirror_session_id = (bit<16>)session_id; meta.i2e_metadata.ingress_tstamp = (bit<32>)standard_metadata.ingress_global_timestamp; - clone_preserving_field_list(CloneType.I2E, session_id, (bit<8>)FieldLists.i2e_mirror_info); + clone_preserving_field_list(CloneType.I2E, session_id, 8w1); meta.acl_metadata.acl_stats_index = acl_stats_index; meta.meter_metadata.meter_index = acl_meter_index; } @@ -4601,7 +4601,7 @@ control process_ip_acl(inout headers hdr, inout metadata meta, inout standard_me @name(".acl_mirror") action acl_mirror(bit<32> session_id, bit<14> acl_stats_index, bit<16> acl_meter_index) { meta.i2e_metadata.mirror_session_id = (bit<16>)session_id; meta.i2e_metadata.ingress_tstamp = (bit<32>)standard_metadata.ingress_global_timestamp; - clone_preserving_field_list(CloneType.I2E, session_id, (bit<8>)FieldLists.i2e_mirror_info); + clone_preserving_field_list(CloneType.I2E, session_id, 8w1); meta.acl_metadata.acl_stats_index = acl_stats_index; meta.meter_metadata.meter_index = acl_meter_index; } @@ -5852,7 +5852,7 @@ control process_system_acl(inout headers hdr, inout metadata meta, inout standar } @name(".copy_to_cpu_with_reason") action copy_to_cpu_with_reason(bit<16> reason_code) { meta.fabric_metadata.reason_code = reason_code; - clone_preserving_field_list(CloneType.I2E, 32w250, (bit<8>)FieldLists.cpu_info); + clone_preserving_field_list(CloneType.I2E, 32w250, 8w2); } @name(".redirect_to_cpu") action redirect_to_cpu(bit<16> reason_code) { copy_to_cpu_with_reason(reason_code); @@ -5860,7 +5860,7 @@ control process_system_acl(inout headers hdr, inout metadata meta, inout standar meta.fabric_metadata.dst_device = 8w0; } @name(".copy_to_cpu") action copy_to_cpu() { - clone_preserving_field_list(CloneType.I2E, 32w250, (bit<8>)FieldLists.cpu_info); + clone_preserving_field_list(CloneType.I2E, 32w250, 8w2); } @name(".drop_packet") action drop_packet() { mark_to_drop(standard_metadata); @@ -5870,7 +5870,7 @@ control process_system_acl(inout headers hdr, inout metadata meta, inout standar mark_to_drop(standard_metadata); } @name(".negative_mirror") action negative_mirror(bit<32> session_id) { - clone_preserving_field_list(CloneType.I2E, session_id, (bit<8>)FieldLists.mirror_info); + clone_preserving_field_list(CloneType.I2E, session_id, 8w5); mark_to_drop(standard_metadata); } @name(".drop_stats") table drop_stats_0 { diff --git a/testdata/p4_14_samples_outputs/switch_20160512/switch-frontend.p4 b/testdata/p4_14_samples_outputs/switch_20160512/switch-frontend.p4 index 226e3ff7a7..41f5658b4a 100644 --- a/testdata/p4_14_samples_outputs/switch_20160512/switch-frontend.p4 +++ b/testdata/p4_14_samples_outputs/switch_20160512/switch-frontend.p4 @@ -3046,16 +3046,16 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t } @name(".egress_mirror") action _egress_mirror_0(@name("session_id") bit<32> session_id) { meta.i2e_metadata.mirror_session_id = (bit<16>)session_id; - clone_preserving_field_list(CloneType.E2E, session_id, (bit<8>)FieldLists.e2e_mirror_info); + clone_preserving_field_list(CloneType.E2E, session_id, 8w3); } @name(".egress_mirror_drop") action _egress_mirror_drop_0(@name("session_id") bit<32> session_id_6) { meta.i2e_metadata.mirror_session_id = (bit<16>)session_id_6; - clone_preserving_field_list(CloneType.E2E, session_id_6, (bit<8>)FieldLists.e2e_mirror_info); + clone_preserving_field_list(CloneType.E2E, session_id_6, 8w3); mark_to_drop(standard_metadata); } @name(".egress_redirect_to_cpu") action _egress_redirect_to_cpu_0(@name("reason_code") bit<16> reason_code_0) { meta.fabric_metadata.reason_code = reason_code_0; - clone_preserving_field_list(CloneType.E2E, 32w250, (bit<8>)FieldLists.cpu_info); + clone_preserving_field_list(CloneType.E2E, 32w250, 8w2); mark_to_drop(standard_metadata); } @name(".egress_acl") table _egress_acl { @@ -3655,7 +3655,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ meta.int_metadata.insert_byte_cnt = meta.int_metadata.gpe_int_hdr_len << 2; meta.int_metadata_i2e.sink = 1w1; meta.i2e_metadata.mirror_session_id = (bit<16>)mirror_id; - clone_preserving_field_list(CloneType.I2E, mirror_id, (bit<8>)FieldLists.int_i2e_mirror_info); + clone_preserving_field_list(CloneType.I2E, mirror_id, 8w4); hdr.int_header.setInvalid(); hdr.int_val[0].setInvalid(); hdr.int_val[1].setInvalid(); @@ -4345,7 +4345,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ _sflow_ingress_session_pkt_counter.count(); meta.fabric_metadata.reason_code = reason_code_5; meta.i2e_metadata.mirror_session_id = (bit<16>)sflow_i2e_mirror_id; - clone_preserving_field_list(CloneType.I2E, sflow_i2e_mirror_id, (bit<8>)FieldLists.sflow_cpu_info); + clone_preserving_field_list(CloneType.I2E, sflow_i2e_mirror_id, 8w6); } @name(".sflow_ing_take_sample") table _sflow_ing_take_sample { actions = { @@ -4529,7 +4529,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ @name(".acl_mirror") action _acl_mirror_1(@name("session_id") bit<32> session_id_8, @name("acl_stats_index") bit<14> acl_stats_index_20, @name("acl_meter_index") bit<16> acl_meter_index_11) { meta.i2e_metadata.mirror_session_id = (bit<16>)session_id_8; meta.i2e_metadata.ingress_tstamp = (bit<32>)standard_metadata.ingress_global_timestamp; - clone_preserving_field_list(CloneType.I2E, session_id_8, (bit<8>)FieldLists.i2e_mirror_info); + clone_preserving_field_list(CloneType.I2E, session_id_8, 8w1); meta.acl_metadata.acl_stats_index = acl_stats_index_20; meta.meter_metadata.meter_index = acl_meter_index_11; } @@ -4604,14 +4604,14 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ @name(".acl_mirror") action _acl_mirror_2(@name("session_id") bit<32> session_id_9, @name("acl_stats_index") bit<14> acl_stats_index_27, @name("acl_meter_index") bit<16> acl_meter_index_18) { meta.i2e_metadata.mirror_session_id = (bit<16>)session_id_9; meta.i2e_metadata.ingress_tstamp = (bit<32>)standard_metadata.ingress_global_timestamp; - clone_preserving_field_list(CloneType.I2E, session_id_9, (bit<8>)FieldLists.i2e_mirror_info); + clone_preserving_field_list(CloneType.I2E, session_id_9, 8w1); meta.acl_metadata.acl_stats_index = acl_stats_index_27; meta.meter_metadata.meter_index = acl_meter_index_18; } @name(".acl_mirror") action _acl_mirror_3(@name("session_id") bit<32> session_id_10, @name("acl_stats_index") bit<14> acl_stats_index_28, @name("acl_meter_index") bit<16> acl_meter_index_19) { meta.i2e_metadata.mirror_session_id = (bit<16>)session_id_10; meta.i2e_metadata.ingress_tstamp = (bit<32>)standard_metadata.ingress_global_timestamp; - clone_preserving_field_list(CloneType.I2E, session_id_10, (bit<8>)FieldLists.i2e_mirror_info); + clone_preserving_field_list(CloneType.I2E, session_id_10, 8w1); meta.acl_metadata.acl_stats_index = acl_stats_index_28; meta.meter_metadata.meter_index = acl_meter_index_19; } @@ -5605,16 +5605,16 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ } @name(".copy_to_cpu_with_reason") action _copy_to_cpu_with_reason_0(@name("reason_code") bit<16> reason_code_6) { meta.fabric_metadata.reason_code = reason_code_6; - clone_preserving_field_list(CloneType.I2E, 32w250, (bit<8>)FieldLists.cpu_info); + clone_preserving_field_list(CloneType.I2E, 32w250, 8w2); } @name(".redirect_to_cpu") action _redirect_to_cpu_0(@name("reason_code") bit<16> reason_code_7) { meta.fabric_metadata.reason_code = reason_code_7; - clone_preserving_field_list(CloneType.I2E, 32w250, (bit<8>)FieldLists.cpu_info); + clone_preserving_field_list(CloneType.I2E, 32w250, 8w2); mark_to_drop(standard_metadata); meta.fabric_metadata.dst_device = 8w0; } @name(".copy_to_cpu") action _copy_to_cpu_0() { - clone_preserving_field_list(CloneType.I2E, 32w250, (bit<8>)FieldLists.cpu_info); + clone_preserving_field_list(CloneType.I2E, 32w250, 8w2); } @name(".drop_packet") action _drop_packet_0() { mark_to_drop(standard_metadata); @@ -5624,7 +5624,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ mark_to_drop(standard_metadata); } @name(".negative_mirror") action _negative_mirror_0(@name("session_id") bit<32> session_id_11) { - clone_preserving_field_list(CloneType.I2E, session_id_11, (bit<8>)FieldLists.mirror_info); + clone_preserving_field_list(CloneType.I2E, session_id_11, 8w5); mark_to_drop(standard_metadata); } @name(".drop_stats") table _drop_stats { diff --git a/testdata/p4_16_samples/issue3178.p4 b/testdata/p4_16_samples/issue3178.p4 new file mode 100644 index 0000000000..99490e521d --- /dev/null +++ b/testdata/p4_16_samples/issue3178.p4 @@ -0,0 +1,7 @@ +enum bit<1> TableType {TT_ACL = 0, TT_FWD = 1}; + +const bit<10> b10 = (bit<10>)(bit<1>)TableType.TT_ACL; +const bit<10> mask = 1 << 9; + +const bit<10> test1 = b10 << 3; +const bit<10> test2 = mask | b10; diff --git a/testdata/p4_16_samples_outputs/enumCast-first.p4 b/testdata/p4_16_samples_outputs/enumCast-first.p4 index 3e38d69eae..bde85aff76 100644 --- a/testdata/p4_16_samples_outputs/enumCast-first.p4 +++ b/testdata/p4_16_samples_outputs/enumCast-first.p4 @@ -33,7 +33,7 @@ struct O { parser p(packet_in packet, out O o) { state start { X x = (X)32w0; - bit<32> z = (bit<32>)X.One; + bit<32> z = 32w1; bit<32> z1 = X.One; bool bb; E1 a = E1.e1; diff --git a/testdata/p4_16_samples_outputs/issue3178-first.p4 b/testdata/p4_16_samples_outputs/issue3178-first.p4 new file mode 100644 index 0000000000..1f9f75f89e --- /dev/null +++ b/testdata/p4_16_samples_outputs/issue3178-first.p4 @@ -0,0 +1,9 @@ +enum bit<1> TableType { + TT_ACL = 1w0, + TT_FWD = 1w1 +} + +const bit<10> b10 = 10w0; +const bit<10> mask = 10w512; +const bit<10> test1 = 10w0; +const bit<10> test2 = 10w512; diff --git a/testdata/p4_16_samples_outputs/issue3178-frontend.p4 b/testdata/p4_16_samples_outputs/issue3178-frontend.p4 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testdata/p4_16_samples_outputs/issue3178.p4 b/testdata/p4_16_samples_outputs/issue3178.p4 new file mode 100644 index 0000000000..e9a5d1bc72 --- /dev/null +++ b/testdata/p4_16_samples_outputs/issue3178.p4 @@ -0,0 +1,9 @@ +enum bit<1> TableType { + TT_ACL = 0, + TT_FWD = 1 +} + +const bit<10> b10 = (bit<10>)(bit<1>)TableType.TT_ACL; +const bit<10> mask = 1 << 9; +const bit<10> test1 = b10 << 3; +const bit<10> test2 = mask | b10; diff --git a/testdata/p4_16_samples_outputs/issue3178.p4-stderr b/testdata/p4_16_samples_outputs/issue3178.p4-stderr new file mode 100644 index 0000000000..7e57a518ff --- /dev/null +++ b/testdata/p4_16_samples_outputs/issue3178.p4-stderr @@ -0,0 +1 @@ +[--Wwarn=missing] warning: Program does not contain a `main' module