Valac produces incorrect C-Code without throwing an error
Submitted by Marius Gräfe
Link to original bug (#733017)
Description
Created attachment 280423 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)
Attachment 280423, "Produced C-Code":
error.c
Version: 0.22.x
Depends on
Edited by Rico Tzschichholz