[flang][runtime] Handle type code synonyms in CFI_... runtime (#66231)

Some CFI_type_... type codes are synonyms; ensure that they are treated
as equivalent when validating inputs to CFI_... runtime routines.
This commit is contained in:
Peter Klausler 2023-09-13 15:25:48 -07:00 committed by GitHub
parent 9918d2556c
commit f5592f3069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -53,10 +53,19 @@ public:
RT_API_ATTRS std::optional<std::pair<TypeCategory, int>>
GetCategoryAndKind() const;
RT_API_ATTRS bool operator==(const TypeCode &that) const {
return raw_ == that.raw_;
RT_API_ATTRS bool operator==(TypeCode that) const {
if (raw_ == that.raw_) { // fast path
return true;
} else {
// Multiple raw CFI_type_... codes can represent the same Fortran
// type category + kind type parameter, e.g. CFI_type_int and
// CFI_type_int32_t.
auto thisCK{GetCategoryAndKind()};
auto thatCK{that.GetCategoryAndKind()};
return thisCK && thatCK && *thisCK == *thatCK;
}
}
bool operator!=(const TypeCode &that) const { return raw_ != that.raw_; }
bool operator!=(TypeCode that) const { return !(*this == that); }
private:
ISO::CFI_type_t raw_{CFI_type_other};

View File

@ -148,9 +148,11 @@ int CFI_section(CFI_cdesc_t *result, const CFI_cdesc_t *source,
if (IsAssumedSize(source) && !upper_bounds) {
return CFI_INVALID_DESCRIPTOR;
}
if ((result->type != source->type) ||
(result->elem_len != source->elem_len)) {
return CFI_INVALID_DESCRIPTOR;
if (runtime::TypeCode{result->type} != runtime::TypeCode{source->type}) {
return CFI_INVALID_TYPE;
}
if (source->elem_len != result->elem_len) {
return CFI_INVALID_ELEM_LEN;
}
if (result->attribute == CFI_attribute_allocatable) {
return CFI_INVALID_ATTRIBUTE;
@ -256,7 +258,7 @@ int CFI_setpointer(CFI_cdesc_t *result, const CFI_cdesc_t *source,
if (source->rank != result->rank) {
return CFI_INVALID_RANK;
}
if (source->type != result->type) {
if (runtime::TypeCode{source->type} != runtime::TypeCode{result->type}) {
return CFI_INVALID_TYPE;
}
if (source->elem_len != result->elem_len) {