| 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
 | 
|---|
| 11 | POUNDINCLUDE <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 | 
 | 
|---|
| 46 | forall( [N] )
 | 
|---|
| 47 | void zip( array(float, N) &, array(float, N) & ) {}
 | 
|---|
| 48 | 
 | 
|---|
| 49 | DECLN_runTests {
 | 
|---|
| 50 | 
 | 
|---|
| 51 |     enum { enu7 = 7, enu42 = 42 };
 | 
|---|
| 52 |     int mut7 = 7, mut42 = 42;
 | 
|---|
| 53 | 
 | 
|---|
| 54 |     // Many are only used in rejection cases, so they are unused in the non-ERRS compilation.
 | 
|---|
| 55 |     (void) cpr7;
 | 
|---|
| 56 |     (void) cpr42;
 | 
|---|
| 57 |     (void) mut7;
 | 
|---|
| 58 |     (void) mut42;
 | 
|---|
| 59 | 
 | 
|---|
| 60 |     #define TRY_COMPAT( LV, RV )            \
 | 
|---|
| 61 |     {                                       \
 | 
|---|
| 62 |         void f( array(float, LV) * ) {}     \
 | 
|---|
| 63 |         array(float, RV) a;                 \
 | 
|---|
| 64 |         f( & a );                           \
 | 
|---|
| 65 |     }
 | 
|---|
| 66 |     ARRANGEMENT( PTRPARM_CALL )
 | 
|---|
| 67 |     #undef TRY_COMPAT
 | 
|---|
| 68 | 
 | 
|---|
| 69 |     #define TRY_COMPAT( LV, RV )            \
 | 
|---|
| 70 |     {                                       \
 | 
|---|
| 71 |         array(float, RV) a;                 \
 | 
|---|
| 72 |         array(float, LV) * b = & a;         \
 | 
|---|
| 73 |         (void) b;                           \
 | 
|---|
| 74 |     }
 | 
|---|
| 75 |     ARRANGEMENT( PTRVAR_INIT )
 | 
|---|
| 76 |     #undef TRY_COMPAT
 | 
|---|
| 77 | 
 | 
|---|
| 78 |     #define TRY_COMPAT( LV, RV )            \
 | 
|---|
| 79 |     {                                       \
 | 
|---|
| 80 |         array(float, RV) a;                 \
 | 
|---|
| 81 |         array(float, LV) * b = NULL;        \
 | 
|---|
| 82 |         b = & a;                            \
 | 
|---|
| 83 |     }
 | 
|---|
| 84 |     ARRANGEMENT( PTRVAR_ASGN )
 | 
|---|
| 85 |     #undef TRY_COMPAT
 | 
|---|
| 86 | 
 | 
|---|
| 87 |     #define TRY_COMPAT( LV, RV )            \
 | 
|---|
| 88 |     {                                       \
 | 
|---|
| 89 |         void f( array(float, LV) & ) {}     \
 | 
|---|
| 90 |         array(float, RV) a;                 \
 | 
|---|
| 91 |         f( a );                             \
 | 
|---|
| 92 |     }
 | 
|---|
| 93 |     ARRANGEMENT( REFPARM_CALL )
 | 
|---|
| 94 |     #undef TRY_COMPAT
 | 
|---|
| 95 | 
 | 
|---|
| 96 |     #define TRY_COMPAT( LV, RV )            \
 | 
|---|
| 97 |     {                                       \
 | 
|---|
| 98 |         array(float, RV) a;                 \
 | 
|---|
| 99 |         array(float, LV) & b = a;           \
 | 
|---|
| 100 |         (void) b;                           \
 | 
|---|
| 101 |     }
 | 
|---|
| 102 |     ARRANGEMENT( REFVAR_INIT )
 | 
|---|
| 103 |     #undef TRY_COMPAT
 | 
|---|
| 104 | 
 | 
|---|
| 105 |     #define TRY_COMPAT( LV, RV )            \
 | 
|---|
| 106 |     {                                       \
 | 
|---|
| 107 |         array(float, RV) a;                 \
 | 
|---|
| 108 |         array(float, LV) & b = *0p;         \
 | 
|---|
| 109 |         & b = & a;                          \
 | 
|---|
| 110 |     }
 | 
|---|
| 111 |     ARRANGEMENT( REFVAR_ASGN )
 | 
|---|
| 112 |     #undef TRY_COMPAT
 | 
|---|
| 113 | 
 | 
|---|
| 114 |     #define TRY_COMPAT( LV, RV )            \
 | 
|---|
| 115 |     {                                       \
 | 
|---|
| 116 |         array(float, LV) a;                 \
 | 
|---|
| 117 |         array(float, RV) b;                 \
 | 
|---|
| 118 |         zip( a, b );                        \
 | 
|---|
| 119 |     }
 | 
|---|
| 120 |     ARRANGEMENT( CALLZIP )
 | 
|---|
| 121 |     #undef TRY_COMPAT
 | 
|---|
| 122 | 
 | 
|---|
| 123 | }
 | 
|---|