public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix up fold_convert_loc for MODIFY_EXPR converted to void (PR c/48685)
@ 2011-04-23  9:06 Jakub Jelinek
  2011-04-23 11:34 ` Richard Guenther
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2011-04-23  9:06 UTC (permalink / raw)
  To: gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix up fold_convert_loc for MODIFY_EXPR converted to void (PR c/48685)
  2011-04-23  9:06 [PATCH] Fix up fold_convert_loc for MODIFY_EXPR converted to void (PR c/48685) Jakub Jelinek
@ 2011-04-23 11:34 ` Richard Guenther
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Guenther @ 2011-04-23 11:34 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Sat, Apr 23, 2011 at 8:36 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> 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?

Ok.

Thanks,
Richard.

> 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
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-04-23  9:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-23  9:06 [PATCH] Fix up fold_convert_loc for MODIFY_EXPR converted to void (PR c/48685) Jakub Jelinek
2011-04-23 11:34 ` Richard Guenther

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).