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]

Applied patch to fp-bit.c


I've applied the following patch to gcc.  While chasing another problem, I
noticed that we had potential problems wrt. aliasing in fp-bit.c.  While the
code will not be broken by -fstrict-aliasing, there are other aliasing checks
in gcc (MEM_IN_STRUCT vs. MEM_SCALAR_P tests) which can cause this type of
code to be miscompiled.

Approved by Jim Wilson.

Bernd

	* fp-bit.c (add, sub, multiply, divide, compare, _eq_f2, _ne_f2,
	_gt_f2, _ge_f2, _lt_f2, _le_f2, float_to_si, float_to_usi, negate,
	sf_to_df, df_to_sf): Likewise.

Index: config/fp-bit.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/config/fp-bit.c,v
retrieving revision 1.57
diff -u -p -r1.57 fp-bit.c
--- config/fp-bit.c	1998/11/23 07:32:12	1.57
+++ config/fp-bit.c	1999/08/26 20:23:14
@@ -780,10 +780,14 @@ add (FLO_type arg_a, FLO_type arg_b)
   fp_number_type b;
   fp_number_type tmp;
   fp_number_type *res;
+  FLO_union_type au, bu;
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
-  unpack_d ((FLO_union_type *) & arg_b, &b);
+  au.value = arg_a;
+  bu.value = arg_b;
 
+  unpack_d (&au, &a);
+  unpack_d (&bu, &b);
+
   res = _fpadd_parts (&a, &b, &tmp);
 
   return pack_d (res);
@@ -796,9 +800,13 @@ sub (FLO_type arg_a, FLO_type arg_b)
   fp_number_type b;
   fp_number_type tmp;
   fp_number_type *res;
+  FLO_union_type au, bu;
+
+  au.value = arg_a;
+  bu.value = arg_b;
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
-  unpack_d ((FLO_union_type *) & arg_b, &b);
+  unpack_d (&au, &a);
+  unpack_d (&bu, &b);
 
   b.sign ^= 1;
 
@@ -986,10 +994,14 @@ multiply (FLO_type arg_a, FLO_type arg_b
   fp_number_type b;
   fp_number_type tmp;
   fp_number_type *res;
+  FLO_union_type au, bu;
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
-  unpack_d ((FLO_union_type *) & arg_b, &b);
+  au.value = arg_a;
+  bu.value = arg_b;
 
+  unpack_d (&au, &a);
+  unpack_d (&bu, &b);
+
   res = _fpmul_parts (&a, &b, &tmp);
 
   return pack_d (res);
@@ -1092,9 +1104,13 @@ divide (FLO_type arg_a, FLO_type arg_b)
   fp_number_type a;
   fp_number_type b;
   fp_number_type *res;
+  FLO_union_type au, bu;
+
+  au.value = arg_a;
+  bu.value = arg_b;
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
-  unpack_d ((FLO_union_type *) & arg_b, &b);
+  unpack_d (&au, &a);
+  unpack_d (&bu, &b);
 
   res = _fpdiv_parts (&a, &b);
 
@@ -1195,10 +1211,14 @@ compare (FLO_type arg_a, FLO_type arg_b)
 {
   fp_number_type a;
   fp_number_type b;
+  FLO_union_type au, bu;
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
-  unpack_d ((FLO_union_type *) & arg_b, &b);
+  au.value = arg_a;
+  bu.value = arg_b;
 
+  unpack_d (&au, &a);
+  unpack_d (&bu, &b);
+
   return __fpcmp_parts (&a, &b);
 }
 #endif
@@ -1213,9 +1233,13 @@ _eq_f2 (FLO_type arg_a, FLO_type arg_b)
 {
   fp_number_type a;
   fp_number_type b;
+  FLO_union_type au, bu;
+
+  au.value = arg_a;
+  bu.value = arg_b;
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
-  unpack_d ((FLO_union_type *) & arg_b, &b);
+  unpack_d (&au, &a);
+  unpack_d (&bu, &b);
 
   if (isnan (&a) || isnan (&b))
     return 1;			/* false, truth == 0 */
@@ -1230,10 +1254,14 @@ _ne_f2 (FLO_type arg_a, FLO_type arg_b)
 {
   fp_number_type a;
   fp_number_type b;
+  FLO_union_type au, bu;
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
-  unpack_d ((FLO_union_type *) & arg_b, &b);
+  au.value = arg_a;
+  bu.value = arg_b;
 
+  unpack_d (&au, &a);
+  unpack_d (&bu, &b);
+
   if (isnan (&a) || isnan (&b))
     return 1;			/* true, truth != 0 */
 
@@ -1247,9 +1275,13 @@ _gt_f2 (FLO_type arg_a, FLO_type arg_b)
 {
   fp_number_type a;
   fp_number_type b;
+  FLO_union_type au, bu;
+
+  au.value = arg_a;
+  bu.value = arg_b;
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
-  unpack_d ((FLO_union_type *) & arg_b, &b);
+  unpack_d (&au, &a);
+  unpack_d (&bu, &b);
 
   if (isnan (&a) || isnan (&b))
     return -1;			/* false, truth > 0 */
@@ -1264,10 +1296,14 @@ _ge_f2 (FLO_type arg_a, FLO_type arg_b)
 {
   fp_number_type a;
   fp_number_type b;
+  FLO_union_type au, bu;
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
-  unpack_d ((FLO_union_type *) & arg_b, &b);
+  au.value = arg_a;
+  bu.value = arg_b;
 
+  unpack_d (&au, &a);
+  unpack_d (&bu, &b);
+
   if (isnan (&a) || isnan (&b))
     return -1;			/* false, truth >= 0 */
   return __fpcmp_parts (&a, &b) ;
@@ -1280,9 +1316,13 @@ _lt_f2 (FLO_type arg_a, FLO_type arg_b)
 {
   fp_number_type a;
   fp_number_type b;
+  FLO_union_type au, bu;
+
+  au.value = arg_a;
+  bu.value = arg_b;
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
-  unpack_d ((FLO_union_type *) & arg_b, &b);
+  unpack_d (&au, &a);
+  unpack_d (&bu, &b);
 
   if (isnan (&a) || isnan (&b))
     return 1;			/* false, truth < 0 */
@@ -1297,10 +1337,14 @@ _le_f2 (FLO_type arg_a, FLO_type arg_b)
 {
   fp_number_type a;
   fp_number_type b;
+  FLO_union_type au, bu;
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
-  unpack_d ((FLO_union_type *) & arg_b, &b);
+  au.value = arg_a;
+  bu.value = arg_b;
 
+  unpack_d (&au, &a);
+  unpack_d (&bu, &b);
+
   if (isnan (&a) || isnan (&b))
     return 1;			/* false, truth <= 0 */
 
@@ -1354,8 +1398,11 @@ float_to_si (FLO_type arg_a)
 {
   fp_number_type a;
   SItype tmp;
+  FLO_union_type au;
+
+  au.value = arg_a;
+  unpack_d (&au, &a);
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
   if (iszero (&a))
     return 0;
   if (isnan (&a))
@@ -1385,8 +1432,11 @@ USItype
 float_to_usi (FLO_type arg_a)
 {
   fp_number_type a;
+  FLO_union_type au;
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
+  au.value = arg_a;
+  unpack_d (&au, &a);
+
   if (iszero (&a))
     return 0;
   if (isnan (&a))
@@ -1415,8 +1465,11 @@ FLO_type
 negate (FLO_type arg_a)
 {
   fp_number_type a;
+  FLO_union_type au;
+
+  au.value = arg_a;
+  unpack_d (&au, &a);
 
-  unpack_d ((FLO_union_type *) & arg_a, &a);
   flip_sign (&a);
   return pack_d (&a);
 }
@@ -1455,8 +1508,11 @@ DFtype
 sf_to_df (SFtype arg_a)
 {
   fp_number_type in;
+  FLO_union_type au;
+
+  au.value = arg_a;
+  unpack_d (&au, &in);
 
-  unpack_d ((FLO_union_type *) & arg_a, &in);
   return __make_dp (in.class, in.sign, in.normal_exp,
 		    ((UDItype) in.fraction.ll) << F_D_BITOFF);
 }
@@ -1489,8 +1545,10 @@ df_to_sf (DFtype arg_a)
 {
   fp_number_type in;
   USItype sffrac;
+  FLO_union_type au;
 
-  unpack_d ((FLO_union_type *) & arg_a, &in);
+  au.value = arg_a;
+  unpack_d (&au, &in);
 
   sffrac = in.fraction.ll >> F_D_BITOFF;
 




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