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
32503250 {
32513251 Sym *s;
32523252 CType type1, *type2;
3253− int qualifiers, storage;
3253+ int qualifiers, storage, saved_nocode_wanted;
32543254
32553255 while (tok == '*') {
32563256 qualifiers = 0;
@@ -3304,7 +3304,12 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td) · 47 unmodified lines
33043304 }
33053305 storage = type->t & VT_STORAGE;
33063306 type->t &= ~VT_STORAGE;
3307+ if (storage & VT_STATIC) {
3308+ saved_nocode_wanted = nocode_wanted;
3309+ nocode_wanted = 1;
3310+ }
33073311 post_type(type, ad);
3312+ nocode_wanted = saved_nocode_wanted;
33083313 type->t |= storage;
33093314 if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2)
33103315 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