ubsan: spu: left shift of negative value
[deliverable/binutils-gdb.git] / gas / config / tc-tic30.c
index d4d98d5ec6e4897b37882292ee3ffb6d39f7ad28..f1954d0d935b63b22bc095c7d594f123eb991694 100644 (file)
@@ -1,6 +1,5 @@
 /* tc-c30.c -- Assembly code for the Texas Instruments TMS320C30
-   Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009
-   Free Software Foundation, Inc.
+   Copyright (C) 1998-2020 Free Software Foundation, Inc.
    Contributed by Steven Haworth (steve@pm.cse.rmit.edu.au)
 
    This file is part of GAS, the GNU Assembler.
@@ -32,9 +31,9 @@
 /* Put here all non-digit non-letter characters that may occur in an
    operand.  */
 static char operand_special_chars[] = "%$-+(,)*._~/<>&^!:[@]";
-static char *ordinal_names[] =
+static const char *ordinal_names[] =
 {
-  "first", "second", "third", "fourth", "fifth"
+  N_("first"), N_("second"), N_("third"), N_("fourth"), N_("fifth")
 };
 
 const char comment_chars[]        = ";";
@@ -85,11 +84,11 @@ debug (const char *string, ...)
   if (flag_debug)
     {
       char str[100];
+      va_list argptr;
 
-      VA_OPEN (argptr, string);
-      VA_FIXEDARG (argptr, const char *, string);
+      va_start (argptr, string);
       vsprintf (str, string, argptr);
-      VA_CLOSE (argptr);
+      va_end (argptr);
       if (str[0] == '\0')
        return (0);
       fputs (str, USE_STDOUT ? stdout : stderr);
@@ -281,7 +280,7 @@ output_invalid (char c)
     snprintf (output_invalid_buf, sizeof (output_invalid_buf),
              "'%c'", c);
   else
-    snprintf (output_invalid_buf, sizeof (output_invalid_buf), 
+    snprintf (output_invalid_buf, sizeof (output_invalid_buf),
              "(0x%x)", (unsigned char) c);
   return output_invalid_buf;
 }
@@ -327,19 +326,19 @@ tic30_find_parallel_insn (char *current_line, char *next_line)
 
   {
     int i;
-    char *opcode, *operands, *line;
+    char *op, *operands, *line;
 
     for (i = 0; i < 2; i++)
       {
        if (i == 0)
          {
-           opcode = &first_opcode[0];
+           op = &first_opcode[0];
            operands = &first_operands[0];
            line = current_line;
          }
        else
          {
-           opcode = &second_opcode[0];
+           op = &second_opcode[0];
            operands = &second_operands[0];
            line = next_line;
          }
@@ -353,14 +352,14 @@ tic30_find_parallel_insn (char *current_line, char *next_line)
            {
              if (is_opcode_char (c) && search_status == NONE)
                {
-                 opcode[char_ptr++] = TOLOWER (c);
+                 op[char_ptr++] = TOLOWER (c);
                  search_status = START_OPCODE;
                }
              else if (is_opcode_char (c) && search_status == START_OPCODE)
-               opcode[char_ptr++] = TOLOWER (c);
+               op[char_ptr++] = TOLOWER (c);
              else if (!is_opcode_char (c) && search_status == START_OPCODE)
                {
-                 opcode[char_ptr] = '\0';
+                 op[char_ptr] = '\0';
                  char_ptr = 0;
                  search_status = END_OPCODE;
                }
@@ -381,11 +380,10 @@ tic30_find_parallel_insn (char *current_line, char *next_line)
        }
       }
   }
-  parallel_insn = malloc (strlen (first_opcode) + strlen (first_operands)
-                         + strlen (second_opcode) + strlen (second_operands) + 8);
-  sprintf (parallel_insn, "q_%s_%s %s | %s",
-          first_opcode, second_opcode,
-          first_operands, second_operands);
+
+  parallel_insn = concat ("q_", first_opcode, "_", second_opcode, " ",
+                         first_operands, " | ", second_operands,
+                         (char *) NULL);
   debug ("parallel insn = %s\n", parallel_insn);
   return parallel_insn;
 }
@@ -400,12 +398,10 @@ static operand *
 tic30_operand (char *token)
 {
   unsigned int count;
-  char ind_buffer[strlen (token)];
   operand *current_op;
 
   debug ("In tic30_operand with %s\n", token);
-  current_op = malloc (sizeof (* current_op));
-  memset (current_op, '\0', sizeof (operand));
+  current_op = XCNEW (operand);
 
   if (*token == DIRECT_REFERENCE)
     {
@@ -464,6 +460,9 @@ tic30_operand (char *token)
       int disp_number = 0;
       int buffer_posn = 1;
       ind_addr_type *ind_addr_op;
+      char * ind_buffer;
+
+      ind_buffer = XNEWVEC (char, strlen (token));
 
       debug ("Found indirect reference\n");
       ind_buffer[0] = *token;
@@ -481,11 +480,13 @@ tic30_operand (char *token)
              if (found_ar)
                {
                  as_bad (_("More than one AR register found in indirect reference"));
+                 free (ind_buffer);
                  return NULL;
                }
              if (*(token + count + 1) < '0' || *(token + count + 1) > '7')
                {
                  as_bad (_("Illegal AR register in indirect reference"));
+                 free (ind_buffer);
                  return NULL;
                }
              ar_number = *(token + count + 1) - '0';
@@ -506,6 +507,7 @@ tic30_operand (char *token)
                  if (found_disp)
                    {
                      as_bad (_("More than one displacement found in indirect reference"));
+                     free (ind_buffer);
                      return NULL;
                    }
                  count++;
@@ -514,6 +516,7 @@ tic30_operand (char *token)
                      if (!is_digit_char (*(token + count)))
                        {
                          as_bad (_("Invalid displacement in indirect reference"));
+                         free (ind_buffer);
                          return NULL;
                        }
                      disp[disp_posn++] = *(token + (count++));
@@ -531,6 +534,7 @@ tic30_operand (char *token)
       if (!found_ar)
        {
          as_bad (_("AR register not found in indirect reference"));
+         free (ind_buffer);
          return NULL;
        }
 
@@ -547,18 +551,21 @@ tic30_operand (char *token)
            {
              /* Maybe an implied displacement of 1 again.  */
              as_bad (_("required displacement wasn't given in indirect reference"));
-             return 0;
+             free (ind_buffer);
+             return NULL;
            }
        }
       else
        {
          as_bad (_("illegal indirect reference"));
+         free (ind_buffer);
          return NULL;
        }
 
       if (found_disp && (disp_number < 0 || disp_number > 255))
        {
          as_bad (_("displacement must be an unsigned 8-bit number"));
+         free (ind_buffer);
          return NULL;
        }
 
@@ -566,6 +573,7 @@ tic30_operand (char *token)
       current_op->indirect.disp = disp_number;
       current_op->indirect.ARnum = ar_number;
       current_op->op_type = Indirect;
+      free (ind_buffer);
     }
   else
     {
@@ -594,9 +602,7 @@ tic30_operand (char *token)
              segT retval;
 
              debug ("Probably a label: %s\n", token);
-             current_op->immediate.label = malloc (strlen (token) + 1);
-             strcpy (current_op->immediate.label, token);
-             current_op->immediate.label[strlen (token)] = '\0';
+             current_op->immediate.label = xstrdup (token);
              save_input_line_pointer = input_line_pointer;
              input_line_pointer = token;
 
@@ -620,15 +626,11 @@ tic30_operand (char *token)
            }
          else
            {
-             unsigned count;
-
              debug ("Found a number or displacement\n");
              for (count = 0; count < strlen (token); count++)
                if (*(token + count) == '.')
                  current_op->immediate.decimal_found = 1;
-             current_op->immediate.label = malloc (strlen (token) + 1);
-             strcpy (current_op->immediate.label, token);
-             current_op->immediate.label[strlen (token)] = '\0';
+             current_op->immediate.label = xstrdup (token);
              current_op->immediate.f_number = (float) atof (token);
              current_op->immediate.s_number = (int) atoi (token);
              current_op->immediate.u_number = (unsigned int) atoi (token);
@@ -1119,7 +1121,7 @@ md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED,
 void
 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
                 segT sec ATTRIBUTE_UNUSED,
-                register fragS *fragP ATTRIBUTE_UNUSED)
+                fragS *fragP ATTRIBUTE_UNUSED)
 {
   debug ("In md_convert_frag()\n");
 }
@@ -1155,7 +1157,7 @@ md_apply_fix (fixS *fixP,
 
 int
 md_parse_option (int c ATTRIBUTE_UNUSED,
-                char *arg ATTRIBUTE_UNUSED)
+                const char *arg ATTRIBUTE_UNUSED)
 {
   debug ("In md_parse_option()\n");
   return 0;
@@ -1210,7 +1212,7 @@ md_pcrel_from (fixS *fixP)
   return fixP->fx_where - fixP->fx_size + (INSN_SIZE * offset);
 }
 
-char *
+const char *
 md_atof (int what_statement_type,
         char *literalP,
         int *sizeP)
@@ -1307,42 +1309,42 @@ md_atof (int what_statement_type,
        }
       if (prec == 2)
        {
-         long exp, mant;
+         long expon, mantis;
 
          if (tmsfloat == 0x80000000)
            value = 0x8000;
          else
            {
              value = 0;
-             exp = (tmsfloat & 0xFF000000);
-             exp >>= 24;
-             mant = tmsfloat & 0x007FFFFF;
+             expon = (tmsfloat & 0xFF000000);
+             expon >>= 24;
+             mantis = tmsfloat & 0x007FFFFF;
              if (tmsfloat & 0x00800000)
                {
-                 mant |= 0xFF000000;
-                 mant += 0x00000800;
-                 mant >>= 12;
-                 mant |= 0x00000800;
-                 mant &= 0x0FFF;
-                 if (exp > 7)
+                 mantis |= 0xFF000000;
+                 mantis += 0x00000800;
+                 mantis >>= 12;
+                 mantis |= 0x00000800;
+                 mantis &= 0x0FFF;
+                 if (expon > 7)
                    value = 0x7800;
                }
              else
                {
-                 mant |= 0x00800000;
-                 mant += 0x00000800;
-                 exp += (mant >> 24);
-                 mant >>= 12;
-                 mant &= 0x07FF;
-                 if (exp > 7)
+                 mantis |= 0x00800000;
+                 mantis += 0x00000800;
+                 expon += (mantis >> 24);
+                 mantis >>= 12;
+                 mantis &= 0x07FF;
+                 if (expon > 7)
                    value = 0x77FF;
                }
-             if (exp < -8)
+             if (expon < -8)
                value = 0x8000;
              if (value == 0)
                {
-                 mant = (exp << 12) | mant;
-                 value = mant & 0xFFFF;
+                 mantis = (expon << 12) | mantis;
+                 value = mantis & 0xFFFF;
                }
            }
        }
@@ -1387,9 +1389,9 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
 #undef MAP
 #undef F
 
-  rel = xmalloc (sizeof (* rel));
+  rel = XNEW (arelent);
   gas_assert (rel != 0);
-  rel->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
+  rel->sym_ptr_ptr = XNEW (asymbol *);
   *rel->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
   rel->address = fixP->fx_frag->fr_address + fixP->fx_where;
   rel->addend = 0;
@@ -1416,7 +1418,7 @@ md_operand (expressionS *expressionP ATTRIBUTE_UNUSED)
 void
 md_assemble (char *line)
 {
-  insn_template *opcode;
+  insn_template *op;
   char *current_posn;
   char *token_start;
   char save_char;
@@ -1464,11 +1466,11 @@ md_assemble (char *line)
     /* Find instruction.  */
     save_char = *current_posn;
     *current_posn = '\0';
-    opcode = (insn_template *) hash_find (op_hash, token_start);
-    if (opcode)
+    op = (insn_template *) hash_find (op_hash, token_start);
+    if (op)
       {
-       debug ("Found instruction %s\n", opcode->name);
-       insn.tm = opcode;
+       debug ("Found instruction %s\n", op->name);
+       insn.tm = op;
       }
     else
       {
This page took 0.029752 seconds and 4 git commands to generate.