Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions flang/include/flang/Runtime/type-code.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@ class TypeCode {
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};
Expand Down
10 changes: 6 additions & 4 deletions flang/runtime/ISO_Fortran_binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down