From 8b9697ca6b756af47eac153961abec70fd9dad6e Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sun, 19 Feb 2017 04:25:46 +0100 Subject: [PATCH] Fix bogus check for VT_LLOCAL types VT_LLOCAL is a flag on .r, not on type.t. Fixing this requires minor surgery for compound literals which accidentally happened to be subsumed by the bogus test. --- tccgen.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tccgen.c b/tccgen.c index 8aa86f3..8d54ade 100644 --- a/tccgen.c +++ b/tccgen.c @@ -4443,7 +4443,7 @@ ST_FUNC void unary(void) there and in function calls. */ /* arrays can also be used although they are not lvalues */ if ((vtop->type.t & VT_BTYPE) != VT_FUNC && - !(vtop->type.t & VT_ARRAY) && !(vtop->type.t & VT_LLOCAL)) + !(vtop->type.t & VT_ARRAY)) test_lvalue(); mk_pointer(&vtop->type); gaddrof(); @@ -5954,12 +5954,15 @@ static void parse_init_elem(int expr_type) global_expr = 1; expr_const1(); global_expr = saved_global_expr; - /* NOTE: symbols are accepted */ - if ((vtop->r & (VT_VALMASK | VT_LVAL)) != VT_CONST + /* NOTE: symbols are accepted, as well as lvalue for anon symbols + (compound literals). */ + if (((vtop->r & (VT_VALMASK | VT_LVAL)) != VT_CONST + && ((vtop->r & (VT_SYM|VT_LVAL)) != (VT_SYM|VT_LVAL) + || vtop->sym->v < SYM_FIRST_ANOM)) #ifdef TCC_TARGET_PE || (vtop->type.t & VT_IMPORT) #endif - ) + ) tcc_error("initializer element is not constant"); break; case EXPR_ANY: @@ -6711,6 +6714,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, /* push global reference */ sym = get_sym_ref(type, sec, addr, size); vpushsym(type, sym); + vtop->r |= r; } #ifdef CONFIG_TCC_BCHECK