| [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 |  | 
|---|
| [2853d6f] | 39 | int ga1[0]; | 
|---|
|  | 40 | E1( int ga2[*];       ) | 
|---|
| [a5aa5bf] | 41 | #ifndef __cforall | 
|---|
| [2853d6f] | 42 | E1( int ga3[3.0];  )                                  // BUG 275: CFA accepts but should reject | 
|---|
| [a5aa5bf] | 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 |  | 
|---|
| [2853d6f] | 51 | void fred(int n) { | 
|---|
|  | 52 | E1(     int a1[];   ) | 
|---|
|  | 53 | E1(     int a2[*];  ) | 
|---|
|  | 54 | int a4[3];      (void) a4; | 
|---|
|  | 55 | int T[3];       (void) T; | 
|---|
|  | 56 | int a5[n];      (void) a5; | 
|---|
| [8a919cf] | 57 | } | 
|---|
|  | 58 |  | 
|---|
| [2853d6f] | 59 | void fred2(int n, | 
|---|
| [81e768d] | 60 | int a1[], | 
|---|
| [2a32118] | 61 | E1(     int a2[*],  ) | 
|---|
| [81e768d] | 62 | int a4[3], | 
|---|
| [2853d6f] | 63 | int T[3]        __attribute__((unused)), | 
|---|
| [81e768d] | 64 | int a5[n] | 
|---|
| [2853d6f] | 65 | ) { | 
|---|
|  | 66 | // FIX ME: Replace attribute-unused on T with void cast, once Trac 297 is fixed. | 
|---|
|  | 67 | // This parameter should be in scope and usable within the body. | 
|---|
| [81e768d] | 68 |  | 
|---|
| [2853d6f] | 69 | (void) a1; | 
|---|
| [2a32118] | 70 | E1(     (void) a2;  ) | 
|---|
| [2853d6f] | 71 | (void) a4; | 
|---|
|  | 72 | //      (void) T; | 
|---|
|  | 73 | (void) a5; | 
|---|
|  | 74 | } | 
|---|
|  | 75 |  | 
|---|
|  | 76 | void mary( | 
|---|
|  | 77 | int T[3]        __attribute__((unused)),  // same as: int *T | 
|---|
|  | 78 | int p1[const 3],                          // same as: int const *p1 | 
|---|
|  | 79 | int p2[static 3],                         // same as T, but length >=3 checked | 
|---|
|  | 80 | int p3[static const 3]                    // both above: 3 is static, p3 is const | 
|---|
|  | 81 | ) { | 
|---|
|  | 82 | // FIX ME: Replace attribute-unused on T with void cast, once Trac 297 is fixed. | 
|---|
|  | 83 | // This parameter should be in scope and usable within the body. | 
|---|
|  | 84 |  | 
|---|
|  | 85 | //      (void) T; | 
|---|
|  | 86 | (void) p1; | 
|---|
|  | 87 | (void) p2; | 
|---|
|  | 88 | (void) p3; | 
|---|
| [8a919cf] | 89 | } | 
|---|
|  | 90 |  | 
|---|
|  | 91 | // function taking (), returning pointer to array of ints | 
|---|
|  | 92 | int (*tom())[3] { | 
|---|
| [2853d6f] | 93 | return 0p; | 
|---|
| [8a919cf] | 94 | } | 
|---|
|  | 95 |  | 
|---|
|  | 96 | // function taking (), returning pointer to function of same type as mary | 
|---|
|  | 97 | int (*(jane)())( int T[3], | 
|---|
|  | 98 | int p1[const 3], | 
|---|
|  | 99 | int p2[static 3], | 
|---|
|  | 100 | int p3[static const 3] | 
|---|
|  | 101 | ) { | 
|---|
| [2853d6f] | 102 | return 0p; | 
|---|
| [8a919cf] | 103 | } | 
|---|
|  | 104 |  | 
|---|
|  | 105 | // functions returning same exotic pointers, in CFA's non-onion syntax | 
|---|
|  | 106 | #ifdef __cforall | 
|---|
|  | 107 | [ * [3] int ] toms_twin(...) { | 
|---|
| [2853d6f] | 108 | return 0p; | 
|---|
| [8a919cf] | 109 | } | 
|---|
|  | 110 | [ * [int]( [3] int T, | 
|---|
| [7ae39f0] | 111 | [const 3] int p1, | 
|---|
|  | 112 | [static 3] int p2, | 
|---|
|  | 113 | [static const 3] int p3 | 
|---|
|  | 114 | ) | 
|---|
| [8a919cf] | 115 | ] janes_twin(...) { | 
|---|
| [2853d6f] | 116 | return 0p; | 
|---|
| [8a919cf] | 117 | } | 
|---|
|  | 118 | #endif | 
|---|
|  | 119 |  | 
|---|
| [7ae39f0] | 120 | // GCC 11+ gives a false warning (-Wvla-parameter) on the valid (C11 ARM p134-135) combination: | 
|---|
|  | 121 | // declare with type int[*], define with type int[n]. | 
|---|
|  | 122 | // https://gcc.gnu.org/bugzilla//show_bug.cgi?id=100420 suggests the internal representation of | 
|---|
|  | 123 | // of a[*] is the same as a[0]. | 
|---|
|  | 124 | // https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-vla-parameter explains | 
|---|
|  | 125 | // the purpose of -Wvla-parameter is to report conflicts between int[] and int[n], which would | 
|---|
|  | 126 | // understandably also include those between int[42] and int[n]. | 
|---|
|  | 127 | // https://stackoverflow.com/questions/17371645/why-use-an-asterisk-instead-of-an-integer-for-a-vla-array-parameter-of-a-f | 
|---|
|  | 128 | // explains the declare-*, define-n pattern. | 
|---|
|  | 129 |  | 
|---|
|  | 130 | // To work around the false warning, and keep to this test's purpose of exercising CFA's | 
|---|
|  | 131 | // handling of exotic C array syntax, what would ideally be demonstrated as a declaration of | 
|---|
|  | 132 | // fm1, followed by its definition, is instead split into fm1x and fm1y.  And similarly for | 
|---|
|  | 133 | // fm5. | 
|---|
|  | 134 |  | 
|---|
| [2853d6f] | 135 | void fm1x( int, int, int[][*] ); | 
|---|
|  | 136 | void fm1y( int r, int c, int m[][c] ) { (void) r; (void) c; (void) m; } | 
|---|
|  | 137 | void fm2( int r, int c, int (*m)[c] ) { (void) r; (void) c; (void) m; }             // same as fm1 | 
|---|
|  | 138 | E2( void fm3( int r, int c, int m[][static c] ) {}  )    // that's not static | 
|---|
|  | 139 | E3( void fm4( int r, int c, int m[][] );            )    // m's immediate element type is incomplete | 
|---|
|  | 140 | void fm5x( int, int, int[*][*] );                    // alt syntax for fm1 decl | 
|---|
|  | 141 | void fm5y( int r, int c, int m[r][c] ) { (void) r; (void) c; (void) m; }            // alt syntax for fm1 defn | 
|---|
| [81e768d] | 142 |  | 
|---|
| [62edde5] | 143 |  | 
|---|
|  | 144 |  | 
|---|
| [66812dd] | 145 | int main() { | 
|---|
| [2853d6f] | 146 | printf("done\n"); | 
|---|
| [66812dd] | 147 | } | 
|---|
| [2ede686] | 148 |  | 
|---|
|  | 149 | // Local Variables: // | 
|---|
|  | 150 | // tab-width: 4 // | 
|---|
|  | 151 | // compile-command: "cfa array.cfa" // | 
|---|
|  | 152 | // End: // | 
|---|