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.
master
Thomas Preud'homme 2012-10-25 18:07:13 +02:00
parent 9966fd4eae
commit 85f6fad3a6
1 changed files with 6 additions and 1 deletions

View File

@ -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);