diff options
author | kargl <kargl@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-02-07 21:28:08 +0000 |
---|---|---|
committer | kargl <kargl@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-02-07 21:28:08 +0000 |
commit | b0bcbce4ddace64b46e76408985663cbffcb641b (patch) | |
tree | c2fad090dcb3b8787bc1b5d56c39255ede69d8ea | |
parent | 6fb211fb2122ba018a65a49f297bd25338974af3 (diff) | |
download | gcc-b0bcbce4ddace64b46e76408985663cbffcb641b.tar.gz |
2017-02-04 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@245255 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/fortran/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fortran/trans-types.c | 29 |
2 files changed, 28 insertions, 7 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 400f516203e..0b3279667dd 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -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. + 2017-02-05 Andre Vehreschild <vehre@gcc.gnu.org> PR fortran/79344 diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c index 759b80eecaa..fc5e486379f 100644 --- a/gcc/fortran/trans-types.c +++ b/gcc/fortran/trans-types.c @@ -234,27 +234,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; } |