]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix the assembler's floating point number parser so that it can correctly handle...
authorBosco Garc?a <jbgg.gnu@gmail.com>
Thu, 22 Aug 2019 11:54:06 +0000 (12:54 +0100)
committerNick Clifton <nickc@redhat.com>
Thu, 22 Aug 2019 11:54:06 +0000 (12:54 +0100)
* atof-generic.c (atof_generic): Do not ignore leading zeros if
they appear after a decimal point.
* testsuite/gas/all/float.s: Extend test to include a number with
a leading decimal point followed by several zeroes.
* testsuite/gas/i386/fp.s: Likewise.
* testsuite/gas/i386/fp.d: Update expected output.

gas/ChangeLog
gas/atof-generic.c
gas/testsuite/gas/all/float.s
gas/testsuite/gas/i386/fp.d
gas/testsuite/gas/i386/fp.s

index 655c8adadf6f20aa2c33ad0bf5aadf55fb643e61..bd9887e4243a3b3a2897dc77f671a1cde8e2ab87 100644 (file)
@@ -1,3 +1,13 @@
+2019-08-22  Bosco GarcĂ­a  <jbgg.gnu@gmail.com>
+           Nick Clifton  <nickc@redhat.com>
+
+       * atof-generic.c (atof_generic): Do not ignore leading zeros if
+       they appear after a decimal point.
+       * testsuite/gas/all/float.s: Extend test to include a number with
+       a leading decimal point followed by several zeroes.
+       * testsuite/gas/i386/fp.s: Likewise.
+       * testsuite/gas/i386/fp.d: Update expected output.
+
 2019-08-22  Barnaby Wilks  <barnaby.wilks@arm.com>
 
        * config/tc-aarch64.c: Add float16 directive and add "Hh" to
index 40ee910c7200f67d0859e2512c7411c56f09c05e..345ccef2c1c32c7acbf98acca48109f2ae62adcc 100644 (file)
@@ -184,23 +184,42 @@ atof_generic (/* return pointer to just AFTER number we read.  */
 
 #ifndef OLD_FLOAT_READS
   /* Ignore trailing 0's after the decimal point.  The original code here
-   * (ifdef'd out) does not do this, and numbers like
-   *   4.29496729600000000000e+09      (2**31)
-   * come out inexact for some reason related to length of the digit
-   * string.
-   */
+     (ifdef'd out) does not do this, and numbers like
+       4.29496729600000000000e+09      (2**31)
+     come out inexact for some reason related to length of the digit
+     string.  */
+
+  /* The case number_of_digits_before_decimal = 0 is handled for
+     deleting zeros after decimal.  In this case the decimal mark and
+     the first zero digits after decimal mark are skipped.  */
+  seen_significant_digit = 0;
+  signed long subtract_decimal_exponent = 0;
+
   if (c && IS_DECIMAL_MARK (c))
     {
-      unsigned int zeros = 0;  /* Length of current string of zeros */
+      unsigned int zeros = 0;  /* Length of current string of zeros.  */
+
+      if (number_of_digits_before_decimal == 0)
+       /* Skip decimal mark.  */
+       first_digit++;
 
       for (p++; (c = *p) && ISDIGIT (c); p++)
        {
          if (c == '0')
            {
-             zeros++;
+             if (number_of_digits_before_decimal == 0
+                 && !seen_significant_digit)
+               {
+                 /* Skip '0' and the decimal mark.  */
+                 first_digit++;
+                 subtract_decimal_exponent--;
+               }
+             else
+               zeros++;
            }
          else
            {
+             seen_significant_digit = 1;
              number_of_digits_after_decimal += 1 + zeros;
              zeros = 0;
            }
@@ -287,6 +306,12 @@ atof_generic (/* return pointer to just AFTER number we read.  */
        }
     }
 
+#ifndef OLD_FLOAT_READS
+  /* Subtract_decimal_exponent != 0 when number_of_digits_before_decimal = 0
+     and first digit after decimal is '0'.  */
+  decimal_exponent += subtract_decimal_exponent;
+#endif
+
   *address_of_string_pointer = p;
 
   number_of_digits_available =
index b098cad1cc2305f9a4b919204a2ffe4a3ddde839..902914f4dc81c5e05d11d22495dc1e614085deac 100644 (file)
@@ -2,3 +2,5 @@
 foo:   .single 0r1.2345e+06
        .single 0f3.14159
        .double 0r2.718282
+        .double .0000000000000000000001
+        .double 1e-22
index 21838e262bc2669bd3812b93f52feb84482baa8e..a9a9538cd09252269270e6a2659c4cec51184e59 100644 (file)
@@ -6,3 +6,4 @@
 Contents of section .data:
  0000 00881bcd 4b789ad4 004071a3 79094f93  ....Kx...@q.y.O.
  0010 0a40789a 5440789a 54400000 00000000  .@x.T@x.T@......
+ 0020 e65e1710 20395e3b e65e1710 20395e3b  .\^.. 9\^;.\^.. 9\^;
index 4187d4e55c3135f3c9bd72578a2e224cab52f859..a1f2b0f0a48428d1745354767ea4854fca8e199d 100644 (file)
@@ -11,3 +11,7 @@
        .single 3.32192809488736218171e0
 #      .byte 0x78, 0x9a, 0x54, 0x40, 0, 0, 0, 0
        .byte 0, 0, 0, 0, 0, 0
+
+# The assembler used to treat the next value as zero instead of 1e-22.
+        .double .0000000000000000000001
+        .double 1e-22