[PATCH] Fix PR28045
Richard Guenther
rguenther@suse.de
Mon Jun 19 09:33:00 GMT 2006
This fixes PR28045, a bug in operand_equal_p that thinks that
(long)a.val == a.val, which in turn causes fold_range_test to emit
wrong code.
Bootstrapped and tested on x86_64-unknown-linux-gnu.
Ok for mainline and branches?
Thanks,
Richard.
:ADDPATCH middle-end:
2006-06-18 Richard Guenther <rguenther@suse.de>
PR middle-end/28045
* fold-const.c (operand_equal_p): Check if the argument types
have the same precision before stripping NOPs.
* gcc.dg/torture/pr28045.c: New testcase.
Index: fold-const.c
===================================================================
*** fold-const.c (revision 114755)
--- fold-const.c (working copy)
*************** operand_equal_p (tree arg0, tree arg1, u
*** 2497,2502 ****
--- 2497,2507 ----
if (TYPE_UNSIGNED (TREE_TYPE (arg0)) != TYPE_UNSIGNED (TREE_TYPE (arg1)))
return 0;
+ /* If both types don't have the same precision, then it is not safe
+ to strip NOPs. */
+ if (TYPE_PRECISION (TREE_TYPE (arg0)) != TYPE_PRECISION (TREE_TYPE (arg1)))
+ return 0;
+
STRIP_NOPS (arg0);
STRIP_NOPS (arg1);
/* { dg-do run } */
extern void abort(void);
struct a
{
unsigned int bits : 1;
signed long val : ((sizeof(long) * 8) - 1);
};
int Fnegate (struct a b)
{
if ((-((long)b.val)) <= ((long) ((1UL << ((sizeof(long) * 8) - 2)) -1UL))
&& (-((long)b.val)) >= (-(((long) ((1UL << ((sizeof(long) * 8) - 2)) -1UL))) - 1))
return 0 ;
abort ();
}
int main ()
{
struct a b = {1, 1};
Fnegate (b);
return 0;
}
More information about the Gcc-patches
mailing list