[flang-commits] [PATCH] D101659: [flang] Fix handling of elem_len in CFI_establish

Diana Picus via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon May 3 01:17:46 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGaaab70407beb: [flang] Fix handling of elem_len in CFI_establish (authored by rovka).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101659/new/

https://reviews.llvm.org/D101659

Files:
  flang/runtime/ISO_Fortran_binding.cpp
  flang/unittests/Evaluate/ISO-Fortran-binding.cpp


Index: flang/unittests/Evaluate/ISO-Fortran-binding.cpp
===================================================================
--- flang/unittests/Evaluate/ISO-Fortran-binding.cpp
+++ 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};
Index: flang/runtime/ISO_Fortran_binding.cpp
===================================================================
--- flang/runtime/ISO_Fortran_binding.cpp
+++ 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101659.342325.patch
Type: text/x-patch
Size: 2026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210503/75c0dfcf/attachment.bin>


More information about the flang-commits mailing list