This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Work-around for bug in ancient SPARC Sun C compiler


On Feb 11, 2002, Alan Modra <amodra@bigpond.net.au> wrote:

> On Mon, Feb 11, 2002 at 04:47:30AM -0200, Alexandre Oliva wrote:
>> +/* Some ancient Sun C compilers would not take such hex constants as
>> +   unsigned, and would end up sign-extending them to form an offsetT,
>> +   so use these constants instead.  */
>> +#define U0xffffffffl ((((unsigned long)1 << 16) << 16) - 1)
>> +#define U0x80000000l ((((unsigned long)1 << 16) << 15))

> I think the defines would look better without the trailing 'l', and
> you need a space after the cast to meet GNU coding guidelines.
> Otherwise OK.

Thanks, here's what I'm checking in:

Index: gas/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* config/tc-sparc.c (U0x80000000, U0xffffffff): New constants.
	Use all over.

Index: gas/config/tc-sparc.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-sparc.c,v
retrieving revision 1.38
diff -u -p -r1.38 tc-sparc.c
--- gas/config/tc-sparc.c 2001/12/21 22:35:24 1.38
+++ gas/config/tc-sparc.c 2002/02/11 06:39:45
@@ -1,6 +1,6 @@
 /* tc-sparc.c -- Assemble for the SPARC
    Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001
+   1999, 2000, 2001, 2002
    Free Software Foundation, Inc.
    This file is part of GAS, the GNU Assembler.
 
@@ -32,6 +32,12 @@
 #include "dwarf2dbg.h"
 #endif
 
+/* Some ancient Sun C compilers would not take such hex constants as
+   unsigned, and would end up sign-extending them to form an offsetT,
+   so use these constants instead.  */
+#define U0xffffffff ((((unsigned long) 1 << 16) << 16) - 1)
+#define U0x80000000 ((((unsigned long) 1 << 16) << 15))
+
 static struct sparc_arch *lookup_arch PARAMS ((char *));
 static void init_default_arch PARAMS ((void));
 static int sparc_ip PARAMS ((char *, const struct sparc_opcode **));
@@ -916,7 +922,7 @@ in_signed_range (val, max)
   if (sparc_arch_size == 32)
     {
       bfd_signed_vma sign = (bfd_signed_vma) 1 << 31;
-      val = ((val & 0xffffffff) ^ sign) - sign;
+      val = ((val & U0xffffffff) ^ sign) - sign;
     }
   if (val > max)
     return 0;
@@ -1019,14 +1025,14 @@ synthetize_setuw (insn)
 	{
 	  if (sizeof (offsetT) > 4
 	      && (the_insn.exp.X_add_number < 0
-		  || the_insn.exp.X_add_number > (offsetT) 0xffffffff))
+		  || the_insn.exp.X_add_number > (offsetT) U0xffffffff))
 	    as_warn (_("set: number not in 0..4294967295 range"));
 	}
       else
 	{
 	  if (sizeof (offsetT) > 4
-	      && (the_insn.exp.X_add_number < -(offsetT) 0x80000000
-		  || the_insn.exp.X_add_number > (offsetT) 0xffffffff))
+	      && (the_insn.exp.X_add_number < -(offsetT) U0x80000000
+		  || the_insn.exp.X_add_number > (offsetT) U0xffffffff))
 	    as_warn (_("set: number not in -2147483648..4294967295 range"));
 	  the_insn.exp.X_add_number = (int) the_insn.exp.X_add_number;
 	}
@@ -1085,8 +1091,8 @@ synthetize_setsw (insn)
     }
 
   if (sizeof (offsetT) > 4
-      && (the_insn.exp.X_add_number < -(offsetT) 0x80000000
-	  || the_insn.exp.X_add_number > (offsetT) 0xffffffff))
+      && (the_insn.exp.X_add_number < -(offsetT) U0x80000000
+	  || the_insn.exp.X_add_number > (offsetT) U0xffffffff))
     as_warn (_("setsw: number not in -2147483648..4294967295 range"));
 
   low32 = the_insn.exp.X_add_number;
@@ -1128,7 +1134,7 @@ synthetize_setx (insn)
   int need_hh22_p = 0, need_hm10_p = 0, need_hi22_p = 0, need_lo10_p = 0;
   int need_xor10_p = 0;
 
-#define SIGNEXT32(x) ((((x) & 0xffffffff) ^ 0x80000000) - 0x80000000)
+#define SIGNEXT32(x) ((((x) & U0xffffffff) ^ U0x80000000) - U0x80000000)
   lower32 = SIGNEXT32 (the_insn.exp.X_add_number);
   upper32 = SIGNEXT32 (BSR (the_insn.exp.X_add_number, 32));
 #undef SIGNEXT32
Index: opcodes/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* sparc-dis.c (print_insn_sparc): Make sure 0xFFFFFFFF is not
	sign-extended.

Index: opcodes/sparc-dis.c
===================================================================
RCS file: /cvs/src/src/opcodes/sparc-dis.c,v
retrieving revision 1.5
diff -u -p -r1.5 sparc-dis.c
--- opcodes/sparc-dis.c 2001/03/13 22:58:37 1.5
+++ opcodes/sparc-dis.c 2002/02/11 06:43:58
@@ -419,7 +419,7 @@ print_insn_sparc (memaddr, info)
 
 		  case 'h':
 		    (*info->fprintf_func) (stream, "%%hi(%#x)",
-					   (0xFFFFFFFF
+					   ((unsigned) 0xFFFFFFFF
 					    & ((int) X_IMM22 (insn) << 10)));
 		    break;
 
@@ -716,7 +716,8 @@ print_insn_sparc (memaddr, info)
 		    {
 		      (*info->fprintf_func) (stream, "\t! ");
 		      info->target = 
-			(0xFFFFFFFF & (int) X_IMM22 (prev_insn) << 10);
+			((unsigned) 0xFFFFFFFF
+			 & ((int) X_IMM22 (prev_insn) << 10));
 		      if (imm_added_to_rs1)
 			info->target += X_SIMM (insn, 13);
 		      else

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]