diff --git a/testdata/p4_16_samples/forloop2.p4 b/testdata/p4_16_samples/forloop2.p4 new file mode 100644 index 00000000000..a7eb53dc0b4 --- /dev/null +++ b/testdata/p4_16_samples/forloop2.p4 @@ -0,0 +1,31 @@ +#include +control generic(inout M m); +package top(generic c); + +header t1 { + bit<64> v; +} + +struct headers_t { + t1 t1; +} + +bit<64> _popcount(in bit<64> val) { + bit<64> n = 0; + bit<64> v = val; + for (bit<64> popcnti in 1 .. 64w63) { + if (v == 0) + return n; + n = n + 1; + v = v & (v - 1); + } + return n; +} + +control c(inout headers_t hdrs) { + apply { + hdrs.t1.v = _popcount(hdrs.t1.v); + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples/forloop3.p4 b/testdata/p4_16_samples/forloop3.p4 new file mode 100644 index 00000000000..cc9e257fc22 --- /dev/null +++ b/testdata/p4_16_samples/forloop3.p4 @@ -0,0 +1,37 @@ +#include +control generic(inout M m); +package top(generic c); + +extern T foo(in T x); + +header t1 { + bit<32> x; +} + +struct headers_t { + t1 t1; +} + +control c(inout headers_t hdrs) { + action a0(bit<8> x, bit<8> y) { + bit<8> idx = 255; + for (bit<8> i1 in 0 .. x) { + for (bit<8> j in i1 .. y) { + idx = foo(j); + if (idx == 255) + break; + } + } + } + + table test { + key = { hdrs.t1.x: exact; } + actions = { a0; } + } + + apply { + test.apply(); + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/forloop1.p4-stderr b/testdata/p4_16_samples_outputs/forloop1.p4-stderr index a9a6caff9ef..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/forloop1.p4-stderr +++ b/testdata/p4_16_samples_outputs/forloop1.p4-stderr @@ -1,3 +0,0 @@ -forloop1.p4(24): [--Wwarn=uninitialized_use] warning: v.x may be uninitialized - hdrs.head.f1 = hdrs.head.f1 + v.x; - ^^^ diff --git a/testdata/p4_16_samples_outputs/forloop2-first.p4 b/testdata/p4_16_samples_outputs/forloop2-first.p4 new file mode 100644 index 00000000000..b28726dbfad --- /dev/null +++ b/testdata/p4_16_samples_outputs/forloop2-first.p4 @@ -0,0 +1,31 @@ +#include + +control generic(inout M m); +package top(generic c); +header t1 { + bit<64> v; +} + +struct headers_t { + t1 t1; +} + +bit<64> _popcount(in bit<64> val) { + bit<64> n = 64w0; + bit<64> v = val; + for (bit<64> popcnti in 64w1 .. 64w63) { + if (v == 64w0) { + return n; + } + n = n + 64w1; + v = v & v + 64w18446744073709551615; + } + return n; +} +control c(inout headers_t hdrs) { + apply { + hdrs.t1.v = _popcount(hdrs.t1.v); + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/forloop2-frontend.p4 b/testdata/p4_16_samples_outputs/forloop2-frontend.p4 new file mode 100644 index 00000000000..e67c79b686f --- /dev/null +++ b/testdata/p4_16_samples_outputs/forloop2-frontend.p4 @@ -0,0 +1,43 @@ +#include + +control generic(inout M m); +package top(generic c); +header t1 { + bit<64> v; +} + +struct headers_t { + t1 t1; +} + +control c(inout headers_t hdrs) { + @name("c.hasReturned") bool hasReturned; + @name("c.retval") bit<64> retval; + @name("c.n") bit<64> n_0; + @name("c.v") bit<64> v_0; + @name("c.popcnti") bit<64> popcnti_0; + apply { + hasReturned = false; + n_0 = 64w0; + for (popcnti_0 in 64w1 .. 64w63) { + if (v_0 == 64w0) { + hasReturned = true; + retval = n_0; + } + if (hasReturned) { + ; + } else { + n_0 = n_0 + 64w1; + v_0 = v_0 & v_0 + 64w18446744073709551615; + } + } + if (hasReturned) { + ; + } else { + retval = n_0; + } + hdrs.t1.v = retval; + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/forloop2-midend.p4 b/testdata/p4_16_samples_outputs/forloop2-midend.p4 new file mode 100644 index 00000000000..b001cb5b614 --- /dev/null +++ b/testdata/p4_16_samples_outputs/forloop2-midend.p4 @@ -0,0 +1,88 @@ +#include + +control generic(inout M m); +package top(generic c); +header t1 { + bit<64> v; +} + +struct headers_t { + t1 t1; +} + +control c(inout headers_t hdrs) { + @name("c.hasReturned") bool hasReturned; + @name("c.retval") bit<64> retval; + @name("c.n") bit<64> n_0; + @name("c.v") bit<64> v_0; + @name("c.popcnti") bit<64> popcnti_0; + @hidden action forloop2l18() { + hasReturned = true; + retval = n_0; + } + @hidden action forloop2l19() { + n_0 = n_0 + 64w1; + v_0 = v_0 & v_0 + 64w18446744073709551615; + } + @hidden action forloop2l14() { + hasReturned = false; + n_0 = 64w0; + } + @hidden action forloop2l22() { + retval = n_0; + } + @hidden action forloop2l27() { + hdrs.t1.v = retval; + } + @hidden table tbl_forloop2l14 { + actions = { + forloop2l14(); + } + const default_action = forloop2l14(); + } + @hidden table tbl_forloop2l18 { + actions = { + forloop2l18(); + } + const default_action = forloop2l18(); + } + @hidden table tbl_forloop2l19 { + actions = { + forloop2l19(); + } + const default_action = forloop2l19(); + } + @hidden table tbl_forloop2l22 { + actions = { + forloop2l22(); + } + const default_action = forloop2l22(); + } + @hidden table tbl_forloop2l27 { + actions = { + forloop2l27(); + } + const default_action = forloop2l27(); + } + apply { + tbl_forloop2l14.apply(); + for (popcnti_0 in 64w1 .. 64w63) { + if (v_0 == 64w0) { + tbl_forloop2l18.apply(); + } + if (hasReturned) { + ; + } else { + tbl_forloop2l19.apply(); + } + } + if (hasReturned) { + ; + } else { + tbl_forloop2l22.apply(); + } + tbl_forloop2l27.apply(); + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/forloop2.p4 b/testdata/p4_16_samples_outputs/forloop2.p4 new file mode 100644 index 00000000000..8ba8cdd304c --- /dev/null +++ b/testdata/p4_16_samples_outputs/forloop2.p4 @@ -0,0 +1,31 @@ +#include + +control generic(inout M m); +package top(generic c); +header t1 { + bit<64> v; +} + +struct headers_t { + t1 t1; +} + +bit<64> _popcount(in bit<64> val) { + bit<64> n = 0; + bit<64> v = val; + for (bit<64> popcnti in 1 .. 64w63) { + if (v == 0) { + return n; + } + n = n + 1; + v = v & v - 1; + } + return n; +} +control c(inout headers_t hdrs) { + apply { + hdrs.t1.v = _popcount(hdrs.t1.v); + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/forloop2.p4-stderr b/testdata/p4_16_samples_outputs/forloop2.p4-stderr new file mode 100644 index 00000000000..8c226c30de1 --- /dev/null +++ b/testdata/p4_16_samples_outputs/forloop2.p4-stderr @@ -0,0 +1,11 @@ +forloop2.p4(17): [--Wwarn=uninitialized_use] warning: v may be uninitialized + if (v == 0) + ^ +forloop2.p4(20): [--Wwarn=uninitialized_use] warning: v may be uninitialized + v = v & (v - 1); + ^ +forloop2.p4(20): [--Wwarn=uninitialized_use] warning: v may be uninitialized + v = v & (v - 1); + ^ +[--Wwarn=uninitialized_use] warning: retval may be uninitialized +[--Wwarn=uninitialized_use] warning: retval may be uninitialized diff --git a/testdata/p4_16_samples_outputs/forloop3-first.p4 b/testdata/p4_16_samples_outputs/forloop3-first.p4 new file mode 100644 index 00000000000..5ac93597f30 --- /dev/null +++ b/testdata/p4_16_samples_outputs/forloop3-first.p4 @@ -0,0 +1,41 @@ +#include + +control generic(inout M m); +package top(generic c); +extern T foo(in T x); +header t1 { + bit<32> x; +} + +struct headers_t { + t1 t1; +} + +control c(inout headers_t hdrs) { + action a0(bit<8> x, bit<8> y) { + bit<8> idx = 8w255; + for (bit<8> i1 in 8w0 .. x) { + for (bit<8> j in i1 .. y) { + idx = foo>(j); + if (idx == 8w255) { + + } + } + } + } + table test { + key = { + hdrs.t1.x: exact @name("hdrs.t1.x"); + } + actions = { + a0(); + @defaultonly NoAction(); + } + default_action = NoAction(); + } + apply { + test.apply(); + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/forloop3-frontend.p4 b/testdata/p4_16_samples_outputs/forloop3-frontend.p4 new file mode 100644 index 00000000000..549b5c9196c --- /dev/null +++ b/testdata/p4_16_samples_outputs/forloop3-frontend.p4 @@ -0,0 +1,45 @@ +#include + +control generic(inout M m); +package top(generic c); +extern T foo(in T x); +header t1 { + bit<32> x; +} + +struct headers_t { + t1 t1; +} + +control c(inout headers_t hdrs) { + @name("c.idx") bit<8> idx_0; + @name("c.i1") bit<8> i1_0; + @name("c.j") bit<8> j_0; + @noWarn("unused") @name(".NoAction") action NoAction_1() { + } + @name("c.a0") action a0(@name("x") bit<8> x_1, @name("y") bit<8> y) { + for (i1_0 in 8w0 .. x_1) { + for (j_0 in i1_0 .. y) { + idx_0 = foo>(j_0); + if (idx_0 == 8w255) { + + } + } + } + } + @name("c.test") table test_0 { + key = { + hdrs.t1.x: exact @name("hdrs.t1.x"); + } + actions = { + a0(); + @defaultonly NoAction_1(); + } + default_action = NoAction_1(); + } + apply { + test_0.apply(); + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/forloop3-midend.p4 b/testdata/p4_16_samples_outputs/forloop3-midend.p4 new file mode 100644 index 00000000000..549b5c9196c --- /dev/null +++ b/testdata/p4_16_samples_outputs/forloop3-midend.p4 @@ -0,0 +1,45 @@ +#include + +control generic(inout M m); +package top(generic c); +extern T foo(in T x); +header t1 { + bit<32> x; +} + +struct headers_t { + t1 t1; +} + +control c(inout headers_t hdrs) { + @name("c.idx") bit<8> idx_0; + @name("c.i1") bit<8> i1_0; + @name("c.j") bit<8> j_0; + @noWarn("unused") @name(".NoAction") action NoAction_1() { + } + @name("c.a0") action a0(@name("x") bit<8> x_1, @name("y") bit<8> y) { + for (i1_0 in 8w0 .. x_1) { + for (j_0 in i1_0 .. y) { + idx_0 = foo>(j_0); + if (idx_0 == 8w255) { + + } + } + } + } + @name("c.test") table test_0 { + key = { + hdrs.t1.x: exact @name("hdrs.t1.x"); + } + actions = { + a0(); + @defaultonly NoAction_1(); + } + default_action = NoAction_1(); + } + apply { + test_0.apply(); + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/forloop3.p4 b/testdata/p4_16_samples_outputs/forloop3.p4 new file mode 100644 index 00000000000..daa3abfd258 --- /dev/null +++ b/testdata/p4_16_samples_outputs/forloop3.p4 @@ -0,0 +1,39 @@ +#include + +control generic(inout M m); +package top(generic c); +extern T foo(in T x); +header t1 { + bit<32> x; +} + +struct headers_t { + t1 t1; +} + +control c(inout headers_t hdrs) { + action a0(bit<8> x, bit<8> y) { + bit<8> idx = 255; + for (bit<8> i1 in 0 .. x) { + for (bit<8> j in i1 .. y) { + idx = foo(j); + if (idx == 255) { + + } + } + } + } + table test { + key = { + hdrs.t1.x: exact; + } + actions = { + a0; + } + } + apply { + test.apply(); + } +} + +top(c()) main; diff --git a/testdata/p4_16_samples_outputs/forloop3.p4-stderr b/testdata/p4_16_samples_outputs/forloop3.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d