X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Ftarget-float.c;h=1bdd3efb69f27b4a0e9e50cf9d7d4ce1a5a96a91;hb=f5a7c406b1975cde626efed526960f2cf1bdaceb;hp=a12f216b53dcbd63619958450b09a8c2f24dc50d;hpb=f1628857d783fee0171f16f1bad0b7816460dec5;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/target-float.c b/gdb/target-float.c index a12f216b53..1bdd3efb69 100644 --- a/gdb/target-float.c +++ b/gdb/target-float.c @@ -1,6 +1,6 @@ /* Floating point routines for GDB, the GNU debugger. - Copyright (C) 2017-2018 Free Software Foundation, Inc. + Copyright (C) 2017-2020 Free Software Foundation, Inc. This file is part of GDB. @@ -21,7 +21,7 @@ #include "gdbtypes.h" #include "floatformat.h" #include "target-float.h" - +#include "gdbarch.h" /* Target floating-point operations. @@ -627,7 +627,6 @@ host_float_ops::from_target (const struct floatformat *fmt, } unsigned char *ufrom = (unsigned char *) from; - T dto; long exponent; unsigned long mant; unsigned int mant_bits, mant_off; @@ -648,8 +647,8 @@ host_float_ops::from_target (const struct floatformat *fmt, { double dto; - floatformat_to_double (fmt->split_half ? fmt->split_half : fmt, - from, &dto); + floatformat_to_double /* ARI: floatformat_to_double */ + (fmt->split_half ? fmt->split_half : fmt, from, &dto); *to = (T) dto; return; } @@ -685,7 +684,7 @@ host_float_ops::from_target (const struct floatformat *fmt, mant_bits_left = fmt->man_len; mant_off = fmt->man_start; - dto = 0.0; + T dto = 0.0; special_exponent = exponent == 0 || exponent == fmt->exp_nan; @@ -1008,13 +1007,18 @@ host_float_ops::to_longest (const gdb_byte *addr, { T host_float; from_target (type, addr, &host_float); - /* Converting an out-of-range value is undefined behavior in C, but we - prefer to return a defined value here. */ - if (host_float > std::numeric_limits::max()) - return std::numeric_limits::max(); - if (host_float < std::numeric_limits::min()) + T min_possible_range = static_cast(std::numeric_limits::min()); + T max_possible_range = -min_possible_range; + /* host_float can be converted to an integer as long as it's in + the range [min_possible_range, max_possible_range). If not, it is either + too large, or too small, or is NaN; in this case return the maximum or + minimum possible value. */ + if (host_float < max_possible_range && host_float >= min_possible_range) + return static_cast (host_float); + if (host_float < min_possible_range) return std::numeric_limits::min(); - return (LONGEST) host_float; + /* This line will be executed if host_float is NaN. */ + return std::numeric_limits::max(); } /* Convert signed integer VAL to a target floating-number of type TYPE @@ -1749,7 +1753,7 @@ match_endianness (const gdb_byte *from, const struct type *type, gdb_byte *to) #define OPPOSITE_BYTE_ORDER BFD_ENDIAN_BIG #endif - if (gdbarch_byte_order (get_type_arch (type)) == OPPOSITE_BYTE_ORDER) + if (type_byte_order (type) == OPPOSITE_BYTE_ORDER) for (i = 0; i < len; i++) to[i] = from[len - i - 1]; else @@ -2156,8 +2160,8 @@ target_float_same_format_p (const struct type *type1, case TYPE_CODE_DECFLOAT: return (TYPE_LENGTH (type1) == TYPE_LENGTH (type2) - && (gdbarch_byte_order (get_type_arch (type1)) - == gdbarch_byte_order (get_type_arch (type2)))); + && (type_byte_order (type1) + == type_byte_order (type2))); default: gdb_assert_not_reached ("unexpected type code"); @@ -2258,7 +2262,7 @@ get_target_float_ops (enum target_float_ops_kind kind) /* For binary floating-point formats that do not match any host format, use mpfr_t as intermediate format to provide precise target-floating - point emulation. However, if the MPFR library is not availabe, + point emulation. However, if the MPFR library is not available, use the largest host floating-point type as intermediate format. */ case target_float_ops_kind::binary: {