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
RevLine 
[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];
40E1( int ga2[*]; )
[a5aa5bf]41 #ifndef __cforall
[2853d6f]42E1( int ga3[3.0]; ) // BUG 275: CFA accepts but should reject
[a5aa5bf]43 #endif
[62edde5]44
[8a919cf]45 int m1[0][3];
46E1( int m2[*][*]; )
47 int m4[3][3];
48
49 typedef int T;
50
[2853d6f]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;
[8a919cf]57 }
58
[2853d6f]59 void fred2(int n,
[81e768d]60 int a1[],
[2853d6f]61E1( 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 // 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;
[8a919cf]90 }
91
92 // function taking (), returning pointer to array of ints
93 int (*tom())[3] {
[2853d6f]94 return 0p;
[8a919cf]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 ) {
[2853d6f]103 return 0p;
[8a919cf]104 }
105
106 // functions returning same exotic pointers, in CFA's non-onion syntax
107 #ifdef __cforall
108 [ * [3] int ] toms_twin(...) {
[2853d6f]109 return 0p;
[8a919cf]110 }
111 [ * [int]( [3] int T,
[7ae39f0]112 [const 3] int p1,
113 [static 3] int p2,
114 [static const 3] int p3
115 )
[8a919cf]116 ] janes_twin(...) {
[2853d6f]117 return 0p;
[8a919cf]118 }
119 #endif
120
[7ae39f0]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
[2853d6f]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
[81e768d]143
[62edde5]144
145
[66812dd]146int main() {
[2853d6f]147 printf("done\n");
[66812dd]148}
[2ede686]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.