source: tests/array.cfa@ 2853d6f

Last change on this file since 2853d6f was 2853d6f, checked in by Michael Brooks <mlbrooks@…>, 9 months ago

Remove uses of warnings to show test success. Eliminate simple causes of other warnings from affected tests and remove the result from WFLAG_OPT_LAX.

Many affected tests also formerly used -fsyntax-only to avoid errors at later compilation stages, or at runtime. Repair such tests to actually work though runtime, and remove them from SYNTAX_ONLY_CODE.

Group tests listed under WFLAGS_OPT according to why they should receive lax treatment. Add reason WFLGAS_OPT_LAX_EXPECT_WARN and give the original list reason WFLGAS_OPT_LAX_TO_INVESTIGATE.

Tests whose purpose is to show a warning are listed as both SYNTAX_ONLY_CODE (so that the warning is the output) and WFLGAS_OPT_LAX_EXPECT_WARN (to document this fact).

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