gdb/testsuite: Reduce test name duplication in gdb.python tests
[deliverable/binutils-gdb.git] / gdb / target-float.c
index b40b6416c1ca55c00ebff65a11183f913bc0eebd..0fd71c0dc335f0e6b0fa76a7e8ad24187d97bf79 100644 (file)
@@ -1,6 +1,6 @@
 /* Floating point routines for GDB, the GNU debugger.
 
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   Copyright (C) 2017-2019 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<T>::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;
@@ -685,7 +684,7 @@ host_float_ops<T>::from_target (const struct floatformat *fmt,
 
   mant_bits_left = fmt->man_len;
   mant_off = fmt->man_start;
-  dto = 0.0;
+  dto = 0.0;
 
   special_exponent = exponent == 0 || exponent == fmt->exp_nan;
 
@@ -948,7 +947,11 @@ host_float_ops<T>::to_string (const gdb_byte *addr, const struct type *type,
 
   T host_float;
   from_target (type, addr, &host_float);
+
+  DIAGNOSTIC_PUSH
+  DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
   return string_printf (host_format.c_str (), host_float);
+  DIAGNOSTIC_POP
 }
 
 /* Parse string IN into a target floating-number of type TYPE and
@@ -977,7 +980,10 @@ host_float_ops<T>::from_string (gdb_byte *addr, const struct type *type,
     scan_format += scanf_length_modifier<T>::value;
   scan_format += "g%n";
 
+  DIAGNOSTIC_PUSH
+  DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
   num = sscanf (in.c_str (), scan_format.c_str(), &host_float, &n);
+  DIAGNOSTIC_POP
 
   /* The sscanf man page suggests not making any assumptions on the effect
      of %n on the result, so we don't.
@@ -1001,13 +1007,18 @@ host_float_ops<T>::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<LONGEST>::max())
-    return std::numeric_limits<LONGEST>::max();
-  if (host_float < std::numeric_limits<LONGEST>::min())
+  T min_possible_range = static_cast<T>(std::numeric_limits<LONGEST>::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<LONGEST> (host_float);
+  if (host_float < min_possible_range)
     return std::numeric_limits<LONGEST>::min();
-  return (LONGEST) host_float;
+  /* This line will be executed if host_float is NaN.  */
+  return std::numeric_limits<LONGEST>::max();
 }
 
 /* Convert signed integer VAL to a target floating-number of type TYPE
@@ -1312,7 +1323,7 @@ mpfr_float_ops::from_target (const struct floatformat *fmt,
 
       mant = get_field (from, order, fmt->totalsize, mant_off, mant_bits);
 
-      mpfr_set_si (tmp.val, mant, MPFR_RNDN);
+      mpfr_set_ui (tmp.val, mant, MPFR_RNDN);
       mpfr_mul_2si (tmp.val, tmp.val, exponent - mant_bits, MPFR_RNDN);
       mpfr_add (to.val, to.val, tmp.val, MPFR_RNDN);
       exponent -= mant_bits;
This page took 0.025703 seconds and 4 git commands to generate.