[PATCH][4.2] Work around PR31136
Richard Guenther
rguenther@suse.de
Sat Apr 21 18:06:00 GMT 2007
This patch works around the fact that FRE does constant propagation
without folding the result. This may cause us to call fold_unary
with (<unnamed-unsigned:6>)(<unnamed-unsigned:4>) 31:6 which is folded
incorrectly by fold_convert_const which we ask to convert
31:6 to (<unnamed-unsigned:6>). The patch fixes that by asking it to
fold (<unnamed-unsigned:4>) 31:6 instead - a no-op patch in case we'd
have folded arguments to fold_unary.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to the
mainline and the 4.2 branch.
Richard.
2007-04-21 Richard Guenther <rguenther@suse.de>
PR middle-end/31136
* fold-const.c (fold_unary): Call fold_convert_const on the
original tree.
* gcc.c-torture/execute/pr31136.c: New testcase.
Index: fold-const.c
===================================================================
*** fold-const.c (revision 124018)
--- fold-const.c (working copy)
*************** fold_unary (enum tree_code code, tree ty
*** 7734,7740 ****
return fold_build1 (BIT_NOT_EXPR, type, fold_convert (type, tem));
}
! tem = fold_convert_const (code, type, arg0);
return tem ? tem : NULL_TREE;
case VIEW_CONVERT_EXPR:
--- 7734,7740 ----
return fold_build1 (BIT_NOT_EXPR, type, fold_convert (type, tem));
}
! tem = fold_convert_const (code, type, op0);
return tem ? tem : NULL_TREE;
case VIEW_CONVERT_EXPR:
Index: testsuite/gcc.c-torture/execute/pr31136.c
===================================================================
*** testsuite/gcc.c-torture/execute/pr31136.c (revision 0)
--- testsuite/gcc.c-torture/execute/pr31136.c (revision 0)
***************
*** 0 ****
--- 1,17 ----
+ extern void abort (void);
+
+ struct S {
+ unsigned b4:4;
+ unsigned b6:6;
+ } s;
+
+ int main()
+ {
+ s.b6 = 31;
+ s.b4 = s.b6;
+ s.b6 = s.b4;
+ if (s.b6 != 15)
+ abort ();
+ return 0;
+ }
+
More information about the Gcc-patches
mailing list