public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix type mismatch caused by COMPOUND_EXPR + x folding (PR c++/33709)
Date: Tue, 30 Oct 2007 19:05:00 -0000	[thread overview]
Message-ID: <20071030183004.GQ5451@devserv.devel.redhat.com> (raw)

Hi!

This testcase breaks with --enable-checking=yes,types because fold
changed
struct S[1] *D.1111;
(struct S *) COMPOUND_EXPR <TARGET_EXPR <D.1111, ...>, D.1111> - x;
into
COMPOUND_EXPR <TARGET_EXPR <D.1111, ...>, D.1111 - x> where the outer
cast was lost.
Fixed thusly, bootstrapped/regtested on x86_64-linux.  Preapproved by richi.

2007-10-30  Jakub Jelinek  <jakub@redhat.com>

	PR c++/33709
	* fold-const.c (fold_binary): If one argument is COMPOUND_EXPR,
	convert second operand of COMPOUND_EXPR to the original type of
	that argument.

	* g++.dg/opt/compound1.C: New test.

--- gcc/fold-const.c.jj	2007-10-19 14:39:55.000000000 +0200
+++ gcc/fold-const.c	2007-10-30 14:09:39.000000000 +0100
@@ -9504,12 +9504,15 @@ fold_binary (enum tree_code code, tree t
       if (TREE_CODE (arg0) == COMPOUND_EXPR)
 	return build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
 		       fold_build2 (code, type,
-				    TREE_OPERAND (arg0, 1), op1));
+				    fold_convert (TREE_TYPE (op0),
+						  TREE_OPERAND (arg0, 1)),
+				    op1));
       if (TREE_CODE (arg1) == COMPOUND_EXPR
 	  && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0)))
 	return build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0),
-		       fold_build2 (code, type,
-				    op0, TREE_OPERAND (arg1, 1)));
+		       fold_build2 (code, type, op0,
+				    fold_convert (TREE_TYPE (op1),
+						  TREE_OPERAND (arg1, 1))));
 
       if (TREE_CODE (arg0) == COND_EXPR || COMPARISON_CLASS_P (arg0))
 	{
--- gcc/testsuite/g++.dg/opt/compound1.C.jj	2007-10-30 14:15:48.000000000 +0100
+++ gcc/testsuite/g++.dg/opt/compound1.C	2007-10-30 14:15:00.000000000 +0100
@@ -0,0 +1,11 @@
+// PR c++/33709
+// { dg-do compile }
+// { dg-options "-O2" }
+
+class S {
+  virtual void foo ();
+};
+struct T {
+  S *s;
+  void bar (unsigned x) { s = (new S[1]) - x; }
+};

	Jakub

                 reply	other threads:[~2007-10-30 18:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071030183004.GQ5451@devserv.devel.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).