[6ca0dab] | 1 | // -*- Mode: C -*- |
---|
| 2 | // |
---|
[2ede686] | 3 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
| 4 | // |
---|
| 5 | // The contents of this file are covered under the licence agreement in the |
---|
| 6 | // file "LICENCE" distributed with Cforall. |
---|
[6ca0dab] | 7 | // |
---|
[2ede686] | 8 | // array.cfa -- test array declarations |
---|
[6ca0dab] | 9 | // |
---|
[2ede686] | 10 | // Author : Peter A. Buhr |
---|
| 11 | // Created On : Tue Feb 19 21:18:06 2019 |
---|
| 12 | // Last Modified By : Peter A. Buhr |
---|
[53692b3] | 13 | // Last Modified On : Sat Jun 5 10:05:51 2021 |
---|
| 14 | // Update Count : 5 |
---|
[6ca0dab] | 15 | // |
---|
[2ede686] | 16 | |
---|
[a5aa5bf] | 17 | // Tests syntax. Comments explain semantics. Test does not show semantics. |
---|
| 18 | // Mostly illustrates facts about C (with which CFA is being tested to agree). |
---|
| 19 | // Is a test oracle under `gcc -x c`. |
---|
[62edde5] | 20 | |
---|
[a5aa5bf] | 21 | #ifdef ERR1 |
---|
| 22 | #define E1(...) __VA_ARGS__ |
---|
| 23 | #else |
---|
| 24 | #define E1(...) |
---|
| 25 | #endif |
---|
[62edde5] | 26 | |
---|
[a5aa5bf] | 27 | #ifdef ERR2 |
---|
| 28 | #define E2(...) __VA_ARGS__ |
---|
| 29 | #else |
---|
| 30 | #define E2(...) |
---|
| 31 | #endif |
---|
[62edde5] | 32 | |
---|
[a5aa5bf] | 33 | #ifdef ERR3 |
---|
| 34 | #define E3(...) __VA_ARGS__ |
---|
| 35 | #else |
---|
| 36 | #define E3(...) |
---|
| 37 | #endif |
---|
[62edde5] | 38 | |
---|
[8a919cf] | 39 | int a1[0]; |
---|
[a5aa5bf] | 40 | E1( int a2[*]; ) |
---|
| 41 | #ifndef __cforall |
---|
| 42 | E1( double a4[3.0]; ) // BUG 275: CFA accepts but should reject |
---|
| 43 | #endif |
---|
[62edde5] | 44 | |
---|
[8a919cf] | 45 | int m1[0][3]; |
---|
| 46 | E1( int m2[*][*]; ) |
---|
| 47 | int m4[3][3]; |
---|
| 48 | |
---|
| 49 | typedef int T; |
---|
| 50 | |
---|
| 51 | int fred(int n) { |
---|
| 52 | E1( int a1[]; ) |
---|
| 53 | E1( int a2[*]; ) |
---|
| 54 | int a4[3]; |
---|
| 55 | int T[3]; |
---|
| 56 | int a5[n]; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | int mary( int T[3], // same as: int *T |
---|
| 60 | int p1[const 3], // same as: int const *p1 |
---|
| 61 | int p2[static 3], // same as T, but length >=3 checked |
---|
| 62 | int p3[static const 3] // both above: 3 is static, p3 is const |
---|
| 63 | ) { |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | // function taking (), returning pointer to array of ints |
---|
| 67 | int (*tom())[3] { |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | // function taking (), returning pointer to function of same type as mary |
---|
| 71 | int (*(jane)())( int T[3], |
---|
| 72 | int p1[const 3], |
---|
| 73 | int p2[static 3], |
---|
| 74 | int p3[static const 3] |
---|
| 75 | ) { |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | // functions returning same exotic pointers, in CFA's non-onion syntax |
---|
| 79 | #ifdef __cforall |
---|
| 80 | [ * [3] int ] toms_twin(...) { |
---|
| 81 | } |
---|
| 82 | [ * [int]( [3] int T, |
---|
[7ae39f0] | 83 | [const 3] int p1, |
---|
| 84 | [static 3] int p2, |
---|
| 85 | [static const 3] int p3 |
---|
| 86 | ) |
---|
[8a919cf] | 87 | ] janes_twin(...) { |
---|
| 88 | } |
---|
| 89 | #endif |
---|
| 90 | |
---|
[7ae39f0] | 91 | // GCC 11+ gives a false warning (-Wvla-parameter) on the valid (C11 ARM p134-135) combination: |
---|
| 92 | // declare with type int[*], define with type int[n]. |
---|
| 93 | // https://gcc.gnu.org/bugzilla//show_bug.cgi?id=100420 suggests the internal representation of |
---|
| 94 | // of a[*] is the same as a[0]. |
---|
| 95 | // https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-vla-parameter explains |
---|
| 96 | // the purpose of -Wvla-parameter is to report conflicts between int[] and int[n], which would |
---|
| 97 | // understandably also include those between int[42] and int[n]. |
---|
| 98 | // https://stackoverflow.com/questions/17371645/why-use-an-asterisk-instead-of-an-integer-for-a-vla-array-parameter-of-a-f |
---|
| 99 | // explains the declare-*, define-n pattern. |
---|
| 100 | |
---|
| 101 | // To work around the false warning, and keep to this test's purpose of exercising CFA's |
---|
| 102 | // handling of exotic C array syntax, what would ideally be demonstrated as a declaration of |
---|
| 103 | // fm1, followed by its definition, is instead split into fm1x and fm1y. And similarly for |
---|
| 104 | // fm5. |
---|
| 105 | |
---|
| 106 | int fm1x( int, int, int[][*] ); |
---|
| 107 | int fm1y( int r, int c, int m[][c] ) {} |
---|
[8a919cf] | 108 | int fm2( int r, int c, int (*m)[c] ) {} // same as fm1 |
---|
| 109 | E2( int fm3( int r, int c, int m[][static c] ) {} ) // that's not static |
---|
| 110 | E3( int fm4( int r, int c, int m[][] ); ) // m's immediate element type is incomplete |
---|
[7ae39f0] | 111 | int fm5x( int, int, int[*][*] ); // same as fm1 decl |
---|
[a5aa5bf] | 112 | #ifndef __cforall |
---|
[7ae39f0] | 113 | int fm5y( int r, int c, int m[r][c] ) {} // BUG 276: CFA chokes but should accept |
---|
[8a919cf] | 114 | // C: same as fm1 defn |
---|
[a5aa5bf] | 115 | #endif |
---|
[62edde5] | 116 | |
---|
| 117 | |
---|
[66812dd] | 118 | int main() { |
---|
[a5aa5bf] | 119 | #pragma GCC warning "Preprocessor started" // force non-empty .expect file, NO TABS!!! |
---|
[66812dd] | 120 | } |
---|
[2ede686] | 121 | |
---|
| 122 | // Local Variables: // |
---|
| 123 | // tab-width: 4 // |
---|
| 124 | // compile-command: "cfa array.cfa" // |
---|
| 125 | // End: // |
---|