Changeset 2fd3de7
- Timestamp:
- May 3, 2026, 8:29:09 AM (8 hours ago)
- Branches:
- master
- Children:
- 8403b32
- Parents:
- 3bfa80f (diff), fc9d167 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- tests/array-collections
- Files:
-
- 2 edited
-
.expect/c-dependent.txt (modified) (1 diff)
-
c-dependent.cfa (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/array-collections/.expect/c-dependent.txt
r3bfa80f r2fd3de7 1 bound_ptr_allow 999: 1.1 1.2 1.31 bound_ptr_allow 42: 1.1 1.2 1.3 2 2 bound_ar_allow 41: 3 3 1.1 1.2 1.3 -
tests/array-collections/c-dependent.cfa
r3bfa80f r2fd3de7 1 void iota1( int n, float * a, float base ) { 1 // Purpose: Demonstrate that aruably-dependent types, like `void (*)( size_t n, float[n] )`, 2 // which are valid in C, work also in CFA. It's a C-compatibility test. 3 // So, here we exercise code that a C compiler that omnisciently warns about bounds would accept. 4 5 // Note this test was once written with a broader intent, articulated after the fact as either of: 6 // - demonstrate how permissive this C-compatibility feature is, 7 // even though gcc continually works to clamp down in these areas 8 // - demonstrate that CFA lowering does not get in the way of C's warnings in these areas 9 // Current decision is these qualities (while desirable) are too fickle to be pursued practically. 10 11 void iota1( size_t n, float * a, float base ) { 2 12 for (i; n) { 3 13 a[i] = base + 0.1f * (float)(i + 1); … … 5 15 } 6 16 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] );17 void f__bound_ptr_allow( size_t n, float a[n] ) { 18 printf( "bound_ptr_allow %zd: %.1f %.1f %.1f\n", n, a[0], a[1], a[2] ); 9 19 } 10 20 void bound_ptr_allow() { 11 21 float a[42]; 12 22 iota1( 42, a, 1.0 ); 13 f__bound_ptr_allow( 999, a );23 f__bound_ptr_allow( 42, a ); // pass actual size (42) ==> bounds ok 14 24 } 15 25 16 void f__bound_ar_allow( int n, float a[][n + 1] ) { 17 printf( "bound_ar_allow %d:\n", n ); 26 // note dimension `n + 1`, exercising nontrivial dim-expression 27 void f__bound_ar_allow( size_t n, float a[][n + 1] ) { 28 printf( "bound_ar_allow %zd:\n", n ); 18 29 printf( "%.1f %.1f %.1f\n", a[0][0], a[0][1], a[0][2] ); 19 30 printf( "%.1f %.1f %.1f\n", a[1][0], a[1][1], a[1][2] ); … … 25 36 iota1( 42, a[1], 2.0 ); 26 37 iota1( 42, a[2], 3.0 ); 27 f__bound_ar_allow( 41, a ); 38 f__bound_ar_allow( 41, a ); // n == 41 ==> len(a) == 42 => bounds ok 28 39 } 29 40
Note:
See TracChangeset
for help on using the changeset viewer.