History

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.

Thomas Preud'homme committed 14 years ago

Commit 85f6fad1 parent 9966fd41 file · +6 −1Browse files

Unified · Split

tccgen.c+6−1
@@ -3250,7 +3250,7 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td) · 3249 unmodified lines
3250{3250{
3251 Sym *s;3251 Sym *s;
3252 CType type1, *type2;3252 CType type1, *type2;
3253 int qualifiers, storage;3253 int qualifiers, storage, saved_nocode_wanted;
3254 3254
3255 while (tok == '*') {3255 while (tok == '*') {
3256 qualifiers = 0;3256 qualifiers = 0;
@@ -3304,7 +3304,12 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td) · 47 unmodified lines
3304 }3304 }
3305 storage = type->t & VT_STORAGE;3305 storage = type->t & VT_STORAGE;
3306 type->t &= ~VT_STORAGE;3306 type->t &= ~VT_STORAGE;
3307 if (storage & VT_STATIC) {
3308 saved_nocode_wanted = nocode_wanted;
3309 nocode_wanted = 1;
3310 }
3307 post_type(type, ad);3311 post_type(type, ad);
3312 nocode_wanted = saved_nocode_wanted;
3308 type->t |= storage;3313 type->t |= storage;
3309 if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2)3314 if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2)
3310 parse_attribute(ad);3315 parse_attribute(ad);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t