From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21738 invoked by alias); 16 Jun 2011 15:42:58 -0000 Received: (qmail 21511 invoked by uid 22791); 16 Jun 2011 15:42:58 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Jun 2011 15:42:41 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 29025) id C62579AC7E3; Thu, 16 Jun 2011 17:42:40 +0200 (CEST) Date: Thu, 16 Jun 2011 15:54:00 -0000 From: Zdenek Dvorak To: Richard Guenther Cc: Tom de Vries , gcc-patches@gcc.gnu.org Subject: Re: [PATCH PR45098] Disallow NULL pointer in pointer arithmetic Message-ID: <20110616154240.GA15905@kam.mff.cuni.cz> References: <4DF9A526.9060906@codesourcery.com> <20110616072405.GA6045@kam.mff.cuni.cz> <4DF9F1DC.8080306@codesourcery.com> <20110616152451.GA12880@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) 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: 2011-06/txt/msg01266.txt.bz2 > >> diff -u gcc/tree-ssa-loop-niter.c (working copy) gcc/tree-ssa-loop-niter.c (working copy) > >> --- gcc/tree-ssa-loop-niter.c (working copy) > >> +++ gcc/tree-ssa-loop-niter.c (working copy) > >> @@ -2875,6 +2875,16 @@ > >>    low = lower_bound_in_type (type, type); > >>    high = upper_bound_in_type (type, type); > >> > >> +  /* In C, pointer arithmetic p + 1 cannot use a NULL pointer, and p - 1 cannot > >> +     produce a NULL pointer.  The contrary would mean NULL points to an object, > >> +     while NULL is supposed to compare unequal with the address of all objects. > >> +     Furthermore, p + 1 cannot produce a NULL pointer and p - 1 cannot use a > >> +     NULL pointer since that would mean wrapping, which we assume here not to > >> +     happen.  So, we can exclude NULL from the valid range of pointer > >> +     arithmetic.  */ > >> +  if (int_cst_value (low) == 0) > >> +    low = build_int_cstu (TREE_TYPE (low), TYPE_ALIGN_UNIT (TREE_TYPE (type))); > >> + > >>    record_nonwrapping_iv (loop, base, step, stmt, low, high, false, true); > >>  } > > > > OK, > > I think this is only valid for !flag_delete_null_pointer_checks, on > architectures where that isn't the default we have to assume that > NULL may point to an object. agreed. Thanks for the correction. Zdenek