Display error on statement expressions with complex return type

The return type of a statement expression (a GCC extention) may
involve elements on the symbol stack that have been put there by
the expression. These will be freed at the end of the expression
so that the calling block can not use them.

Contrary to the comment (written in 2003), this bug no longer shows
up in Valgrind, as freed symbols are now put onto a stack for later
reuse.
This commit is contained in:
Daniel Glöckner 2008-09-11 21:04:22 +02:00 committed by grischka
parent 3783b33508
commit a80acab4fc

14
tcc.c
View File

@ -8275,6 +8275,20 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
/* pop locally defined labels */
label_pop(&local_label_stack, llabel);
/* pop locally defined symbols */
if(is_expr) {
/* XXX: this solution makes only valgrind happy...
triggered by gcc.c-torture/execute/20000917-1.c */
Sym *p;
switch(vtop->type.t & VT_BTYPE) {
case VT_PTR:
case VT_STRUCT:
case VT_ENUM:
case VT_FUNC:
for(p=vtop->type.ref;p;p=p->prev)
if(p->prev==s)
error("unsupported expression type");
}
}
sym_pop(&local_stack, s);
next();
} else if (tok == TOK_RETURN) {