History

Don't fail on const/restrict/static/* inside []

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]

Petr Skocik committed 8 years ago

Commit ef668aa1 parent d6d3cf03 files · +51 −2Browse files

Unified · Split

3 files
  1. tccgen.c +17 −2
  2. tests/tests2/100_c99array-decls.c +34 −0
  3. tests/tests2/100_c99array-decls.expect +0 −0
tccgen.c+17−2
@@ -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 != ']') {
tests/tests2/100_c99array-decls.c+34−0
@@ -0,0 +1,34 @@
1void foo(int [5]);
2void fooc(int x[const 5]);
3void foos(int x[static 5]);
4void foov(int x[volatile 5]);
5void foor(int x[restrict 5]);
6void fooc(int [const 5]);
7void foos(int [static 5]);
8void foov(int [volatile 5]);
9void foor(int [restrict 5]);
10void fooc(int (* const x));
11void foos(int *x);
12void foov(int * volatile x);
13void foor(int * restrict x);
14void fooc(int x[volatile 5])
15{
16 x[3] = 42;
17#ifdef INVALID
18 x = 0;
19#endif
20}
21void foovm(int x[const *]);
22void foovm(int * const x);
23#ifdef INVALID
24void wrongc(int x[3][const 4]);
25void wrongvm(int x[static *]);
26void foovm(int x[const *])
27{
28 x[2] = 1;
29}
30#endif
31int main()
32{
33 return 0;
34}
tests/tests2/100_c99array-decls.expect+0−0

Empty file added.

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