// -*- Mode: C -*- // // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // array.cfa -- test array declarations // // Author : Peter A. Buhr // Created On : Tue Feb 19 21:18:06 2019 // Last Modified By : Peter A. Buhr // Last Modified On : Sat Jun 5 10:05:51 2021 // Update Count : 5 // // Tests syntax. Comments explain semantics. Test does not show semantics. // Mostly illustrates facts about C (with which CFA is being tested to agree). // Is a test oracle under `gcc -x c`. #ifdef ERR1 #define E1(...) __VA_ARGS__ #else #define E1(...) #endif #ifdef ERR2 #define E2(...) __VA_ARGS__ #else #define E2(...) #endif #ifdef ERR3 #define E3(...) __VA_ARGS__ #else #define E3(...) #endif int a1[0]; E1( int a2[*]; ) #ifndef __cforall E1( double a4[3.0]; ) // BUG 275: CFA accepts but should reject #endif int m1[0][3]; E1( int m2[*][*]; ) int m4[3][3]; typedef int T; int fred(int n) { E1( int a1[]; ) E1( int a2[*]; ) int a4[3]; int T[3]; int a5[n]; } int fred2(int n, int a1[], E1( int a2[*], ) int a4[3], int T[3], int a5[n] ) {} int mary( int T[3], // same as: int *T int p1[const 3], // same as: int const *p1 int p2[static 3], // same as T, but length >=3 checked int p3[static const 3] // both above: 3 is static, p3 is const ) { } // function taking (), returning pointer to array of ints int (*tom())[3] { } // function taking (), returning pointer to function of same type as mary int (*(jane)())( int T[3], int p1[const 3], int p2[static 3], int p3[static const 3] ) { } // functions returning same exotic pointers, in CFA's non-onion syntax #ifdef __cforall [ * [3] int ] toms_twin(...) { } [ * [int]( [3] int T, [const 3] int p1, [static 3] int p2, [static const 3] int p3 ) ] janes_twin(...) { } #endif // GCC 11+ gives a false warning (-Wvla-parameter) on the valid (C11 ARM p134-135) combination: // declare with type int[*], define with type int[n]. // https://gcc.gnu.org/bugzilla//show_bug.cgi?id=100420 suggests the internal representation of // of a[*] is the same as a[0]. // https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-vla-parameter explains // the purpose of -Wvla-parameter is to report conflicts between int[] and int[n], which would // understandably also include those between int[42] and int[n]. // https://stackoverflow.com/questions/17371645/why-use-an-asterisk-instead-of-an-integer-for-a-vla-array-parameter-of-a-f // explains the declare-*, define-n pattern. // To work around the false warning, and keep to this test's purpose of exercising CFA's // handling of exotic C array syntax, what would ideally be demonstrated as a declaration of // fm1, followed by its definition, is instead split into fm1x and fm1y. And similarly for // fm5. int fm1x( int, int, int[][*] ); int fm1y( int r, int c, int m[][c] ) {} int fm2( int r, int c, int (*m)[c] ) {} // same as fm1 E2( int fm3( int r, int c, int m[][static c] ) {} ) // that's not static E3( int fm4( int r, int c, int m[][] ); ) // m's immediate element type is incomplete int fm5x( int, int, int[*][*] ); // same as fm1 decl int fm5y( int r, int c, int m[r][c] ) {} // same as fm1 defn int main() { #pragma GCC warning "Preprocessor started" // force non-empty .expect file, NO TABS!!! } // Local Variables: // // tab-width: 4 // // compile-command: "cfa array.cfa" // // End: //