[commit] Fix type-punning warnings in gdbserver

Daniel Jacobowitz drow@false.org
Fri Mar 30 17:15:00 GMT 2007


I've been meaning to do this for ages; it removes the warnings while
building gdbserver on i386-linux or x86_64-linux.  Tested on
x86_64-linux without regression and committed.

-- 
Daniel Jacobowitz
CodeSourcery

2007-03-30  Daniel Jacobowitz  <dan@codesourcery.com>

	* i387-fp.c (struct i387_fsave, struct i387_fxsave): Make 16-bit
	fields short instead of int.  Add explicit padding.
	(i387_cache_to_fsave): Remove unnecessary casts.
	(i387_fsave_to_cache): Doc fix.
	(i387_cache_to_fxsave): Remove unnecessary casts and masking.

Index: i387-fp.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/i387-fp.c,v
retrieving revision 1.6
diff -u -p -r1.6 i387-fp.c
--- i387-fp.c	30 Mar 2007 15:29:46 -0000	1.6
+++ i387-fp.c	30 Mar 2007 17:10:33 -0000
@@ -32,14 +32,18 @@ int num_xmm_registers = 8;
 struct i387_fsave {
   /* All these are only sixteen bits, plus padding, except for fop (which
      is only eleven bits), and fooff / fioff (which are 32 bits each).  */
-  unsigned int fctrl;
-  unsigned int fstat;
-  unsigned int ftag;
+  unsigned short fctrl;
+  unsigned short pad1;
+  unsigned short fstat;
+  unsigned short pad2;
+  unsigned short ftag;
+  unsigned short pad3;
   unsigned int fioff;
   unsigned short fiseg;
   unsigned short fop;
   unsigned int fooff;
-  unsigned int foseg;
+  unsigned short foseg;
+  unsigned short pad4;
 
   /* Space for eight 80-bit FP values.  */
   unsigned char st_space[80];
@@ -53,13 +57,14 @@ struct i387_fxsave {
   unsigned short ftag;
   unsigned short fop;
   unsigned int fioff;
-  unsigned int fiseg;
+  unsigned short fiseg;
+  unsigned short pad1;
   unsigned int fooff;
-  unsigned int foseg;
+  unsigned short foseg;
+  unsigned short pad12;
 
   unsigned int mxcsr;
-
-  unsigned int _pad1;
+  unsigned int pad3;
 
   /* Space for eight 80-bit FP values in 128-bit spaces.  */
   unsigned char st_space[128];
@@ -88,23 +93,23 @@ i387_cache_to_fsave (void *buf)
 
   /* Some registers are 16-bit.  */
   collect_register_by_name ("fctrl", &val);
-  *(unsigned short *) &fp->fctrl = val;
+  fp->fctrl = val;
 
   collect_register_by_name ("fstat", &val);
   val &= 0xFFFF;
-  *(unsigned short *) &fp->fstat = val;
+  fp->fstat = val;
 
   collect_register_by_name ("ftag", &val);
   val &= 0xFFFF;
-  *(unsigned short *) &fp->ftag = val;
+  fp->ftag = val;
 
   collect_register_by_name ("fiseg", &val);
   val &= 0xFFFF;
-  *(unsigned short *) &fp->fiseg = val;
+  fp->fiseg = val;
 
   collect_register_by_name ("foseg", &val);
   val &= 0xFFFF;
-  *(unsigned short *) &fp->foseg = val;
+  fp->foseg = val;
 }
 
 void
@@ -137,6 +142,7 @@ i387_fsave_to_cache (const void *buf)
   val = fp->foseg & 0xFFFF;
   supply_register_by_name ("foseg", &val);
 
+  /* fop has only 11 valid bits.  */
   val = (fp->fop) & 0x7FF;
   supply_register_by_name ("fop", &val);
 }
@@ -165,11 +171,10 @@ i387_cache_to_fxsave (void *buf)
 
   /* Some registers are 16-bit.  */
   collect_register_by_name ("fctrl", &val);
-  *(unsigned short *) &fp->fctrl = val;
+  fp->fctrl = val;
 
   collect_register_by_name ("fstat", &val);
-  val &= 0xFFFF;
-  *(unsigned short *) &fp->fstat = val;
+  fp->fstat = val;
 
   /* Convert to the simplifed tag form stored in fxsave data.  */
   collect_register_by_name ("ftag", &val);
@@ -182,15 +187,13 @@ i387_cache_to_fxsave (void *buf)
       if (tag != 3)
 	val2 |= (1 << i);
     }
-  *(unsigned short *) &fp->ftag = val2;
+  fp->ftag = val2;
 
   collect_register_by_name ("fiseg", &val);
-  val &= 0xFFFF;
-  *(unsigned short *) &fp->fiseg = val;
+  fp->fiseg = val;
 
   collect_register_by_name ("foseg", &val);
-  val &= 0xFFFF;
-  *(unsigned short *) &fp->foseg = val;
+  fp->foseg = val;
 }
 
 static int



More information about the Gdb-patches mailing list