diff options
Diffstat (limited to 'tests/conformance/4-statements')
11 files changed, 117 insertions, 0 deletions
diff --git a/tests/conformance/4-statements/uninit_array_init_ok.zc b/tests/conformance/4-statements/uninit_array_init_ok.zc new file mode 100644 index 0000000..d291448 --- /dev/null +++ b/tests/conformance/4-statements/uninit_array_init_ok.zc @@ -0,0 +1,10 @@ +// expect: 10/ +// spec 4.1.5: a full array initializer list initializes the array +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { + int[4] a = { 1, 2, 3, 4 }; + pn(a[0] + a[1] + a[2] + a[3]); + return 0; +} +// zc0: skip diff --git a/tests/conformance/4-statements/uninit_assigned_ok.zc b/tests/conformance/4-statements/uninit_assigned_ok.zc new file mode 100644 index 0000000..6c831a4 --- /dev/null +++ b/tests/conformance/4-statements/uninit_assigned_ok.zc @@ -0,0 +1,11 @@ +// expect: 3/ +// spec 4.1.5: a local assigned before use is fine +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { + int x; + x = 3; + pn(x); + return 0; +} +// zc0: skip diff --git a/tests/conformance/4-statements/uninit_both_branches_ok.zc b/tests/conformance/4-statements/uninit_both_branches_ok.zc new file mode 100644 index 0000000..205acdf --- /dev/null +++ b/tests/conformance/4-statements/uninit_both_branches_ok.zc @@ -0,0 +1,11 @@ +// expect: 1/ +// spec 4.1.5: every branch assigns before the join +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { + int x; + if (1) x = 1; else x = 2; + pn(x); + return 0; +} +// zc0: skip diff --git a/tests/conformance/4-statements/uninit_branch_rejected.zc b/tests/conformance/4-statements/uninit_branch_rejected.zc new file mode 100644 index 0000000..ca93c39 --- /dev/null +++ b/tests/conformance/4-statements/uninit_branch_rejected.zc @@ -0,0 +1,10 @@ +// expect error: used before it is initialized +// spec 4.1.5: a local set on only some branches is unset at the join +include rt; +fn main() { + int x; + if (0) x = 1; + rt.put_n(x); + return 0; +} +// zc0: skip diff --git a/tests/conformance/4-statements/uninit_do_loop_ok.zc b/tests/conformance/4-statements/uninit_do_loop_ok.zc new file mode 100644 index 0000000..4f09302 --- /dev/null +++ b/tests/conformance/4-statements/uninit_do_loop_ok.zc @@ -0,0 +1,12 @@ +// expect: 1/ +// spec 4.1.5: do/while always runs once, so an assignment in the body initializes +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { + int x; + int n = 0; + do { x = 1; n = 0; } while (n); + pn(x); + return 0; +} +// zc0: skip diff --git a/tests/conformance/4-statements/uninit_loop_rejected.zc b/tests/conformance/4-statements/uninit_loop_rejected.zc new file mode 100644 index 0000000..67d8120 --- /dev/null +++ b/tests/conformance/4-statements/uninit_loop_rejected.zc @@ -0,0 +1,11 @@ +// expect error: used before it is initialized +// spec 4.1.5: a loop that may run zero times does not initialize +include rt; +fn main() { + int x; + int n = 0; + while (n) x = 1; + rt.put_n(x); + return 0; +} +// zc0: skip diff --git a/tests/conformance/4-statements/uninit_outparam_agg_ok.zc b/tests/conformance/4-statements/uninit_outparam_agg_ok.zc new file mode 100644 index 0000000..75ba07d --- /dev/null +++ b/tests/conformance/4-statements/uninit_outparam_agg_ok.zc @@ -0,0 +1,13 @@ +// expect: 5/ +// spec 4.1.5: &aggregate counts as initializing the whole aggregate +include rt; +struct point { int x; int y; } +void pn(int x) { rt.put_n(x); rt.put_c(10); } +void fill(point* p) { p->x = 2; p->y = 3; } +fn main() { + point p; + fill(&p); + pn(p.x + p.y); + return 0; +} +// zc0: skip diff --git a/tests/conformance/4-statements/uninit_outparam_ok.zc b/tests/conformance/4-statements/uninit_outparam_ok.zc new file mode 100644 index 0000000..e97f54b --- /dev/null +++ b/tests/conformance/4-statements/uninit_outparam_ok.zc @@ -0,0 +1,12 @@ +// expect: 7/ +// spec 4.1.5: passing &x counts as initializing x +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +void fill(int* p) { *p = 7; } +fn main() { + int x; + fill(&x); + pn(x); + return 0; +} +// zc0: skip diff --git a/tests/conformance/4-statements/uninit_partial_struct_rejected.zc b/tests/conformance/4-statements/uninit_partial_struct_rejected.zc new file mode 100644 index 0000000..9c71f92 --- /dev/null +++ b/tests/conformance/4-statements/uninit_partial_struct_rejected.zc @@ -0,0 +1,11 @@ +// expect error: used before it is initialized +// spec 4.1.5: writing some fields does not initialize the aggregate +include rt; +struct point { int x; int y; } +fn main() { + point p; + p.x = 1; + rt.put_n(p.y); + return 0; +} +// zc0: skip diff --git a/tests/conformance/4-statements/uninit_read_rejected.zc b/tests/conformance/4-statements/uninit_read_rejected.zc new file mode 100644 index 0000000..3ef407a --- /dev/null +++ b/tests/conformance/4-statements/uninit_read_rejected.zc @@ -0,0 +1,5 @@ +// expect error: used before it is initialized +// spec 4.1.5: reading a local before any assignment is an error +include rt; +fn main() { int x; rt.put_n(x); return 0; } +// zc0: skip diff --git a/tests/conformance/4-statements/uninit_struct_init_ok.zc b/tests/conformance/4-statements/uninit_struct_init_ok.zc new file mode 100644 index 0000000..ab033ae --- /dev/null +++ b/tests/conformance/4-statements/uninit_struct_init_ok.zc @@ -0,0 +1,11 @@ +// expect: 9/ +// spec 4.1.5: while(1) always enters, so an assignment before break initializes +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { + int x; + while (1) { x = 9; break; } + pn(x); + return 0; +} +// zc0: skip |
