source: tests/array.cfa @ 6b1c4f2

ast-experimental
Last change on this file since 6b1c4f2 was 8a919cf, checked in by Michael Brooks <mlbrooks@…>, 14 months ago

Address build error from commit a5aa5b.

To keep: Change all tabs to spaces in the test source, to make error-case output consistent across compilers.

To investigate further: Comment out test of "dependent parameter" syntax that uses star in prototype, which got an unexpected warning under gcc11.

  • Property mode set to 100644
File size: 3.3 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 a1[0];
40E1( int a2[*];       )
41                                                        #ifndef __cforall
42E1( double a4[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    int fred(int n) {
52E1(     int a1[];    )
53E1(     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,
83            [const 3] int p1,
84            [static 3] int p2,
85            [static const 3] int p3
86            )
87    ] janes_twin(...) {
88    }
89    #endif
90
91
92//  int fm1( int, int, int[][*] );                      // TODO: investigate gcc-11 warning
93//  int fm1( int r, int c, int m[][c] ) {}
94    int fm2( int r, int c, int (*m)[c] ) {}             // same as fm1
95E2( int fm3( int r, int c, int m[][static c] ) {}  )    // that's not static
96E3( int fm4( int r, int c, int m[][] );            )    // m's immediate element type is incomplete
97    int fm5( int, int, int[*][*] );                     // same as fm1 decl
98                                                        #ifndef __cforall
99    int fm5( int r, int c, int m[r][c] ) {}             // BUG 276: CFA chokes but should accept
100                                                        // C: same as fm1 defn
101                                                        #endif
102
103
104int main() {
105    #pragma GCC warning "Preprocessor started"          // force non-empty .expect file, NO TABS!!!
106}
107
108// Local Variables: //
109// tab-width: 4 //
110// compile-command: "cfa array.cfa" //
111// End: //
Note: See TracBrowser for help on using the repository browser.