* [PATCH] Fix type mismatch caused by COMPOUND_EXPR + x folding (PR c++/33709)
@ 2007-10-30 19:05 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2007-10-30 19:05 UTC (permalink / raw)
To: gcc-patches
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-10-30 18:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-30 19:05 [PATCH] Fix type mismatch caused by COMPOUND_EXPR + x folding (PR c++/33709) Jakub Jelinek
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).