diff --git a/flang/runtime/ISO_Fortran_binding.cpp b/flang/runtime/ISO_Fortran_binding.cpp --- a/flang/runtime/ISO_Fortran_binding.cpp +++ b/flang/runtime/ISO_Fortran_binding.cpp @@ -234,11 +234,13 @@ if (!descriptor) { return CFI_INVALID_DESCRIPTOR; } - std::size_t minElemLen{MinElemLen(type)}; - if (minElemLen > 0) { - elem_len = minElemLen; - } else if (elem_len <= 0) { - return CFI_INVALID_ELEM_LEN; + if (type == CFI_type_struct || type == CFI_type_other || + IsCharacterType(type)) { + if (elem_len <= 0) + return CFI_INVALID_ELEM_LEN; + } else { + elem_len = MinElemLen(type); + assert(elem_len > 0 && "Unknown element length for type"); } descriptor->base_addr = base_addr; descriptor->elem_len = elem_len; diff --git a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp b/flang/unittests/Evaluate/ISO-Fortran-binding.cpp --- a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp +++ b/flang/unittests/Evaluate/ISO-Fortran-binding.cpp @@ -114,6 +114,7 @@ } } if (type == CFI_type_struct || type == CFI_type_char || + type == CFI_type_char16_t || type == CFI_type_char32_t || type == CFI_type_other) { MATCH(elem_len, res->ElementBytes()); } @@ -136,6 +137,7 @@ } if ((type == CFI_type_struct || type == CFI_type_char || + type == CFI_type_char16_t || type == CFI_type_char32_t || type == CFI_type_other) && elem_len <= 0) { ++numErr; @@ -166,7 +168,8 @@ CFI_attribute_t attrCases[]{ CFI_attribute_pointer, CFI_attribute_allocatable, CFI_attribute_other}; CFI_type_t typeCases[]{CFI_type_int, CFI_type_struct, CFI_type_double, - CFI_type_char, CFI_type_other, CFI_TYPE_LAST + 1}; + CFI_type_char, CFI_type_char16_t, CFI_type_char32_t, CFI_type_other, + CFI_TYPE_LAST + 1}; CFI_index_t *extentCases[]{extents, nullptr}; void *baseAddrCases[]{dummyAddr, nullptr}; CFI_rank_t rankCases[]{0, 1, CFI_MAX_RANK, CFI_MAX_RANK + 1};