source: tests/array-collections/dimexpr-match-cfa.cfa @ ba068c0

Last change on this file since ba068c0 was 0b8c951d, checked in by Peter A. Buhr <pabuhr@…>, 14 months ago

more rename directories containers to collections

  • Property mode set to 100644
File size: 4.1 KB
Line 
1// These "-cfa" test cases run the dimexpr-match framework (see the hfa) on the CFA "new array."
2// The test is not runnable in gcc.
3// Essentially parallels dimexpr-match.cfa, but uses array(float, 17), of array.hfa, in place of `float[17]`.
4
5#ifndef __cforall
6#error This test is CFA-only
7#endif
8
9#ifdef INCLUDE_MINIMAL
10#define POUNDINCLUDE #include
11POUNDINCLUDE <collections/array.hfa>
12#else
13#include <collections/array.hfa>                                                // part of SUT
14#endif
15
16#include "dimexpr-match.hfa"                                                    // test framework
17
18// CFA "classic" behaviour is inconsistent between "C array" and "new array."
19// The impelementation of "non classic" rules makes C arrays and new arrays work the same.
20#ifdef CFA_IS_CLASSIC
21
22    // CFA "classic" allows mismatched static lengths on "new arrays," which is a bug.
23    // For cfacc-classic compiling C arrays, the (expected) rejection of mismatched static lenghts happens in gcc, not cfa-cpp.
24    // When the CFA input is a C array, the cfa-cc handling is passthrough, so GCC sees the error.
25    // When the CFA input is a new array, the cfa-cpp handling is nontrivial; this rewriting hides the error from GCC, causing the case to be accepted.
26    // This issue is fixed in the implementation of the "non classic" rules.
27    #undef  RULE_CF_NE_STA_STA
28    #define RULE_CF_NE_STA_STA  ACC
29
30    // CFA "classic" rejects mismatched `[N]`s on "new arrays," which is the original signature featere of "new arrays."
31    // But it is unable to do the same with `n`s.  So CFA "classic" treats `n` and `[N]` differently.
32    // The impelementation of "non classic" rules extends this safety to `n`s, and to C arrays.
33    #undef  GRP_K_DIM                 // reclassify dim7/dim42 as group XXX, instead of group DYN
34    #define GRP_K_DIM  XXX
35    #define RULE_CF_EQ_XXX_XXX  ACC   // these rules correspond with non-"classic" DYN
36    #define RULE_CF_NE_XXX_XXX  REJ
37    #define RULE_CF_NE_XXX_STA  REJ
38    #define RULE_CF_NE_STA_XXX  REJ
39    #define RULE_CF_NE_XXX_DYN  REJ
40    #define RULE_CF_NE_DYN_XXX  REJ
41    #define RULE_CF_NE_XXX_UNS  REJ
42    #define RULE_CF_NE_UNS_XXX  REJ
43
44#endif
45
46forall( [N] )
47void zip( array(float, N) & a, array(float, N) & b ) {}
48
49DECLN_runTests {
50
51    enum { enu7 = 7, enu42 = 42 };
52    int mut7 = 7, mut42 = 42;
53
54    #define TRY_COMPAT( LV, RV )            \
55    {                                       \
56        void f( array(float, LV) * x ) {}   \
57        array(float, RV) a;                 \
58        f( & a );                           \
59    }
60    ARRANGEMENT( PTRPARM_CALL )
61    #undef TRY_COMPAT
62
63    #define TRY_COMPAT( LV, RV )            \
64    {                                       \
65        array(float, RV) a;                 \
66        array(float, LV) * b = & a;         \
67    }
68    ARRANGEMENT( PTRVAR_INIT )
69    #undef TRY_COMPAT
70
71    #define TRY_COMPAT( LV, RV )            \
72    {                                       \
73        array(float, RV) a;                 \
74        array(float, LV) * b = NULL;        \
75        b = & a;                            \
76    }
77    ARRANGEMENT( PTRVAR_ASGN )
78    #undef TRY_COMPAT
79
80    #define TRY_COMPAT( LV, RV )            \
81    {                                       \
82        void f( array(float, LV) & x ) {}   \
83        array(float, RV) a;                 \
84        f( a );                             \
85    }
86    ARRANGEMENT( REFPARM_CALL )
87    #undef TRY_COMPAT
88
89    #define TRY_COMPAT( LV, RV )            \
90    {                                       \
91        array(float, RV) a;                 \
92        array(float, LV) & b = a;           \
93    }
94    ARRANGEMENT( REFVAR_INIT )
95    #undef TRY_COMPAT
96
97    #define TRY_COMPAT( LV, RV )            \
98    {                                       \
99        array(float, RV) a;                 \
100        array(float, LV) & b = *0p;         \
101        & b = & a;                          \
102    }
103    ARRANGEMENT( REFVAR_ASGN )
104    #undef TRY_COMPAT
105
106    #define TRY_COMPAT( LV, RV )            \
107    {                                       \
108        array(float, LV) a;                 \
109        array(float, RV) b;                 \
110        zip( a, b );                        \
111    }
112    ARRANGEMENT( CALLZIP )
113    #undef TRY_COMPAT
114
115}
Note: See TracBrowser for help on using the repository browser.