summaryrefslogtreecommitdiff
path: root/tests/arrays
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2020-03-18 14:05:13 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2020-03-18 14:05:13 +0100
commitb95a766454eb914f4eb5a68e9040e03faffabf52 (patch)
treef8f34ebf108a5b7f7c5b09ad9bcab0a2eaa9fe2e /tests/arrays
parent5a97fa5a1b56e3a942f01d21efc203da25187d03 (diff)
downloadvala-b95a766454eb914f4eb5a68e9040e03faffabf52.tar.gz
codegen: Use memset to initialize inline-allocated array with non-constant size
In addition to a0bb129e5a2e8580eb272d9a68ba054e7b170dba Fixes https://gitlab.gnome.org/GNOME/vala/issues/910
Diffstat (limited to 'tests/arrays')
-rw-r--r--tests/arrays/fixed-length-init0-not-allowed.vala54
1 files changed, 45 insertions, 9 deletions
diff --git a/tests/arrays/fixed-length-init0-not-allowed.vala b/tests/arrays/fixed-length-init0-not-allowed.vala
index 932f011b3..9cb8a43a7 100644
--- a/tests/arrays/fixed-length-init0-not-allowed.vala
+++ b/tests/arrays/fixed-length-init0-not-allowed.vala
@@ -1,13 +1,49 @@
+const int BAR = 1024;
+
void main () {
- const int FOO = 4;
+ {
+ const int FOO = 4;
+
+ char bar[FOO] = { 'f', 'o', 'o', '\0' };
+ assert ((string) bar == "foo");
+
+ char baz[FOO];
+ baz[0] = 'f';
+ baz[1] = 'o';
+ baz[2] = 'o';
+ baz[3] = '\0';
+ assert ((string) baz == "foo");
+ }
+ {
+ const int FOO = 1024;
+
+ string foo[FOO];
+
+ assert (foo[0] == null);
+ assert (foo[FOO / 2] == null);
+ assert (foo[FOO - 1] == null);
+ }
+ {
+ const int FOO = 1024;
+
+ string array[16 * FOO];
+
+ assert (array[0] == null);
+ assert (array[16 * FOO / 2] == null);
+ assert (array[16 * FOO - 1] == null);
+ }
+ {
+ string array[BAR];
- char bar[FOO] = { 'f', 'o', 'o', '\0' };
- assert ((string) bar == "foo");
+ assert (array[0] == null);
+ assert (array[BAR / 2] == null);
+ assert (array[BAR - 1] == null);
+ }
+ {
+ string array[16 * BAR];
- char baz[FOO];
- baz[0] = 'f';
- baz[1] = 'o';
- baz[2] = 'o';
- baz[3] = '\0';
- assert ((string) baz == "foo");
+ assert (array[0] == null);
+ assert (array[16 * BAR / 2] == null);
+ assert (array[16 * BAR - 1] == null);
+ }
}