From patchwork Thu Mar 1 20:23:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 144109 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 C40031007F2 for ; Fri, 2 Mar 2012 07:24:35 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1331238382; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=p2O3gER kbs1UUJtcHCN7gsKQx0w=; b=YLGeI4ZBeUqA/IjWcHN1XftqCvQYvsukFEExXnH OEtWxU6fNq+SEuAhbJdRYMd5MNqKMzMNU/KEW2OdA/pD+8utja1E18tdzOWMdjMw O6VZ42tYbvn3WfrCWTlWCrQ4jNvl0/uH0u3QNXu/oNsWcGTv7fuKON+Mfi4uadQS ik7Y= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=p7iqkIGbh1sSvdnsBHWTpV6enRPof7nUMENyscbTEIHcs50f70brSnpVKZ0lCX nuHPArQoBmmgtd10imi4Eq7iQoQfW1B9Lf+QuQgregQQNssN8QTVgn9h5Pk3JVCX 5H0G8rNdVD4P/WOnEMrIHDBujYeOAoZHa7a6uMidJU8uc=; Received: (qmail 13763 invoked by alias); 1 Mar 2012 20:24:02 -0000 Received: (qmail 13730 invoked by uid 22791); 1 Mar 2012 20:23:59 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY X-Spam-Check-By: sourceware.org Received: from mailout01.t-online.de (HELO mailout01.t-online.de) (194.25.134.80) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Mar 2012 20:23:46 +0000 Received: from fwd24.aul.t-online.de (fwd24.aul.t-online.de ) by mailout01.t-online.de with smtp id 1S3CXR-000800-DO; Thu, 01 Mar 2012 21:23:45 +0100 Received: from [84.152.168.118] (GQrdLoZlrhjVrLPBDgwoZ5MthgSlrfrBf2PeSqOJu3r5lMRrl-IuTFSjpSjOqT7Z0d@[84.152.168.118]) by fwd24.aul.t-online.de with esmtp id 1S3CXQ-1XMOYa0; Thu, 1 Mar 2012 21:23:44 +0100 Message-ID: <4F4FDABB.5060308@t-online.de> Date: Thu, 01 Mar 2012 21:23:23 +0100 From: Bernd Schmidt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.20) Gecko/20110920 Lightning/1.0b3pre Thunderbird/3.1.12 MIME-Version: 1.0 To: GCC Patches Subject: Fix POINTER_PLUS_EXPR oversight 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 In pointer_diff we still expect pointer addition to use PLUS_EXPR. I discovered this while working on a new port with somewhat unusual pointer types. Interestingly, the C++ frontend also has a pointer_diff function, but doesn't seem to attempt to optimize. Is there a reason for this? Bootstrapped and tested on i686-linux. Ok for now or stage1? Bernd * c-typeck.c (pointer_diff): Check for POINTER_PLUS_EXPR, not PLUS_EXPR. Index: gcc/c-typeck.c =================================================================== --- gcc/c-typeck.c (revision 183969) +++ gcc/c-typeck.c (working copy) @@ -3447,7 +3447,9 @@ pointer_diff (location_t loc, tree op0, else con1 = op1; - if (TREE_CODE (con0) == PLUS_EXPR) + gcc_assert (TREE_CODE (con0) != PLUS_EXPR + && TREE_CODE (con1) != PLUS_EXPR); + if (TREE_CODE (con0) == POINTER_PLUS_EXPR) { lit0 = TREE_OPERAND (con0, 1); con0 = TREE_OPERAND (con0, 0); @@ -3455,7 +3457,7 @@ pointer_diff (location_t loc, tree op0, else lit0 = integer_zero_node; - if (TREE_CODE (con1) == PLUS_EXPR) + if (TREE_CODE (con1) == POINTER_PLUS_EXPR) { lit1 = TREE_OPERAND (con1, 1); con1 = TREE_OPERAND (con1, 0);