]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
trans-types.c (gfc_get_int_kind_from_width_isofortranen): Choose REAL type with the...
authorSteven G. Kargl <kargl@gcc.gnu.org>
Wed, 8 Feb 2017 00:37:22 +0000 (00:37 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Wed, 8 Feb 2017 00:37:22 +0000 (00:37 +0000)
2017-02-07  Steven G. Kargl  <kargl@gcc.gnu.org>

* trans-types.c (gfc_get_int_kind_from_width_isofortranen):  Choose
REAL type with the widest precision if two (or more) have the same
storage size.

From-SVN: r245265

gcc/fortran/ChangeLog
gcc/fortran/trans-types.c

index d4ea0e901cc7a779bc4a4c0dd1b09dc638f887a1..9dc753b567c4e7a8ab634195161d2624ad9e2c40 100644 (file)
@@ -1,3 +1,9 @@
+2017-02-07  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       * trans-types.c (gfc_get_int_kind_from_width_isofortranen):  Choose
+       REAL type with the widest precision if two (or more) have the same
+       storage size.
+
 2016-12-22  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        Backport from trunk
index fa553f4ff1f1abcba3a5ff86d7d03f1e268855b0..5d59ef52f784dd3754c91b205712150d22474a71 100644 (file)
@@ -256,27 +256,42 @@ gfc_get_int_kind_from_width_isofortranenv (int size)
   return -1;
 }
 
-/* Get the kind number corresponding to a real of given storage size,
-   following the required return values for ISO_FORTRAN_ENV REAL* constants:
-   -2 is returned if we support a kind of larger size, -1 otherwise.  */
+
+/* Get the kind number corresponding to a real of a given storage size.
+   If two real's have the same storage size, then choose the real with
+   the largest precision.  If a kind type is unavailable and a real
+   exists with wider storage, then return -2; otherwise, return -1.  */
+
 int
 gfc_get_real_kind_from_width_isofortranenv (int size)
 {
-  int i;
+  int digits, i, kind;
 
   size /= 8;
 
+  kind = -1;
+  digits = 0;
+
   /* Look for a kind with matching storage size.  */
   for (i = 0; gfc_real_kinds[i].kind != 0; i++)
     if (int_size_in_bytes (gfc_get_real_type (gfc_real_kinds[i].kind)) == size)
-      return gfc_real_kinds[i].kind;
+      {
+       if (gfc_real_kinds[i].digits > digits)
+         {
+           digits = gfc_real_kinds[i].digits;
+           kind = gfc_real_kinds[i].kind;
+         }
+      }
+
+  if (kind != -1)
+    return kind;
 
   /* Look for a kind with larger storage size.  */
   for (i = 0; gfc_real_kinds[i].kind != 0; i++)
     if (int_size_in_bytes (gfc_get_real_type (gfc_real_kinds[i].kind)) > size)
-      return -2;
+      kind = -2;
 
-  return -1;
+  return kind;
 }