[3/3] S12Z/GAS: Correct a signed vs unsigned comparison error with GCC 4.1

Message ID alpine.LFD.2.21.1809141949510.16413@eddie.linux-mips.org
State New
Headers show
Series
  • A bunch of C89 and GCC 4.1.2 fixes
Related show

Commit Message

Maciej W. Rozycki Sept. 19, 2018, 12:56 p.m.
Fix a build error:

cc1: warnings being treated as errors
.../gas/config/tc-s12z.c: In function 'lex_opr':
.../gas/config/tc-s12z.c:617: warning: comparison between signed and unsigned
.../gas/config/tc-s12z.c:624: warning: comparison between signed and unsigned
make[4]: *** [config/tc-s12z.o] Error 1

observed with GCC 4.1.2 with the `s12z-elf' target.

Here we have a constant assembly instruction operand, whose value is 
within the 24-bit unsigned range, to be placed in a machine instruction 
such as to use the least space-consuming encoding.  So the sign of that 
value does not matter, because signed values are out of range and are 
not supposed to appear here, and we only have this warning here because 
the `X_add_number' member of `struct expressionS' is of the `offsetT' 
type, which is signed.

Use an auxiliary variable of an unsigned data type then, observing that 
both `offsetT' and `valueT' have the same width, as they correspond to 
`bfd_signed_vma' and `bfd_vma' respectively.

	gas/
	* config/tc-s12z.c (lex_opr): Use an auxiliary unsigned variable
	in encoding a constant operand.
---
 gas/config/tc-s12z.c |   24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

binutils-s12z-gas-opr-constant.diff

Comments

Nick Clifton Sept. 19, 2018, 3:02 p.m. | #1
Hi Maciej,

> 	gas/

> 	* config/tc-s12z.c (lex_opr): Use an auxiliary unsigned variable

> 	in encoding a constant operand.


Approved - please apply.

Cheers
  Nick

PS. I am assuming that Alan will review patch 2...
Maciej W. Rozycki Sept. 20, 2018, 2:57 p.m. | #2
Hi Nick,

> > 	gas/

> > 	* config/tc-s12z.c (lex_opr): Use an auxiliary unsigned variable

> > 	in encoding a constant operand.

> 

> Approved - please apply.


 Applied, thanks for your review.

 This is I believe the last bit oustanding I had for the time being, so 
I'll be moving on to my other projects for now.

  Maciej

Patch

Index: src/gas/config/tc-s12z.c
===================================================================
--- src.orig/gas/config/tc-s12z.c
+++ src/gas/config/tc-s12z.c
@@ -614,31 +614,33 @@  lex_opr (uint8_t *buffer, int *n_bytes, 
       buffer[3] = 0;
       if (exp->X_op == O_constant)
 	{
-	  if (exp->X_add_number < (0x1U << 14))
+	  valueT value = exp->X_add_number;
+
+	  if (value < (0x1U << 14))
 	    {
 	      *xb = 0x00;
 	      *n_bytes = 2;
-	      *xb |= exp->X_add_number >> 8;
-	      buffer[1] = exp->X_add_number;
+	      *xb |= value >> 8;
+	      buffer[1] = value;
 	    }
-	  else if (exp->X_add_number < (0x1U << 19))
+	  else if (value < (0x1U << 19))
 	    {
 	      *xb = 0xf8;
-	      if (exp->X_add_number & (0x1U << 17))
+	      if (value & (0x1U << 17))
 		*xb |= 0x04;
-	      if (exp->X_add_number & (0x1U << 16))
+	      if (value & (0x1U << 16))
 		*xb |= 0x01;
 	      *n_bytes = 3;
-	      buffer[1] = exp->X_add_number >> 8;
-	      buffer[2] = exp->X_add_number;
+	      buffer[1] = value >> 8;
+	      buffer[2] = value;
 	    }
 	  else
 	    {
 	      *xb = 0xfa;
 	      *n_bytes = 4;
-	      buffer[1] = exp->X_add_number >> 16;
-	      buffer[2] = exp->X_add_number >> 8;
-	      buffer[3] = exp->X_add_number;
+	      buffer[1] = value >> 16;
+	      buffer[2] = value >> 8;
+	      buffer[3] = value;
 	    }
 	}
       return 1;