From patchwork Thu Jul 7 12:57:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 103656 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E0977B6F18 for ; Thu, 7 Jul 2011 22:57:52 +1000 (EST) Received: (qmail 29918 invoked by alias); 7 Jul 2011 12:57:50 -0000 Received: (qmail 29910 invoked by uid 22791); 7 Jul 2011 12:57:50 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 07 Jul 2011 12:57:33 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p67CvPjj022274 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 7 Jul 2011 08:57:25 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p67CvO6k015927 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 7 Jul 2011 08:57:24 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p67CvNU5015663; Thu, 7 Jul 2011 14:57:23 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p67CvNQt015661; Thu, 7 Jul 2011 14:57:23 +0200 Date: Thu, 7 Jul 2011 14:57:23 +0200 From: Jakub Jelinek To: "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix complex {*, /} real or real * complex handling in C FE (PR c/49644) Message-ID: <20110707125723.GO2687@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi! For MULT_EXPR and TRUNC_DIV_EXPR, both sides of COMPLEX_EXPR contain a copy of the non-complex operand, which means its side-effects can be evaluated twice. For PLUS_EXPR/MINUS_EXPR they appear just in one of the operands and thus it works fine as is. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.6? 2011-07-07 Jakub Jelinek PR c/49644 * c-typeck.c (build_binary_op): For MULT_EXPR and TRUNC_DIV_EXPR with one non-complex and one complex argument, call c_save_expr on both operands. * gcc.c-torture/execute/pr49644.c: New test. Jakub --- gcc/c-typeck.c.jj 2011-05-31 08:03:10.000000000 +0200 +++ gcc/c-typeck.c 2011-07-07 11:47:31.000000000 +0200 @@ -10032,6 +10032,8 @@ build_binary_op (location_t location, en if (first_complex) { op0 = c_save_expr (op0); + if (code == MULT_EXPR || code == TRUNC_DIV_EXPR) + op1 = c_save_expr (op1); real = build_unary_op (EXPR_LOCATION (orig_op0), REALPART_EXPR, op0, 1); imag = build_unary_op (EXPR_LOCATION (orig_op0), IMAGPART_EXPR, @@ -10052,6 +10054,8 @@ build_binary_op (location_t location, en } else { + if (code == MULT_EXPR) + op0 = c_save_expr (op0); op1 = c_save_expr (op1); real = build_unary_op (EXPR_LOCATION (orig_op1), REALPART_EXPR, op1, 1); --- gcc/testsuite/gcc.c-torture/execute/pr49644.c.jj 2011-07-07 11:48:34.000000000 +0200 +++ gcc/testsuite/gcc.c-torture/execute/pr49644.c 2011-07-07 11:35:52.000000000 +0200 @@ -0,0 +1,16 @@ +/* PR c/49644 */ + +extern void abort (void); + +int +main (void) +{ + _Complex double a[12], *c = a, s = 3.0 + 1.0i; + double b[12] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, *d = b; + int i; + for (i = 0; i < 6; i++) + *c++ = *d++ * s; + if (c != a + 6 || d != b + 6) + abort (); + return 0; +}