This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix up fold_convert_loc for MODIFY_EXPR converted to void (PR c/48685)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 23 Apr 2011 08:36:29 +0200
- Subject: [PATCH] Fix up fold_convert_loc for MODIFY_EXPR converted to void (PR c/48685)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
Roger changed fold_convert* back in 2007 to not actually convert to void
GIMPLE_MODIFY_STMT:
http://gcc.gnu.org/ml/gcc-patches/2007-01/msg00279.html
as GIMPLE_MODIFY_STMT didn't have TREE_TYPE and thus converting it to
void has been difficult.
That == GIMPLE_MODIFY_STMT check has been changed into == MODIFY_EXPR
during real tuplification apparently, but MODIFY_EXPR has a type
and can be converted to void_type_node type just fine. Not doing so
breaks e.g. following testcase, because fold_convert_loc (void_type_node, modify_expr);
doesn't actually yield a void_type_node tree and if it is inside of
NON_LVALUE_EXPR with void type, the NON_LVALUE_EXPR won't be removed.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk/4.6?
2011-04-23 Jakub Jelinek <jakub@redhat.com>
PR c/48685
* fold-const.c (fold_convert_loc): Add NOP_EXPR when casting
to VOID_TYPE even around MODIFY_EXPR.
* gcc.dg/pr48685.c: New test.
--- gcc/fold-const.c.jj 2011-04-18 11:28:05.000000000 +0200
+++ gcc/fold-const.c 2011-04-22 21:21:51.000000000 +0200
@@ -2029,8 +2029,6 @@ fold_convert_loc (location_t loc, tree t
case VOID_TYPE:
tem = fold_ignored_result (arg);
- if (TREE_CODE (tem) == MODIFY_EXPR)
- goto fold_convert_exit;
return fold_build1_loc (loc, NOP_EXPR, type, tem);
default:
--- gcc/testsuite/gcc.dg/pr48685.c.jj 2011-04-22 21:24:01.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr48685.c 2011-04-22 21:24:14.000000000 +0200
@@ -0,0 +1,11 @@
+/* PR c/48685 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int
+main ()
+{
+ int v = 1;
+ (void) (1 == 2 ? (void) 0 : (v = 0));
+ return v;
+}
Jakub