source: tests/array-collections/c-dependent.cfa@ 8403b32

Last change on this file since 8403b32 was fc9d167, checked in by Michael Brooks <mlbrooks@…>, 5 days ago

Slightly loosen a test that has failed on 32-bit build lately.

Since 16d9c3a, this test was failing on all builds. The present change in not 32-bit specific; it's expected to fix this particular test, on all builds.

Note there are further 32-bit issues remaining, even after this fix.

Test is: array-collections/c-dependent

Loosening is: Adjust test's scope to avoid exercising "truly incorrect" C code; which may receive compile-time array-bound warnings on sufficiently advanced C compilers. In test code and .expect, switch from passing incorrect bounds to passing correct bounds; the point of the test (newly clarified, always foremost) is that CFA handles C's dependently sized VLA parameter.

  • Property mode set to 100644
File size: 1.7 KB
Line 
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
11void iota1( size_t n, float * a, float base ) {
12 for (i; n) {
13 a[i] = base + 0.1f * (float)(i + 1);
14 }
15}
16
17void 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] );
19}
20void bound_ptr_allow() {
21 float a[42];
22 iota1( 42, a, 1.0 );
23 f__bound_ptr_allow( 42, a ); // pass actual size (42) ==> bounds ok
24}
25
26// note dimension `n + 1`, exercising nontrivial dim-expression
27void f__bound_ar_allow( size_t n, float a[][n + 1] ) {
28 printf( "bound_ar_allow %zd:\n", n );
29 printf( "%.1f %.1f %.1f\n", a[0][0], a[0][1], a[0][2] );
30 printf( "%.1f %.1f %.1f\n", a[1][0], a[1][1], a[1][2] );
31 printf( "%.1f %.1f %.1f\n", a[2][0], a[2][1], a[2][2] );
32}
33void bound_ar_allow() {
34 float a[3][42];
35 iota1( 42, a[0], 1.0 );
36 iota1( 42, a[1], 2.0 );
37 iota1( 42, a[2], 3.0 );
38 f__bound_ar_allow( 41, a ); // n == 41 ==> len(a) == 42 => bounds ok
39}
40
41
42int main() {
43 bound_ptr_allow();
44 bound_ar_allow();
45
46 return 0;
47}
Note: See TracBrowser for help on using the repository browser.