From a80acab4fc15c3df6c062191d486518645557d2e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Gl=C3=B6ckner?= Date: Thu, 11 Sep 2008 21:04:22 +0200 Subject: [PATCH] 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. --- tcc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tcc.c b/tcc.c index cd9048a1..62062e10 100644 --- a/tcc.c +++ b/tcc.c @@ -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) { -- 2.11.4.GIT