Skip to content

Commit 4b10a9c

Browse files
committed
Address comments
1 parent 7118b77 commit 4b10a9c

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

flang/include/flang/ISO_Fortran_binding.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,15 @@ extern "C++" template <typename T> struct FlexibleArray : T {
146146
CFI_rank_t rank; /* [0 .. CFI_MAX_RANK] */ \
147147
CFI_type_t type; \
148148
CFI_attribute_t attribute; \
149-
/* The lsb of this field indicates the presence of the f18Addendum. Other \
150-
* bits are used to specify the index of the allocator used to managed \
151-
* memory of the data hold by the descriptor. */ \
149+
/* This encodes both the presence of the f18Addendum and the index of the \
150+
* allocator used to managed memory of the data hold by the descriptor. */ \
152151
unsigned char extra;
153152

153+
/* Number of bits used to encode the addendum presence flag */
154+
#define _CFI_ADDENDUM_BITS 1
155+
/* Value of the addendum presence flag */
156+
#define _CFI_ADDENDUM_FLAG 1
157+
154158
typedef struct CFI_cdesc_t {
155159
_CFI_CDESC_T_HEADER_MEMBERS
156160
#ifdef __cplusplus
@@ -160,8 +164,15 @@ typedef struct CFI_cdesc_t {
160164
#endif
161165

162166
#ifdef __cplusplus
163-
RT_API_ATTRS inline bool HasAddendum() const { return extra & 1; }
164-
RT_API_ATTRS inline int GetAllocIdx() const { return ((int)extra >> 1); }
167+
RT_API_ATTRS inline bool HasAddendum() const {
168+
return extra & _CFI_ADDENDUM_FLAG;
169+
}
170+
RT_API_ATTRS inline void SetHasAddendum() {
171+
extra = extra | _CFI_ADDENDUM_FLAG;
172+
}
173+
RT_API_ATTRS inline int GetAllocIdx() const {
174+
return ((int)extra >> _CFI_ADDENDUM_BITS);
175+
}
165176
#endif
166177
} CFI_cdesc_t;
167178

flang/include/flang/Runtime/descriptor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ class Dimension {
9292
// The storage for this object follows the last used dim[] entry in a
9393
// Descriptor (CFI_cdesc_t) generic descriptor. Space matters here, since
9494
// descriptors serve as POINTER and ALLOCATABLE components of derived type
95-
// instances. The presence of this structure is implied by the lsb of
96-
// CFI_cdesc_t.extra set to 1, and the number of elements in the len_[]
95+
// instances. The presence of this structure is encoded in the
96+
// CFI_cdesc_t.extra field, and the number of elements in the len_[]
9797
// array is determined by derivedType_->LenParameters().
9898
class DescriptorAddendum {
9999
public:

flang/runtime/descriptor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ RT_API_ATTRS void Descriptor::Establish(TypeCode t, std::size_t elementBytes,
5252
}
5353
}
5454
if (addendum) {
55-
raw_.extra = raw_.extra | 1;
55+
raw_.SetHasAddendum();
5656
}
5757
DescriptorAddendum *a{Addendum()};
5858
RUNTIME_CHECK(terminator, addendum == (a != nullptr));
@@ -297,6 +297,8 @@ void Descriptor::Dump(FILE *f) const {
297297
std::fprintf(f, " type %d\n", static_cast<int>(raw_.type));
298298
std::fprintf(f, " attribute %d\n", static_cast<int>(raw_.attribute));
299299
std::fprintf(f, " extra %d\n", static_cast<int>(raw_.extra));
300+
std::fprintf(f, " addendum %d\n", static_cast<int>(raw_.HasAddendum()));
301+
std::fprintf(f, " alloc_idx %d\n", static_cast<int>(raw_.GetAllocIdx()));
300302
for (int j{0}; j < raw_.rank; ++j) {
301303
std::fprintf(f, " dim[%d] lower_bound %jd\n", j,
302304
static_cast<std::intmax_t>(raw_.dim[j].lower_bound));

flang/unittests/Evaluate/ISO-Fortran-binding.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ static void check_CFI_establish(CFI_cdesc_t *dv, void *base_addr,
113113
}
114114
}
115115
}
116-
MATCH(0, res->raw().extra);
117116
if (type == CFI_type_struct || type == CFI_type_char ||
118117
type == CFI_type_char16_t || type == CFI_type_char32_t ||
119118
type == CFI_type_other) {

0 commit comments

Comments
 (0)