From patchwork Thu Jul 7 11:07:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 103638 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 13050B6F7A for ; Thu, 7 Jul 2011 21:08:06 +1000 (EST) Received: (qmail 5865 invoked by alias); 7 Jul 2011 11:08:03 -0000 Received: (qmail 5855 invoked by uid 22791); 7 Jul 2011 11:08:02 -0000 X-SWARE-Spam-Status: No, hits=-3.3 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 07 Jul 2011 11:07:48 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id A2E448765C for ; Thu, 7 Jul 2011 13:07:47 +0200 (CEST) Date: Thu, 7 Jul 2011 13:07:47 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH][1/n] Do not force sizetype for POINTER_PLUS_EXPR Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 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 This is the first of a series of enabling patches to make POINTER_PLUS_EXPR not forcefully take a sizetype offset (I'm still no 100% what requirements I will end up implementing, but the first goal is to have less TYPE_IS_SIZETYPE types). This patch removes the (T *)index +p (int)PTR -> PTR +p index folding. We shouldn't change what the user specified as the pointer base as we can't be sure we don't mess up here, considering int foo(int *p, uintptr_t o) { return *((uintptr_t)p + (int *)o); } int main () { int res = 0; return foo((int *)0, (uintptr_t)&res); } if the o argument in foo is really the offset then the C code is invoking undefined behavior as you may not do anything with an integer which you converted to a pointer other than converting it back. Bootstrapped and tested on x86_64-unknown-linux-gnu. Richard. 2011-07-07 Richard Guenther * fold-const.c (fold_binary_loc): Remove index +p PTR -> PTR +p index folding. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 175920) +++ gcc/fold-const.c (working copy) @@ -9484,13 +9484,6 @@ fold_binary_loc (location_t loc, fold_convert_loc (loc, sizetype, arg0))); - /* index +p PTR -> PTR +p index */ - if (POINTER_TYPE_P (TREE_TYPE (arg1)) - && INTEGRAL_TYPE_P (TREE_TYPE (arg0))) - return fold_build2_loc (loc, POINTER_PLUS_EXPR, type, - fold_convert_loc (loc, type, arg1), - fold_convert_loc (loc, sizetype, arg0)); - /* (PTR +p B) +p A -> PTR +p (B + A) */ if (TREE_CODE (arg0) == POINTER_PLUS_EXPR) {