This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix type mismatch caused by COMPOUND_EXPR + x folding (PR c++/33709)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 30 Oct 2007 14:30:04 -0400
- Subject: [PATCH] Fix type mismatch caused by COMPOUND_EXPR + x folding (PR c++/33709)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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