GNOME Bugzilla – Bug 733017
Valac produces incorrect C-Code without throwing an error
Last modified: 2018-05-22 15:12:36 UTC
Created attachment 280423 [details] Produced C-Code The following snippet produces incorrect C-Code: int main () { int vals[] = {}; vals += 1; //avoid unused variable warning return 0; } Vala itself produces no error, it's the GCC that does. This example might not be valid Vala syntax but the produced errors are horrible: marius@marius-VB:~/temp$ valac error.vala /home/marius/temp/error.vala.c: In function ‘_vala_array_add1’: /home/marius/temp/error.vala.c:22:3: warning: passing argument 1 of ‘g_realloc_n’ makes pointer from integer without a cast [enabled by default] *array = g_renew (gint, *array, *size); ^ In file included from /usr/include/glib-2.0/glib/glist.h:32:0, from /usr/include/glib-2.0/glib/ghash.h:33, from /usr/include/glib-2.0/glib.h:50, from /home/marius/temp/error.vala.c:9: /usr/include/glib-2.0/glib/gmem.h:97:10: note: expected ‘gpointer’ but argument is of type ‘gint’ gpointer g_realloc_n (gpointer mem, ^ /home/marius/temp/error.vala.c:22:10: warning: assignment makes integer from pointer without a cast [enabled by default] *array = g_renew (gint, *array, *size); ^ /home/marius/temp/error.vala.c:24:10: error: subscripted value is neither array nor pointer nor vector (*array)[(*length)++] = value; ^ /home/marius/temp/error.vala.c: In function ‘_vala_main’: /home/marius/temp/error.vala.c:30:2: error: invalid initializer gint vals[] = NULL; ^ /home/marius/temp/error.vala.c:35:7: error: incompatible types when assigning to type ‘gint[1]’ from type ‘gint *’ vals = _tmp0_; ^ /home/marius/temp/error.vala.c:38:2: warning: passing argument 1 of ‘_vala_array_add1’ from incompatible pointer type [enabled by default] _vala_array_add1 (&vals, &vals_length1, &_vals_size_, 1); ^ /home/marius/temp/error.vala.c:19:13: note: expected ‘gint *’ but argument is of type ‘gint (*)[1]’ static void _vala_array_add1 (gint* array, int* length, int* size, gint value) { ^ /home/marius/temp/error.vala.c:40:7: error: incompatible types when assigning to type ‘gint[1]’ from type ‘void *’ vals = (g_free (vals), NULL); ^ /home/marius/temp/error.vala.c: In function ‘main’: /home/marius/temp/error.vala.c:46:2: warning: ‘g_type_init’ is deprecated (declared at /usr/include/glib-2.0/gobject/gtype.h:667) [-Wdeprecated-declarations] g_type_init (); ^ error: cc exited with status 256 Compilation failed: 1 error(s), 0 warning(s)
Thanks for the report. In theory it should be correct code. The length of the fixed array should be decided by the compiler itself. In practice something the implementation does not cover this case.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/459.