From 85f6fad3a6acbfa07a3dc45b673965fc26890d8e Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Thu, 25 Oct 2012 18:07:13 +0200 Subject: [PATCH] Forbid VLA as static variables Currently, VLA are not forbidden for static variable. This leads to problems even if for fixed-size array when the size expression uses the ternary operator (cond ? then-value : else-value) because it is parsed as a general expression which leads to code generated in this case. This commit solve the problem by forbidding VLA for static variables. Although not required for the fix, avoiding code generation when the expression is constant would be a nice addition though. --- tccgen.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tccgen.c b/tccgen.c index 71d0809..2f6e458 100644 --- a/tccgen.c +++ b/tccgen.c @@ -3250,7 +3250,7 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td) { Sym *s; CType type1, *type2; - int qualifiers, storage; + int qualifiers, storage, saved_nocode_wanted; while (tok == '*') { qualifiers = 0; @@ -3304,7 +3304,12 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td) } storage = type->t & VT_STORAGE; type->t &= ~VT_STORAGE; + if (storage & VT_STATIC) { + saved_nocode_wanted = nocode_wanted; + nocode_wanted = 1; + } post_type(type, ad); + nocode_wanted = saved_nocode_wanted; type->t |= storage; if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2) parse_attribute(ad);