source: tests/array-collections/c-dependent.cfa@ 16d9c3a

Last change on this file since 16d9c3a was 16d9c3a, checked in by Michael Brooks <mlbrooks@…>, 11 hours ago

Strengthen a test that had been evading warnings on 64-bit only.

This test change is expected to break the 64-bit build (to match currently-broken 32-bit). A subsequet test change is expected to fix both builds.

This change makes a test, which was incorrectly architecture-specific, into one that is architecture-independent.

Test is: array-collections/c_dependent.

The relevant array-size warning occurs in gcc-11+ (new-gcc).

The test had been passing on 64-bit only because of a quirk: new-gcc's dependent warning gives false accept when a dimension expression is complex enough; CFA's (arch-specific) inserted casts interacted with an incidental choice of the test program, as follows:

original
void fbound_ptr_allow( int n, float a[n] );
source
void f
bound_ptr_allow( int n, float a[(unsigned long int) n] ); 64-bit lowering => different enough type, check skipped
void fbound_ptr_allow( int n, float a[(unsigned int) n] );
32-bit lowering => close enough type, check enforced

this change's revision
void fbound_ptr_allow( size_t n, float a[n] );
source
void f
bound_ptr_allow( unsigned long int n, float a[(unsigned long int) n] ); 64-bit lowering => close enough type, check enforced
void fbound_ptr_allow( unsigned int n, float a[(unsigned int) n] );
32-bit lowering => close enough type, check enforced

  • Property mode set to 100644
File size: 869 bytes
Line 
1void iota1( int n, float * a, float base ) {
2 for (i; n) {
3 a[i] = base + 0.1f * (float)(i + 1);
4 }
5}
6
7void f__bound_ptr_allow( size_t n, float a[n] ) {
8 printf( "bound_ptr_allow %zd: %.1f %.1f %.1f\n", n, a[0], a[1], a[2] );
9}
10void bound_ptr_allow() {
11 float a[42];
12 iota1( 42, a, 1.0 );
13 f__bound_ptr_allow( 999, a );
14}
15
16void f__bound_ar_allow( size_t n, float a[][n + 1] ) {
17 printf( "bound_ar_allow %zd:\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}
22void 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
31int main() {
32 bound_ptr_allow();
33 bound_ar_allow();
34
35 return 0;
36}
Note: See TracBrowser for help on using the repository browser.