This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[vta, trunk] avoid aliasing warning in decimal128.c


GCC reports strict-aliasing violations in decimal128.c.  This patch
silences the warning.

I'm installing this in the VTA branch.  Ok for trunk?

for ChangeLog.vta
from  Alexandre Oliva  <aoliva@redhat.com>

	* libdecnumber/dpd/decimal128.c (decimal128ToNumber): Use memcpy
	to copy across aliasing-incompatible types.

Index: libdecnumber/dpd/decimal128.c
===================================================================
--- libdecnumber/dpd/decimal128.c.orig	2008-07-29 17:57:06.000000000 -0300
+++ libdecnumber/dpd/decimal128.c	2008-12-13 04:37:02.000000000 -0200
@@ -1,5 +1,5 @@
 /* Decimal 128-bit format module for the decNumber C Library.
-   Copyright (C) 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
    Contributed by IBM Corporation.  Author Mike Cowlishaw.
 
    This file is part of GCC.
@@ -211,18 +211,20 @@ decNumber * decimal128ToNumber(const dec
 
   /* load source from storage; this is endian */
   pu=(const uInt *)d128->bytes;	   /* overlay */
+#define CP(to, from) (memcpy (&(to), &(from), sizeof (to)))
   if (DECLITEND) {
-    sourlo=pu[0];		   /* directly load the low int */
-    sourml=pu[1];		   /* then the mid-low */
-    sourmh=pu[2];		   /* then the mid-high */
-    sourhi=pu[3];		   /* then the high int */
+    CP (sourlo, pu[0]);		   /* directly load the low int */
+    CP (sourml, pu[1]);		   /* then the mid-low */
+    CP (sourmh, pu[2]);		   /* then the mid-high */
+    CP (sourhi, pu[3]);		   /* then the high int */
     }
    else {
-    sourhi=pu[0];		   /* directly load the high int */
-    sourmh=pu[1];		   /* then the mid-high */
-    sourml=pu[2];		   /* then the mid-low */
-    sourlo=pu[3];		   /* then the low int */
+    CP (sourhi, pu[0]);		   /* directly load the high int */
+    CP (sourmh, pu[1]);		   /* then the mid-high */
+    CP (sourml, pu[2]);		   /* then the mid-low */
+    CP (sourlo, pu[3]);		   /* then the low int */
     }
+#undef CP
 
   comb=(sourhi>>26)&0x1f;	   /* combination field */
 
-- 
Alexandre Oliva           http://www.lsd.ic.unicamp.br/~oliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

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