[flang] Fix: CFI_type_char is now considered Fortran CHARACTER
authorJean Perier <jperier@hsw1.pgi.net>
Wed, 28 Nov 2018 20:17:34 +0000 (12:17 -0800)
committerJean Perier <jperier@hsw1.pgi.net>
Wed, 28 Nov 2018 20:17:34 +0000 (12:17 -0800)
Original-commit: flang-compiler/f18@7c23573bd9630976daf9368913a4d7b71d1ffb3e
Reviewed-on: https://github.com/flang-compiler/f18/pull/227
Tree-same-pre-rewrite: false

flang/runtime/ISO_Fortran_binding.cc
flang/runtime/type-code.cc
flang/runtime/type-code.h

index 1838540..ab98a6e 100644 (file)
 namespace Fortran::ISO {
 extern "C" {
 
+static inline constexpr bool IsCharacterType(CFI_type_t ty) {
+  return ty == CFI_type_char;
+}
+static inline constexpr bool IsAssumedSize(const CFI_cdesc_t *dv) {
+  return dv->rank > 0 && dv->dim[dv->rank - 1].extent == -1;
+}
+
 void *CFI_address(
     const CFI_cdesc_t *descriptor, const CFI_index_t subscripts[]) {
   auto p = reinterpret_cast<char *>(descriptor->base_addr);
@@ -55,7 +62,7 @@ int CFI_allocate(CFI_cdesc_t *descriptor, const CFI_index_t lower_bounds[],
       descriptor->type > CFI_type_struct) {
     return CFI_INVALID_TYPE;
   }
-  if (descriptor->type != CFI_type_char) {
+  if (!IsCharacterType(descriptor->type)) {
     elem_len = descriptor->elem_len;
     if (elem_len <= 0) {
       return CFI_INVALID_ELEM_LEN;
@@ -203,10 +210,6 @@ int CFI_is_contiguous(const CFI_cdesc_t *descriptor) {
   return 1;
 }
 
-static inline bool IsAssumedSize(const CFI_cdesc_t *dv) {
-  return dv->rank > 0 && dv->dim[dv->rank - 1].extent == -1;
-}
-
 int CFI_section(CFI_cdesc_t *result, const CFI_cdesc_t *source,
     const CFI_index_t lower_bounds[], const CFI_index_t upper_bounds[],
     const CFI_index_t strides[]) {
@@ -297,7 +300,7 @@ int CFI_select_part(CFI_cdesc_t *result, const CFI_cdesc_t *source,
     return CFI_INVALID_DESCRIPTOR;
   }
 
-  if (result->type != CFI_type_char) {
+  if (!IsCharacterType(result->type)) {
     elem_len = result->elem_len;
   }
   if (displacement + elem_len > source->elem_len) {
index 72c45dd..b2505d8 100644 (file)
@@ -45,7 +45,7 @@ TypeCode::TypeCode(TypeCategory f, int kind) {
     break;
   case TypeCategory::Character:
     if (kind == 1) {
-      raw_ = CFI_type_cptr;
+      raw_ = CFI_type_char;
     }
     break;
   case TypeCategory::Logical:
index 21d488a..7f3f16b 100644 (file)
@@ -43,7 +43,7 @@ public:
     return raw_ >= CFI_type_float_Complex &&
         raw_ <= CFI_type_long_double_Complex;
   }
-  constexpr bool IsCharacter() const { return raw_ == CFI_type_cptr; }
+  constexpr bool IsCharacter() const { return raw_ == CFI_type_char; }
   constexpr bool IsLogical() const { return raw_ == CFI_type_Bool; }
   constexpr bool IsDerived() const { return raw_ == CFI_type_struct; }