crx: ubsan: cannot be represented

Alan Modra amodra@gmail.com
Mon Aug 31 10:50:24 GMT 2020


	* config/tc-crx.c: Formatting.
	(CRX_PRINT): Wrap params in parentheses.  Remove parens from uses
	throughout file.
	(reset_vars, get_register, get_copregister, get_optype, get_opbits),
	(get_opflags, get_number_of_operands, parse_operand, gettrap),
	(handle_LoadStor, getconstant, check_range, getreg_image),
	(parse_operands, parse_insn, print_operand, print_constant),
	(exponent2scale, mask_reg, process_label_constant, set_operand),
	(assemble_insn, print_insn): Delete unnecessary forward declaration.
	(print_insn): Make static.
	(print_constant): Make "constant" unsigned.
	(assemble_insn): Tidy REVERSE_MATCH index calc.
	* expr.c (generic_bignum_to_int32): Cast elements to valueT.

diff --git a/gas/config/tc-crx.c b/gas/config/tc-crx.c
index 03a5e6e322..041b9eb777 100644
--- a/gas/config/tc-crx.c
+++ b/gas/config/tc-crx.c
@@ -47,7 +47,7 @@
 
 /* Assign a number NUM, shifted by SHIFT bytes, into a location
    pointed by index BYTE of array 'output_opcode'.  */
-#define CRX_PRINT(BYTE, NUM, SHIFT)   output_opcode[BYTE] |= (NUM << SHIFT)
+#define CRX_PRINT(BYTE, NUM, SHIFT)   output_opcode[BYTE] |= (NUM) << (SHIFT)
 
 /* Operand errors.  */
 typedef enum
@@ -140,31 +140,8 @@ const relax_typeS md_relax_table[] =
   {0xfffffe, -0x1000000, 6, 0}		/* 24 */
 };
 
-static void    reset_vars	        (char *);
-static reg     get_register	        (char *);
-static copreg  get_copregister	        (char *);
-static argtype get_optype	        (operand_type);
-static int     get_opbits	        (operand_type);
-static int     get_opflags	        (operand_type);
-static int     get_number_of_operands   (void);
-static void    parse_operand	        (char *, ins *);
-static int     gettrap		        (const char *);
-static void    handle_LoadStor	        (const char *);
 static int     get_cinv_parameters	(const char *);
-static long    getconstant		(long, int);
-static op_err  check_range		(long *, int, unsigned int, int);
-static int     getreg_image	        (int);
-static void    parse_operands	        (ins *, char *);
-static void    parse_insn	        (ins *, char *);
-static void    print_operand	        (int, int, argument *);
-static void    print_constant	        (int, int, argument *);
-static int     exponent2scale	        (int);
-static void    mask_reg		        (int, unsigned short *);
-static void    process_label_constant   (char *, ins *);
-static void    set_operand	        (char *, ins *);
 static char *  preprocess_reglist	(char *, int *);
-static int     assemble_insn	        (char *, ins *);
-static void    print_insn	        (ins *);
 static void    warn_if_needed		(ins *);
 static int     adjust_if_needed		(ins *);
 
@@ -1169,8 +1146,7 @@ static void
 print_constant (int nbits, int shift, argument *arg)
 {
   unsigned long mask = 0;
-
-  long constant = getconstant (arg->constant, nbits);
+  unsigned long constant = getconstant (arg->constant, nbits);
 
   switch (nbits)
   {
@@ -1191,7 +1167,7 @@ print_constant (int nbits, int shift, argument *arg)
 	      output_opcode[0]    output_opcode[1]     */
 
       CRX_PRINT (0, (constant >> WORD_SHIFT) & mask, 0);
-      CRX_PRINT (1, (constant & 0xFFFF), WORD_SHIFT);
+      CRX_PRINT (1, constant & 0xFFFF, WORD_SHIFT);
       break;
 
     case 16:
@@ -1516,10 +1492,7 @@ assemble_insn (char *mnemonic, ins *insn)
 	     Index 0	  -->> 1
 	     Index 1	  -->> 0
 	     Other index  -->> stays the same.  */
-	  int j = instruction->flags & REVERSE_MATCH ?
-		  i == 0 ? 1 :
-		  i == 1 ? 0 : i :
-		  i;
+	  int j = (instruction->flags & REVERSE_MATCH) && i <= 1 ? 1 - i : i;
 
 	  /* Only check range - don't update the constant's value, since the
 	     current instruction may not be the last we try to match.
@@ -1569,10 +1542,12 @@ assemble_insn (char *mnemonic, ins *insn)
 	      as_bad (_("Operand out of range (arg %d)"), invalid_const);
 	      break;
 	    case OP_NOT_EVEN:
-	  as_bad (_("Operand has odd displacement (arg %d)"), invalid_const);
+	      as_bad (_("Operand has odd displacement (arg %d)"),
+		      invalid_const);
 	      break;
 	    case OP_ILLEGAL_DISPU4:
-	  as_bad (_("Invalid DISPU4 operand value (arg %d)"), invalid_const);
+	      as_bad (_("Invalid DISPU4 operand value (arg %d)"),
+		      invalid_const);
 	      break;
 	    case OP_ILLEGAL_CST4:
 	      as_bad (_("Invalid CST4 operand value (arg %d)"), invalid_const);
@@ -1604,10 +1579,7 @@ assemble_insn (char *mnemonic, ins *insn)
 
       for (i = 0; i < insn->nargs; i++)
 	{
-	  int j = instruction->flags & REVERSE_MATCH ?
-		  i == 0 ? 1 :
-		  i == 1 ? 0 : i :
-		  i;
+	  int j = (instruction->flags & REVERSE_MATCH) && i <= 1 ? 1 - i : i;
 
 	  /* This time, update constant value before printing it.  */
 	  if ((insn->arg[j].X_op == O_constant)
@@ -1864,7 +1836,7 @@ preprocess_reglist (char *param, int *allocated)
 /* Print the instruction.
    Handle also cases where the instruction is relaxable/relocatable.  */
 
-void
+static void
 print_insn (ins *insn)
 {
   unsigned int i, j, insn_size;
diff --git a/gas/expr.c b/gas/expr.c
index 7c002c0d96..da4fbcf8cd 100644
--- a/gas/expr.c
+++ b/gas/expr.c
@@ -224,8 +224,8 @@ static valueT
 generic_bignum_to_int32 (void)
 {
   valueT number =
-	   ((generic_bignum[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
-	   | (generic_bignum[0] & LITTLENUM_MASK);
+    ((((valueT) generic_bignum[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
+     | ((valueT) generic_bignum[0] & LITTLENUM_MASK));
   number &= 0xffffffff;
   return number;
 }


More information about the Binutils mailing list