diff --git a/frontends/p4/frontend.cpp b/frontends/p4/frontend.cpp index 69e1e508e3e..70325ea3f0f 100644 --- a/frontends/p4/frontend.cpp +++ b/frontends/p4/frontend.cpp @@ -252,6 +252,7 @@ const IR::P4Program *FrontEnd::run(const CompilerOptions &options, const IR::P4P new SetHeaders(&refMap, &typeMap), // Check for constants only after inlining new CheckConstants(&refMap, &typeMap), + new ConstantFolding(&refMap, &typeMap, constantFoldingPolicy), new SimplifyControlFlow(&refMap, &typeMap), // more ifs may have been added to parsers new RemoveParserControlFlow(&refMap, &typeMap), diff --git a/testdata/p4_16_samples/issue4548.p4 b/testdata/p4_16_samples/issue4548.p4 new file mode 100644 index 00000000000..34229a7c765 --- /dev/null +++ b/testdata/p4_16_samples/issue4548.p4 @@ -0,0 +1,20 @@ +#include + +bit<16> fun1(bit<8> args1) { + return (bit<16>)args1; +} +bit<8> fun2(bit<4> args2) { + fun1(8w10); + return 8w0; +} + +control ingress() { + apply { + fun2(4w3); + fun2(4w3); + } +} + +control Ingress(); +package top( Ingress ig); +top( ingress()) main; diff --git a/testdata/p4_16_samples_outputs/gauntlet_hdr_in_value-bmv2-frontend.p4 b/testdata/p4_16_samples_outputs/gauntlet_hdr_in_value-bmv2-frontend.p4 index 9f1d61223e4..c6aef92944a 100644 --- a/testdata/p4_16_samples_outputs/gauntlet_hdr_in_value-bmv2-frontend.p4 +++ b/testdata/p4_16_samples_outputs/gauntlet_hdr_in_value-bmv2-frontend.p4 @@ -25,7 +25,7 @@ parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { @name("ingress.retval") bit<16> retval; apply { - retval = ((Headers){eth_hdr = (ethernet_t){dst_addr = 48w1,src_addr = 48w1,eth_type = 16w1}}).eth_hdr.eth_type + 16w1; + retval = 16w2; h.eth_hdr.eth_type = retval; } } diff --git a/testdata/p4_16_samples_outputs/issue1638-frontend.p4 b/testdata/p4_16_samples_outputs/issue1638-frontend.p4 index b53e6238df9..10f89571382 100644 --- a/testdata/p4_16_samples_outputs/issue1638-frontend.p4 +++ b/testdata/p4_16_samples_outputs/issue1638-frontend.p4 @@ -24,7 +24,7 @@ control MyC(inout hdr_t hdr, inout meta_t meta, in intrinsic_metadata_t intr_md) } @name("MyC.c2.a") table c2_a { key = { - ((meta_t){f0 = 8w0,f1 = 8w0,f2 = 8w0}).f0: exact @name("meta.f0"); + 8w0: exact @name("meta.f0"); } actions = { NoAction_1(); diff --git a/testdata/p4_16_samples_outputs/issue1638-midend.p4 b/testdata/p4_16_samples_outputs/issue1638-midend.p4 index 85208c2d2e2..92098d6b4c4 100644 --- a/testdata/p4_16_samples_outputs/issue1638-midend.p4 +++ b/testdata/p4_16_samples_outputs/issue1638-midend.p4 @@ -32,17 +32,17 @@ control MyC(inout hdr_t hdr, inout meta_t meta, in intrinsic_metadata_t intr_md) } default_action = NoAction_1(); } - @hidden action issue1638l23() { + @hidden action issue1638l20() { key_0 = 8w0; } - @hidden table tbl_issue1638l23 { + @hidden table tbl_issue1638l20 { actions = { - issue1638l23(); + issue1638l20(); } - const default_action = issue1638l23(); + const default_action = issue1638l20(); } apply { - tbl_issue1638l23.apply(); + tbl_issue1638l20.apply(); c2_a.apply(); } } diff --git a/testdata/p4_16_samples_outputs/issue1937-2-bmv2-frontend.p4 b/testdata/p4_16_samples_outputs/issue1937-2-bmv2-frontend.p4 index c3f111e19b0..6eec5ad228a 100644 --- a/testdata/p4_16_samples_outputs/issue1937-2-bmv2-frontend.p4 +++ b/testdata/p4_16_samples_outputs/issue1937-2-bmv2-frontend.p4 @@ -28,7 +28,7 @@ parser parserImpl(packet_in packet, out headers_t hdr, inout metadata_t meta, in transition foo_start_0; } state foo_start_0 { - hdr.h1.f2 = 8w5 >> 2; + hdr.h1.f2 = 8w1; transition start_1; } state start_1 { diff --git a/testdata/p4_16_samples_outputs/issue1937-3-bmv2-frontend.p4 b/testdata/p4_16_samples_outputs/issue1937-3-bmv2-frontend.p4 index acde3032cf0..7628ea34d47 100644 --- a/testdata/p4_16_samples_outputs/issue1937-3-bmv2-frontend.p4 +++ b/testdata/p4_16_samples_outputs/issue1937-3-bmv2-frontend.p4 @@ -19,7 +19,7 @@ control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_m apply { tmp = hdr.h1.f1; hdr.h1.f1 = tmp >> 2; - hdr.h1.f2 = 8w5 >> 2; + hdr.h1.f2 = 8w1; } } diff --git a/testdata/p4_16_samples_outputs/issue1937-frontend.p4 b/testdata/p4_16_samples_outputs/issue1937-frontend.p4 index 44dcf7a6538..5d2104714b1 100644 --- a/testdata/p4_16_samples_outputs/issue1937-frontend.p4 +++ b/testdata/p4_16_samples_outputs/issue1937-frontend.p4 @@ -19,7 +19,7 @@ parser parserImpl(out h1_t hdr) { transition foo_start_0; } state foo_start_0 { - hdr.f2 = 8w5 >> 2; + hdr.f2 = 8w1; transition start_1; } state start_1 { diff --git a/testdata/p4_16_samples_outputs/issue2303-frontend.p4 b/testdata/p4_16_samples_outputs/issue2303-frontend.p4 index b0d3ba5f2eb..5dd582404db 100644 --- a/testdata/p4_16_samples_outputs/issue2303-frontend.p4 +++ b/testdata/p4_16_samples_outputs/issue2303-frontend.p4 @@ -33,7 +33,7 @@ parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { apply { - h.h.a = ((Meta){f0 = 8w0,f1 = 8w0,f2 = 8w0}).f0; + h.h.a = 8w0; } } diff --git a/testdata/p4_16_samples_outputs/issue2648-frontend.p4 b/testdata/p4_16_samples_outputs/issue2648-frontend.p4 index 9837ef0c25f..1ba9e688ca3 100644 --- a/testdata/p4_16_samples_outputs/issue2648-frontend.p4 +++ b/testdata/p4_16_samples_outputs/issue2648-frontend.p4 @@ -26,7 +26,7 @@ control ingress(inout Headers h) { @name("ingress.tmp_0") bit<8> tmp_0; @name("ingress.retval") bit<8> retval; apply { - retval = ((H){a = 8w1}).a; + retval = 8w1; tmp = retval; tmp_0 = tmp; h.h[tmp_0].a = 8w1; diff --git a/testdata/p4_16_samples_outputs/issue4500-frontend.p4 b/testdata/p4_16_samples_outputs/issue4500-frontend.p4 index 1a02e7c1290..e8332bd8f77 100644 --- a/testdata/p4_16_samples_outputs/issue4500-frontend.p4 +++ b/testdata/p4_16_samples_outputs/issue4500-frontend.p4 @@ -7,9 +7,7 @@ extern void baz(); control c() { apply { bar(E.e0); - if (E.e0 == E.e0) { - baz(); - } + baz(); } } diff --git a/testdata/p4_16_samples_outputs/issue4548-first.p4 b/testdata/p4_16_samples_outputs/issue4548-first.p4 new file mode 100644 index 00000000000..d2834d13faa --- /dev/null +++ b/testdata/p4_16_samples_outputs/issue4548-first.p4 @@ -0,0 +1,19 @@ +#include + +bit<16> fun1(bit<8> args1) { + return (bit<16>)args1; +} +bit<8> fun2(bit<4> args2) { + fun1(8w10); + return 8w0; +} +control ingress() { + apply { + fun2(4w3); + fun2(4w3); + } +} + +control Ingress(); +package top(Ingress ig); +top(ingress()) main; diff --git a/testdata/p4_16_samples_outputs/issue4548-frontend.p4 b/testdata/p4_16_samples_outputs/issue4548-frontend.p4 new file mode 100644 index 00000000000..ed2c9513131 --- /dev/null +++ b/testdata/p4_16_samples_outputs/issue4548-frontend.p4 @@ -0,0 +1,10 @@ +#include + +control ingress() { + apply { + } +} + +control Ingress(); +package top(Ingress ig); +top(ingress()) main; diff --git a/testdata/p4_16_samples_outputs/issue4548-midend.p4 b/testdata/p4_16_samples_outputs/issue4548-midend.p4 new file mode 100644 index 00000000000..ed2c9513131 --- /dev/null +++ b/testdata/p4_16_samples_outputs/issue4548-midend.p4 @@ -0,0 +1,10 @@ +#include + +control ingress() { + apply { + } +} + +control Ingress(); +package top(Ingress ig); +top(ingress()) main; diff --git a/testdata/p4_16_samples_outputs/issue4548.p4 b/testdata/p4_16_samples_outputs/issue4548.p4 new file mode 100644 index 00000000000..d2834d13faa --- /dev/null +++ b/testdata/p4_16_samples_outputs/issue4548.p4 @@ -0,0 +1,19 @@ +#include + +bit<16> fun1(bit<8> args1) { + return (bit<16>)args1; +} +bit<8> fun2(bit<4> args2) { + fun1(8w10); + return 8w0; +} +control ingress() { + apply { + fun2(4w3); + fun2(4w3); + } +} + +control Ingress(); +package top(Ingress ig); +top(ingress()) main; diff --git a/testdata/p4_16_samples_outputs/issue4548.p4-stderr b/testdata/p4_16_samples_outputs/issue4548.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/named-arg1-frontend.p4 b/testdata/p4_16_samples_outputs/named-arg1-frontend.p4 index 076249913ee..6f105f02516 100644 --- a/testdata/p4_16_samples_outputs/named-arg1-frontend.p4 +++ b/testdata/p4_16_samples_outputs/named-arg1-frontend.p4 @@ -6,7 +6,7 @@ parser par(out bool b) { transition adder_0_start; } state adder_0_start { - x_0 = 32w0 + 32w6; + x_0 = 32w6; transition start_0; } state start_0 {