| Last change
 on this file since 1cc5c6a was             81e768d, checked in by Michael Brooks <mlbrooks@…>, 11 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 casestests/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])tovoid (*)(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:
            861 bytes | 
      
      
| Line |  | 
|---|
| 1 | void iota1( int n, float * a, float base ) { | 
|---|
| 2 | for (i; n) { | 
|---|
| 3 | a[i] = base + 0.1f * (float)(i + 1); | 
|---|
| 4 | } | 
|---|
| 5 | } | 
|---|
| 6 |  | 
|---|
| 7 | void f__bound_ptr_allow( int n, float a[n] ) { | 
|---|
| 8 | printf( "bound_ptr_allow %d: %.1f %.1f %.1f\n", n, a[0], a[1], a[2] ); | 
|---|
| 9 | } | 
|---|
| 10 | void bound_ptr_allow() { | 
|---|
| 11 | float a[42]; | 
|---|
| 12 | iota1( 42, a, 1.0 ); | 
|---|
| 13 | f__bound_ptr_allow( 999, a ); | 
|---|
| 14 | } | 
|---|
| 15 |  | 
|---|
| 16 | void f__bound_ar_allow( int n, float a[][n + 1] ) { | 
|---|
| 17 | printf( "bound_ar_allow %d:\n", n ); | 
|---|
| 18 | printf( "%.1f %.1f %.1f\n", a[0][0], a[0][1], a[0][2] ); | 
|---|
| 19 | printf( "%.1f %.1f %.1f\n", a[1][0], a[1][1], a[1][2] ); | 
|---|
| 20 | printf( "%.1f %.1f %.1f\n", a[2][0], a[2][1], a[2][2] ); | 
|---|
| 21 | } | 
|---|
| 22 | void bound_ar_allow() { | 
|---|
| 23 | float a[3][42]; | 
|---|
| 24 | iota1( 42, a[0], 1.0 ); | 
|---|
| 25 | iota1( 42, a[1], 2.0 ); | 
|---|
| 26 | iota1( 42, a[2], 3.0 ); | 
|---|
| 27 | f__bound_ar_allow( 41, a ); | 
|---|
| 28 | } | 
|---|
| 29 |  | 
|---|
| 30 |  | 
|---|
| 31 | int main() { | 
|---|
| 32 | bound_ptr_allow(); | 
|---|
| 33 | bound_ar_allow(); | 
|---|
| 34 |  | 
|---|
| 35 | return 0; | 
|---|
| 36 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.