source: tests/array-container/dimexpr-match-cfa.cfa @ ed1a7ab8

Last change on this file since ed1a7ab8 was 0f4ac10, checked in by Michael Brooks <mlbrooks@…>, 17 months ago

Add tests demonstrating CFA's treatment of C arrays, compared with GCC's.

These tests recognize two levels of CFA functionality: Classic and Preview. This commit shows that CFA Master implements Classic. Preview refers to Mike's forthcoming changes.

Only the CFA part runs in the nightly build. Under CFA Classic, a limitation is that only some rejection cases are exercised in the nightly build. A hand-driven testing script can access all the cases and CFA Preview will exercise all the cases in the nightly build.

test dimexpr-match-c: how CFA's treatment of C arrays compares with GCC's

test dimexpr-match-cfa: how CFA's treamtment of <containers/array.hfa>-arrays aligns with the above

  • Property mode set to 100644
File size: 4.2 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 <containers/array.hfa>
12#else
13#include <containers/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
47DECLN_runTests {
48
49    enum { enu7 = 7, enu42 = 42 };
50    int mut7 = 7, mut42 = 42;
51
52   
53    #define TRY_COMPAT( LV, RV )            \
54    {                                       \
55        void f( array(float, LV) * x ) {}   \
56        array(float, RV) a;                 \
57        f( & a );                           \
58    }
59    ARRANGEMENT( PTRPARM_CALL )
60    #undef TRY_COMPAT
61
62    #define TRY_COMPAT( LV, RV )            \
63    {                                       \
64        array(float, RV) a;                 \
65        array(float, LV) * b = & a;         \
66    }
67    ARRANGEMENT( PTRVAR_INIT )
68    #undef TRY_COMPAT
69
70    #define TRY_COMPAT( LV, RV )            \
71    {                                       \
72        array(float, RV) a;                 \
73        array(float, LV) * b = NULL;        \
74        b = & a;                            \
75    }
76    ARRANGEMENT( PTRVAR_ASGN )
77    #undef TRY_COMPAT
78
79    #define TRY_COMPAT( LV, RV )            \
80    {                                       \
81        void f( array(float, LV) & x ) {}   \
82        array(float, RV) a;                 \
83        f( a );                             \
84    }
85    ARRANGEMENT( REFPARM_CALL )
86    #undef TRY_COMPAT
87
88    #define TRY_COMPAT( LV, RV )            \
89    {                                       \
90        array(float, RV) a;                 \
91        array(float, LV) & b = a;           \
92    }
93    ARRANGEMENT( REFVAR_INIT )
94    #undef TRY_COMPAT
95
96    #define TRY_COMPAT( LV, RV )            \
97    {                                       \
98        array(float, RV) a;                 \
99        array(float, LV) & b = *0p;         \
100        & b = & a;                          \
101    }
102    ARRANGEMENT( REFVAR_ASGN )
103    #undef TRY_COMPAT
104
105
106    forall( [N] )
107    void zip( array(float, N) & a, array(float, N) & b ) {}
108
109    #define TRY_COMPAT( LV, RV )            \
110    {                                       \
111        array(float, LV) a;                 \
112        array(float, RV) b;                 \
113        zip( a, b );                        \
114    }
115    ARRANGEMENT( CALLZIP )
116    #undef TRY_COMPAT
117
118}
Note: See TracBrowser for help on using the repository browser.