From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16003 invoked by alias); 30 Oct 2007 18:30:17 -0000 Received: (qmail 15928 invoked by uid 22791); 30 Oct 2007 18:30:13 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 30 Oct 2007 18:30:07 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.1) with ESMTP id l9UIU5ak027115 for ; Tue, 30 Oct 2007 14:30:05 -0400 Received: from devserv.devel.redhat.com (devserv.devel.redhat.com [10.10.36.72]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l9UIU4AL020146 for ; Tue, 30 Oct 2007 14:30:05 -0400 Received: from devserv.devel.redhat.com (localhost.localdomain [127.0.0.1]) by devserv.devel.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id l9UIU4vC012250 for ; Tue, 30 Oct 2007 14:30:04 -0400 Received: (from jakub@localhost) by devserv.devel.redhat.com (8.12.11.20060308/8.12.11/Submit) id l9UIU4b3012248 for gcc-patches@gcc.gnu.org; Tue, 30 Oct 2007 14:30:04 -0400 Date: Tue, 30 Oct 2007 19:05:00 -0000 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix type mismatch caused by COMPOUND_EXPR + x folding (PR c++/33709) Message-ID: <20071030183004.GQ5451@devserv.devel.redhat.com> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2007-10/txt/msg01827.txt.bz2 Hi! This testcase breaks with --enable-checking=yes,types because fold changed struct S[1] *D.1111; (struct S *) COMPOUND_EXPR , D.1111> - x; into COMPOUND_EXPR , 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 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