Skip to content

Commit fba474d

Browse files
authored
[flang] Fix CFI_CDESC_T(rank) for C (#66260)
The CFI_CDESC_T(rank) macro defined for C (not C++) in ISO_Fortran_binding.h incorporates a cdesc_t structure as a member, which works for data layout but doesn't allow for direct access to its members. (The C++ definition can use inheritance.) Restructure the definitions in that header file so that CFI_CDESC_T(rank) for C defines a struct with the expected members.
1 parent 256a0b2 commit fba474d

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

flang/include/flang/ISO_Fortran_binding.h

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,21 @@ template <typename T> struct FlexibleArray : T {
134134
#endif
135135

136136
/* 18.5.3 generic data descriptor */
137-
typedef struct CFI_cdesc_t {
138-
/* These three members must appear first, in exactly this order. */
139-
void *base_addr;
140-
size_t elem_len; /* element size in bytes */
141-
int version; /* == CFI_VERSION */
142-
CFI_rank_t rank; /* [0 .. CFI_MAX_RANK] */
143-
CFI_type_t type;
144-
CFI_attribute_t attribute;
137+
138+
/* Descriptor header members */
139+
#define _CFI_CDESC_T_HEADER_MEMBERS \
140+
/* These three members must appear first, \
141+
* in exactly this order. */ \
142+
void *base_addr; \
143+
size_t elem_len; /* element size in bytes */ \
144+
int version; /* == CFI_VERSION */ \
145+
CFI_rank_t rank; /* [0 .. CFI_MAX_RANK] */ \
146+
CFI_type_t type; \
147+
CFI_attribute_t attribute; \
145148
unsigned char f18Addendum;
149+
150+
typedef struct CFI_cdesc_t {
151+
_CFI_CDESC_T_HEADER_MEMBERS
146152
#ifdef __cplusplus
147153
cfi_internal::FlexibleArray<CFI_dim_t> dim;
148154
#else
@@ -152,8 +158,9 @@ typedef struct CFI_cdesc_t {
152158

153159
/* 18.5.4 */
154160
#ifdef __cplusplus
155-
// The struct below take care of getting the memory storage for C++ CFI_cdesc_t
156-
// that contain an emulated flexible array.
161+
// This struct acquires the additional storage, if any is
162+
// needed, for C++'s CFI_cdesc_t's emulated flexible
163+
// dim[] array.
157164
namespace cfi_internal {
158165
template <int r> struct CdescStorage : public CFI_cdesc_t {
159166
static_assert((r > 1 && r <= CFI_MAX_RANK), "CFI_INVALID_RANK");
@@ -164,10 +171,10 @@ template <> struct CdescStorage<0> : public CFI_cdesc_t {};
164171
} // namespace cfi_internal
165172
#define CFI_CDESC_T(rank) cfi_internal::CdescStorage<rank>
166173
#else
167-
#define CFI_CDESC_T(rank) \
174+
#define CFI_CDESC_T(_RANK) \
168175
struct { \
169-
CFI_cdesc_t cdesc; /* must be first */ \
170-
CFI_dim_t dim[rank]; \
176+
_CFI_CDESC_T_HEADER_MEMBERS \
177+
CFI_dim_t dim[_RANK]; \
171178
}
172179
#endif
173180

0 commit comments

Comments
 (0)