Fix overflow detection in the Z80 assembler.
[binutils-gdb.git] / gas / config / tc-ns32k.c
index 2b3eab8662bf82529cd72fd483ba8815ff2b3015..98fa520b9ba1f2b6ac3fd392b614484267b1154f 100644 (file)
@@ -1,5 +1,5 @@
 /* ns32k.c  -- Assemble on the National Semiconductor 32k series
-   Copyright (C) 1987-2017 Free Software Foundation, Inc.
+   Copyright (C) 1987-2021 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
@@ -84,7 +84,7 @@ struct addr_mode
 typedef struct addr_mode addr_modeS;
 
 char *freeptr, *freeptr_static;        /* Points at some number of free bytes.  */
-struct hash_control *inst_hash_handle;
+htab_t inst_hash_handle;
 
 struct ns32k_opcode *desc;     /* Pointer at description of instruction.  */
 addr_modeS addr_modeP;
@@ -442,7 +442,7 @@ addr_mode (char *operand,
     case 'e':
       if (str[strl - 1] != ']')
        {
-         if ((!strncmp (str, "ext(", 4)) && strl > 7)
+         if ((startswith (str, "ext(")) && strl > 7)
            {                           /* external */
              addrmodeP->disp[0] = str + 4;
              i = 0;
@@ -493,10 +493,10 @@ addr_mode (char *operand,
        default:
          break;
        }
-      /* Drop through.  */
+      /* Fall through.  */
 
     case 3:
-      if (!strncmp (str, "tos", 3))
+      if (startswith (str, "tos"))
        {
          addrmodeP->mode = 23; /* TopOfStack */
          return -1;
@@ -513,11 +513,11 @@ addr_mode (char *operand,
        {
          if (str[strl - 2] == ')')
            {
-             if (!strncmp (&str[strl - 5], "(fp", 3))
+             if (startswith (&str[strl - 5], "(fp"))
                mode = 16;              /* Memory Relative.  */
-             else if (!strncmp (&str[strl - 5], "(sp", 3))
+             else if (startswith (&str[strl - 5], "(sp"))
                mode = 17;
-             else if (!strncmp (&str[strl - 5], "(sb", 3))
+             else if (startswith (&str[strl - 5], "(sb"))
                mode = 18;
 
              if (mode != DEFAULT)
@@ -568,13 +568,13 @@ addr_mode (char *operand,
              /* Fall through.  */
 
            default:
-             if (!strncmp (&str[strl - 4], "(fp", 3))
+             if (startswith (&str[strl - 4], "(fp"))
                mode = 24;
-             else if (!strncmp (&str[strl - 4], "(sp", 3))
+             else if (startswith (&str[strl - 4], "(sp"))
                mode = 25;
-             else if (!strncmp (&str[strl - 4], "(sb", 3))
+             else if (startswith (&str[strl - 4], "(sb"))
                mode = 26;
-             else if (!strncmp (&str[strl - 4], "(pc", 3))
+             else if (startswith (&str[strl - 4], "(pc"))
                mode = 27;
 
              if (mode != DEFAULT)
@@ -1103,7 +1103,8 @@ parse (const char *line, int recursive_level)
       c = *lineptr;
       *(char *) lineptr = '\0';
 
-      if (!(desc = (struct ns32k_opcode *) hash_find (inst_hash_handle, line)))
+      desc = (struct ns32k_opcode *) str_hash_find (inst_hash_handle, line);
+      if (!desc)
        as_fatal (_("No such opcode"));
 
       *(char *) lineptr = c;
@@ -1331,7 +1332,7 @@ fix_new_ns32k (fragS *frag,               /* Which frag? */
   fix_bsr (fixP) = bsr;
   fix_bit_fixP (fixP) = bit_fixP;
   /* We have a MD overflow check for displacements.  */
-  fixP->fx_no_overflow = (im_disp != 0);
+  fixP->fx_no_overflow = im_disp != 0 || bit_fixP != NULL;
 }
 
 static void
@@ -1359,7 +1360,7 @@ fix_new_ns32k_exp (fragS *frag,           /* Which frag? */
   fix_bsr (fixP) = bsr;
   fix_bit_fixP (fixP) = bit_fixP;
   /* We have a MD overflow check for displacements.  */
-  fixP->fx_no_overflow = (im_disp != 0);
+  fixP->fx_no_overflow = im_disp != 0 || bit_fixP != NULL;
 }
 
 /* Convert number to chars in correct order.  */
@@ -1895,18 +1896,14 @@ md_begin (void)
 {
   /* Build a hashtable of the instructions.  */
   const struct ns32k_opcode *ptr;
-  const char *status;
   const struct ns32k_opcode *endop;
 
-  inst_hash_handle = hash_new ();
+  inst_hash_handle = str_htab_create ();
 
   endop = ns32k_opcodes + sizeof (ns32k_opcodes) / sizeof (ns32k_opcodes[0]);
   for (ptr = ns32k_opcodes; ptr < endop; ptr++)
-    {
-      if ((status = hash_insert (inst_hash_handle, ptr->name, (char *) ptr)))
-       /* Fatal.  */
-       as_fatal (_("Can't hash %s: %s"), ptr->name, status);
-    }
+    if (str_hash_insert (inst_hash_handle, ptr->name, ptr, 0) != NULL)
+      as_fatal (_("duplicate %s"), ptr->name);
 
   /* Some private space please!  */
   freeptr_static = XNEWVEC (char, PRIVATE_SIZE);
@@ -1920,7 +1917,7 @@ md_begin (void)
 const char *
 md_atof (int type, char *litP, int *sizeP)
 {
-  return ieee_md_atof (type, litP, sizeP, FALSE);
+  return ieee_md_atof (type, litP, sizeP, false);
 }
 \f
 int