S12Z: gas: Fix bug when a symbol name was the single letter 'c'.
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 14 Jan 2019 15:55:17 +0000 (16:55 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 16 Jan 2019 18:35:05 +0000 (19:35 +0100)
The assembler incorrectly recognised "c" as a register name, and
refused to allow it where it expected a symbol/label.

gas/
* config/tc-s12z.c (lex_reg_name): Compare the length of the strings
before the contents.
* testsuite/gas/s12z/labels.d: New file.
* testsuite/gas/s12z/labels.s: New file.
* testsuite/gas/s12z/s12z.exp: Add them.

gas/ChangeLog
gas/config/tc-s12z.c
gas/testsuite/gas/s12z/labels.d [new file with mode: 0644]
gas/testsuite/gas/s12z/labels.s [new file with mode: 0644]
gas/testsuite/gas/s12z/s12z.exp

index 6b852c2..2fd79ba 100644 (file)
@@ -1,8 +1,13 @@
 2019-01-16  John Darrington <john@darrington.wattle.id.au>
 
-        * config/tc-s12z.c (tfr): Change as_bad to as_warn.
+       * config/tc-s12z.c (lex_reg_name): Compare the length of the strings
+       before the contents.
+       * testsuite/gas/s12z/labels.d: New file.
+       * testsuite/gas/s12z/labels.s: New file.
+       * testsuite/gas/s12z/s12z.exp: Add them.
+       * config/tc-s12z.c (tfr): Change as_bad to as_warn.
        Also fix message typo and semantics.
-        * config/tc-s12z.c (emit_opr): Emit BFD_RELOC_S12Z_OPR instead of
+       * config/tc-s12z.c (emit_opr): Emit BFD_RELOC_S12Z_OPR instead of
        BFD_RELOC_24.
        * testsuite/gas/s12z/opr-indirect-expr.d: Expect R_S12Z_OPR instead
        of R_S12Z_EXT24.
index f6c5889..e62f383 100644 (file)
@@ -308,7 +308,7 @@ lex_reg_name (uint16_t which, int *reg)
       p++;
     }
 
-  int len = p - input_line_pointer;
+  size_t len = p - input_line_pointer;
 
   if (len <= 0)
     return 0;
@@ -318,7 +318,8 @@ lex_reg_name (uint16_t which, int *reg)
     {
       gas_assert (registers[i].name);
 
-      if (0 == strncasecmp (registers[i].name, input_line_pointer, len))
+      if (len == strlen (registers[i].name)
+         && 0 == strncasecmp (registers[i].name, input_line_pointer, len))
        {
          if ((0x1U << i) & which)
            {
diff --git a/gas/testsuite/gas/s12z/labels.d b/gas/testsuite/gas/s12z/labels.d
new file mode 100644 (file)
index 0000000..d00e756
--- /dev/null
@@ -0,0 +1,18 @@
+#objdump: -d -r
+#name:    check that certain symbol labels are correctly accepted.
+#source:  labels.s
+
+
+.*:     file format elf32-s12z
+
+
+Disassembly of section .text:
+
+00000000 <.text>:
+   0:  c4 fa 00 00     st d0, 0
+   4:  00 
+                       2: R_S12Z_OPR   c
+   5:  c4 bd           st d0, d1
+   7:  c5 fa 00 00     st d1, 0
+   b:  00 
+                       9: R_S12Z_OPR   xavier
diff --git a/gas/testsuite/gas/s12z/labels.s b/gas/testsuite/gas/s12z/labels.s
new file mode 100644 (file)
index 0000000..9326262
--- /dev/null
@@ -0,0 +1,3 @@
+       st d0, c               ; c is a valid label
+       st d0, d1               ; Move D0 into the memory at address D1
+       st d1, xavier           ; This is a valid label
index 03baf90..76d0931 100644 (file)
@@ -119,6 +119,7 @@ run_dump_test bit-manip-invalid
 run_dump_test opr-symbol
 run_dump_test brclr-symbols
 run_dump_test dbCC
+run_dump_test labels
 
 # Expression related tests
 run_dump_test opr-expr