This patch makes tcc ignore them. Normally (as per the C standard), They should be only applicable inside parameter arrays and affect (const/restrict) the pointer the array gets converted to. [matz: fix formatting, add volatile handling, add testcase, add comment about above deficiency]
Unified · Split
| @@ -4348,8 +4348,23 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) · 4347 unmodified lines | |||
| 4348 | int saved_nocode_wanted = nocode_wanted; | 4348 | int saved_nocode_wanted = nocode_wanted; |
| 4349 | /* array definition */ | 4349 | /* array definition */ |
| 4350 | next(); | 4350 | next(); |
| 4351 | if (tok == TOK_RESTRICT1) | 4351 | while (1) { |
| 4352 | next(); | 4352 | /* XXX The optional type-quals and static should only be accepted |
| 4353 | in parameter decls. The '*' as well, and then even only | ||
| 4354 | in prototypes (not function defs). */ | ||
| 4355 | switch (tok) { | ||
| 4356 | case TOK_RESTRICT1: case TOK_RESTRICT2: case TOK_RESTRICT3: | ||
| 4357 | case TOK_CONST1: | ||
| 4358 | case TOK_VOLATILE1: | ||
| 4359 | case TOK_STATIC: | ||
| 4360 | case '*': | ||
| 4361 | next(); | ||
| 4362 | continue; | ||
| 4363 | default: | ||
| 4364 | break; | ||
| 4365 | } | ||
| 4366 | break; | ||
| 4367 | } | ||
| 4353 | n = -1; | 4368 | n = -1; |
| 4354 | t1 = 0; | 4369 | t1 = 0; |
| 4355 | if (tok != ']') { | 4370 | if (tok != ']') { |
| @@ -0,0 +1,34 @@ | |||
| 1 | void foo(int [5]); | ||
| 2 | void fooc(int x[const 5]); | ||
| 3 | void foos(int x[static 5]); | ||
| 4 | void foov(int x[volatile 5]); | ||
| 5 | void foor(int x[restrict 5]); | ||
| 6 | void fooc(int [const 5]); | ||
| 7 | void foos(int [static 5]); | ||
| 8 | void foov(int [volatile 5]); | ||
| 9 | void foor(int [restrict 5]); | ||
| 10 | void fooc(int (* const x)); | ||
| 11 | void foos(int *x); | ||
| 12 | void foov(int * volatile x); | ||
| 13 | void foor(int * restrict x); | ||
| 14 | void fooc(int x[volatile 5]) | ||
| 15 | { | ||
| 16 | x[3] = 42; | ||
| 17 | #ifdef INVALID | ||
| 18 | x = 0; | ||
| 19 | #endif | ||
| 20 | } | ||
| 21 | void foovm(int x[const *]); | ||
| 22 | void foovm(int * const x); | ||
| 23 | #ifdef INVALID | ||
| 24 | void wrongc(int x[3][const 4]); | ||
| 25 | void wrongvm(int x[static *]); | ||
| 26 | void foovm(int x[const *]) | ||
| 27 | { | ||
| 28 | x[2] = 1; | ||
| 29 | } | ||
| 30 | #endif | ||
| 31 | int main() | ||
| 32 | { | ||
| 33 | return 0; | ||
| 34 | } | ||
Empty file added.