[AArch64][SVE 09/32] Improve error messages for invalid floats
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 21 Sep 2016 15:49:07 +0000 (16:49 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Wed, 21 Sep 2016 15:49:07 +0000 (16:49 +0100)
Previously:

        fmov d0, #2

would give an error:

        Operand 2 should be an integer register

whereas the user probably just forgot to add the ".0" to make:

        fmov d0, #2.0

This patch reports an invalid floating point constant unless the
operand is obviously a register.

The FPIMM8 handling is only relevant for SVE.  Without it:

        fmov z0, z1

would try to parse z1 as an integer immediate zero (the res2 path),
whereas it's more likely that the user forgot the predicate.  This is
tested by the final patch.

gas/
* config/tc-aarch64.c (parse_aarch64_imm_float): Report a specific
low-severity error for registers.
(parse_operands): Report an invalid floating point constant for
if parsing an FPIMM8 fails, and if no better error has been
recorded.
* testsuite/gas/aarch64/diagnostic.s,
testsuite/gas/aarch64/diagnostic.l: Add tests for integer operands
to FMOV.

gas/ChangeLog
gas/config/tc-aarch64.c
gas/testsuite/gas/aarch64/diagnostic.l
gas/testsuite/gas/aarch64/diagnostic.s

index 6b279823503e560b8ea1992babebe6adb257841d..70f0e71841509fad50f1def9253fb35cedc494f3 100644 (file)
@@ -1,3 +1,14 @@
+2016-09-21  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * config/tc-aarch64.c (parse_aarch64_imm_float): Report a specific
+       low-severity error for registers.
+       (parse_operands): Report an invalid floating point constant for
+       if parsing an FPIMM8 fails, and if no better error has been
+       recorded.
+       * testsuite/gas/aarch64/diagnostic.s,
+       testsuite/gas/aarch64/diagnostic.l: Add tests for integer operands
+       to FMOV.
+
 2016-09-21  Richard Sandiford  <richard.sandiford@arm.com>
 
        * config/tc-aarch64.c (aarch64_double_precision_fmovable): Rename
index 40f6253e3e699ffd6842206cd60b0c256e1a1822..388c4bfa20f4b0f36250e4096956da80fe99f6e1 100644 (file)
@@ -2189,6 +2189,12 @@ parse_aarch64_imm_float (char **ccp, int *immed, bfd_boolean dp_p,
     }
   else
     {
+      if (reg_name_p (str, reg_type))
+       {
+         set_recoverable_error (_("immediate operand required"));
+         return FALSE;
+       }
+
       /* We must not accidentally parse an integer as a floating-point number.
         Make sure that the value we parse is not an integer by checking for
         special characters '.' or 'e'.  */
@@ -5223,8 +5229,9 @@ parse_operands (char *str, const aarch64_opcode *opcode)
               it is probably not worth the effort to support it.  */
            if (!(res1 = parse_aarch64_imm_float (&str, &qfloat, FALSE,
                                                  imm_reg_type))
-               && !(res2 = parse_constant_immediate (&str, &val,
-                                                     imm_reg_type)))
+               && (error_p ()
+                   || !(res2 = parse_constant_immediate (&str, &val,
+                                                         imm_reg_type))))
              goto failure;
            if ((res1 && qfloat == 0) || (res2 && val == 0))
              {
@@ -5288,11 +5295,12 @@ parse_operands (char *str, const aarch64_opcode *opcode)
            bfd_boolean dp_p
              = (aarch64_get_qualifier_esize (inst.base.operands[0].qualifier)
                 == 8);
-           if (! parse_aarch64_imm_float (&str, &qfloat, dp_p, imm_reg_type))
-             goto failure;
-           if (qfloat == 0)
+           if (!parse_aarch64_imm_float (&str, &qfloat, dp_p, imm_reg_type)
+               || qfloat == 0)
              {
-               set_fatal_syntax_error (_("invalid floating-point constant"));
+               if (!error_p ())
+                 set_fatal_syntax_error (_("invalid floating-point"
+                                           " constant"));
                goto failure;
              }
            inst.base.operands[i].imm.value = encode_imm_float_bits (qfloat);
index c278887ecb1ff7a6ef84442dbceed698c580593d..67ef484b7b7fac72f53b1b1265aa87cd487b29fa 100644 (file)
 [^:]*:255: Error: register element index out of range 0 to 15 at operand 1 -- `ld2 {v0\.b,v1\.b}\[-1\],\[x0\]'
 [^:]*:258: Error: register element index out of range 0 to 15 at operand 1 -- `ld2 {v0\.b,v1\.b}\[16\],\[x0\]'
 [^:]*:259: Error: register element index out of range 0 to 15 at operand 1 -- `ld2 {v0\.b,v1\.b}\[67\],\[x0\]'
+[^:]*:261: Error: invalid floating-point constant at operand 2 -- `fmov d0,#2'
+[^:]*:262: Error: invalid floating-point constant at operand 2 -- `fmov d0,#-2'
+[^:]*:263: Error: invalid floating-point constant at operand 2 -- `fmov s0,2'
+[^:]*:264: Error: invalid floating-point constant at operand 2 -- `fmov s0,-2'
index ac2eb5cb902a980757c478f1991142d9884c3c41..3092b9b7ca1a5110a1da9aed01f093b418f37091 100644 (file)
        ld2     {v0.b, v1.b}[15], [x0]
        ld2     {v0.b, v1.b}[16], [x0]
        ld2     {v0.b, v1.b}[67], [x0]
+
+       fmov    d0, #2
+       fmov    d0, #-2
+       fmov    s0, 2
+       fmov    s0, -2
This page took 0.047252 seconds and 4 git commands to generate.