From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31273 invoked by alias); 16 Jun 2011 15:33:34 -0000 Received: (qmail 31254 invoked by uid 22791); 16 Jun 2011 15:33:31 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST X-Spam-Check-By: sourceware.org Received: from mail-ww0-f51.google.com (HELO mail-ww0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Jun 2011 15:33:17 +0000 Received: by wwf26 with SMTP id 26so1504839wwf.8 for ; Thu, 16 Jun 2011 08:33:15 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.205.202 with SMTP id fr10mr1044083wbb.60.1308238395569; Thu, 16 Jun 2011 08:33:15 -0700 (PDT) Received: by 10.227.28.69 with HTTP; Thu, 16 Jun 2011 08:33:15 -0700 (PDT) In-Reply-To: <20110616152451.GA12880@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> Date: Thu, 16 Jun 2011 15:42:00 -0000 Message-ID: Subject: Re: [PATCH PR45098] Disallow NULL pointer in pointer arithmetic From: Richard Guenther To: Zdenek Dvorak Cc: Tom de Vries , gcc-patches@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 2011-06/txt/msg01264.txt.bz2 On Thu, Jun 16, 2011 at 5:24 PM, Zdenek Dvorak wr= ote: > Hi, > >> 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 @@ >> =A0 =A0low =3D lower_bound_in_type (type, type); >> =A0 =A0high =3D upper_bound_in_type (type, type); >> >> + =A0/* In C, pointer arithmetic p + 1 cannot use a NULL pointer, and p = - 1 cannot >> + =A0 =A0 produce a NULL pointer. =A0The contrary would mean NULL points= to an object, >> + =A0 =A0 while NULL is supposed to compare unequal with the address of = all objects. >> + =A0 =A0 Furthermore, p + 1 cannot produce a NULL pointer and p - 1 can= not use a >> + =A0 =A0 NULL pointer since that would mean wrapping, which we assume h= ere not to >> + =A0 =A0 happen. =A0So, we can exclude NULL from the valid range of poi= nter >> + =A0 =A0 arithmetic. =A0*/ >> + =A0if (int_cst_value (low) =3D=3D 0) >> + =A0 =A0low =3D build_int_cstu (TREE_TYPE (low), TYPE_ALIGN_UNIT (TREE_= TYPE (type))); >> + >> =A0 =A0record_nonwrapping_iv (loop, base, step, stmt, low, high, false, = true); >> =A0} > > 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. Richard. > Zdenek >