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
43484348 int saved_nocode_wanted = nocode_wanted;
43494349 /* array definition */
43504350 next();
4351− if (tok == TOK_RESTRICT1)
4352− next();
4351+ while (1) {
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+ }
43534368 n = -1;
43544369 t1 = 0;
43554370 if (tok != ']') {
tests/tests2/100_c99array-decls.c+34−0
@@ -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+}
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