source: tests/array.cfa@ 6a6e205

Last change on this file since 6a6e205 was 2a32118, checked in by Michael Brooks <mlbrooks@…>, 8 months ago

Fix a warning missed in 2853d6fb0.

  • Property mode set to 100644
File size: 4.8 KB
Line 
1// -*- Mode: C -*-
2//
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.
7//
8// array.cfa -- test array declarations
9//
10// Author : Peter A. Buhr
11// Created On : Tue Feb 19 21:18:06 2019
12// Last Modified By : Peter A. Buhr
13// Last Modified On : Sat Jun 5 10:05:51 2021
14// Update Count : 5
15//
16
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`.
20
21#ifdef ERR1
22#define E1(...) __VA_ARGS__
23#else
24#define E1(...)
25#endif
26
27#ifdef ERR2
28#define E2(...) __VA_ARGS__
29#else
30#define E2(...)
31#endif
32
33#ifdef ERR3
34#define E3(...) __VA_ARGS__
35#else
36#define E3(...)
37#endif
38
39 int ga1[0];
40E1( int ga2[*]; )
41 #ifndef __cforall
42E1( int ga3[3.0]; ) // BUG 275: CFA accepts but should reject
43 #endif
44
45 int m1[0][3];
46E1( int m2[*][*]; )
47 int m4[3][3];
48
49 typedef int T;
50
51 void fred(int n) {
52E1( int a1[]; )
53E1( int a2[*]; )
54 int a4[3]; (void) a4;
55 int T[3]; (void) T;
56 int a5[n]; (void) a5;
57 }
58
59 void fred2(int n,
60 int a1[],
61E1( int a2[*], )
62 int a4[3],
63 int T[3] __attribute__((unused)),
64 int a5[n]
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.
68
69 (void) a1;
70E1( (void) a2; )
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;
89 }
90
91 // function taking (), returning pointer to array of ints
92 int (*tom())[3] {
93 return 0p;
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 ) {
102 return 0p;
103 }
104
105 // functions returning same exotic pointers, in CFA's non-onion syntax
106 #ifdef __cforall
107 [ * [3] int ] toms_twin(...) {
108 return 0p;
109 }
110 [ * [int]( [3] int T,
111 [const 3] int p1,
112 [static 3] int p2,
113 [static const 3] int p3
114 )
115 ] janes_twin(...) {
116 return 0p;
117 }
118 #endif
119
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
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
138E2( void fm3( int r, int c, int m[][static c] ) {} ) // that's not static
139E3( 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
142
143
144
145int main() {
146 printf("done\n");
147}
148
149// Local Variables: //
150// tab-width: 4 //
151// compile-command: "cfa array.cfa" //
152// End: //
Note: See TracBrowser for help on using the repository browser.