Last change
on this file since 28c2c9d5 was 81e768d, checked in by Michael Brooks <mlbrooks@…>, 10 months ago |
Fix #276; add support for c-array parameters using dependent lengths.
Without this fix, declarations like
void f( int m, int n, float[m][n] );
would either
- generate bad C code, with unmangled variable names appearing in the function definition, or
- refuse to resolve a valid-c call of such a function.
tests/array-collections/c-dependent: add direct tests of such cases
tests/tuplearray: activate and expand cases which were blocked on #276
tests/array: activate case fm5y, which was blocked on #276; [noise] adjust source line numbers in .expect
tests/typedefRedef: expand coverage of "error, an array detail is different" cases; [noise] adjust source line numbers in .expect
tests/functions: [noise] adjust .expect to have resolved array sizes (extra casts) in the diffed code dump
The fix is:
- (ResolvExpr/ResolveTypeof, ResolvExpr/Resolver) Resolve the dimension expressions, where they were missed.
- (ResolvExpr/Resolver) Prevent dimension expressions that are bound to other parameters from escaping in the function's type, to where they are out of scope. In the f example above, redact the type shown to callers from
void (*)(int, int, float[m][n]) to void (*)(int, int, float[][*]) .
- (ResolvExpr/Unify) Relax the matching rules for such a type, when used at a call site, letting the patameters wildcard type match with the concrete type in scope at the caller's side.
- (Validate/ReplaceTypedef) Apply the former, stricter matching rules to the one place where they are still needed: detecting inconsistent typedefs.
|
-
Property mode
set to
100644
|
File size:
1.6 KB
|
Line | |
---|
1 | typedef volatile struct Foo FooInterm;
|
---|
2 | typedef const FooInterm Foo;
|
---|
3 | #ifdef ERR1
|
---|
4 | typedef struct Foo Foo;
|
---|
5 | #endif
|
---|
6 |
|
---|
7 | typedef int ** pt;
|
---|
8 | typedef int ** pt;
|
---|
9 |
|
---|
10 | #ifdef __CFA__
|
---|
11 | extern "C" {
|
---|
12 | #endif
|
---|
13 | typedef int __io_read_fn ( char buf);
|
---|
14 | typedef int __io_write_fn ( const char buf);
|
---|
15 |
|
---|
16 |
|
---|
17 | __io_read_fn read;
|
---|
18 | __io_write_fn write;
|
---|
19 | #ifdef __CFA__
|
---|
20 | }
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | int sz;
|
---|
24 | typedef int FUNC(int, ...);
|
---|
25 | typedef int FUNC(int, ...);
|
---|
26 |
|
---|
27 | typedef int ARR[];
|
---|
28 | typedef int ARR[];
|
---|
29 | #ifdef ERR1
|
---|
30 | // if a typedef has an array dimension, it can only be redefined to the same dimension
|
---|
31 | typedef int ARR[2];
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | typedef [ float[], char[], int[] ] ARRSa;
|
---|
35 | typedef [ float[], char[], int[] ] ARRSa;
|
---|
36 | #ifdef ERR1
|
---|
37 | typedef [ float[], char[2], int[] ] ARRSa;
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | typedef int ARRSb[][1][2][3];
|
---|
41 | typedef int ARRSb[][1][2][3];
|
---|
42 | #ifdef ERR1
|
---|
43 | typedef int ARRSb[][1][2][99];
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | typedef int X;
|
---|
47 | typedef int Y;
|
---|
48 | typedef Y Y2;
|
---|
49 | typedef X X2;
|
---|
50 |
|
---|
51 | typedef Y2 Z;
|
---|
52 | typedef X2 Z;
|
---|
53 |
|
---|
54 | typedef Z X2;
|
---|
55 | typedef int X2;
|
---|
56 | typedef Z X2;
|
---|
57 | typedef int X2;
|
---|
58 |
|
---|
59 | X2 value __attribute__((aligned(4 * sizeof(X2))));
|
---|
60 |
|
---|
61 | __attribute__((aligned(4 * sizeof(X2)))) struct rseq_cs {
|
---|
62 | int foo;
|
---|
63 | };
|
---|
64 |
|
---|
65 | // xxx - this doesn't work yet due to parsing problems with generic types
|
---|
66 | // #ifdef __CFA__
|
---|
67 | // typedef forall(type T) void foo(T);
|
---|
68 | // typedef forall(type T) void foo(T);
|
---|
69 | // typedef forall(type S) void foo(S); // should be allowed to do this...
|
---|
70 | // #endif
|
---|
71 |
|
---|
72 | int main() {
|
---|
73 | typedef int ARR[sz];
|
---|
74 |
|
---|
75 | // can't redefine typedef which is VLA
|
---|
76 | #if ERR1
|
---|
77 | typedef int ARR[sz];
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | Foo * x;
|
---|
81 |
|
---|
82 | typedef struct Bar Foo;
|
---|
83 | Foo * y;
|
---|
84 |
|
---|
85 | typedef int *** pt;
|
---|
86 |
|
---|
87 | #pragma GCC warning "Compiled" // force non-empty .expect file, NO TABS!!!
|
---|
88 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.