From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24562 invoked by alias); 17 Jun 2011 11:22:49 -0000 Received: (qmail 24551 invoked by uid 22791); 17 Jun 2011 11:22:48 -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-wy0-f175.google.com (HELO mail-wy0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 17 Jun 2011 11:22:35 +0000 Received: by wye20 with SMTP id 20so1991568wye.20 for ; Fri, 17 Jun 2011 04:22:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.197.83 with SMTP id ej19mr1953511wbb.105.1308309753672; Fri, 17 Jun 2011 04:22:33 -0700 (PDT) Received: by 10.227.28.69 with HTTP; Fri, 17 Jun 2011 04:22:33 -0700 (PDT) In-Reply-To: <20110617111306.GA26510@kam.mff.cuni.cz> References: <4DF9A526.9060906@codesourcery.com> <4DFA7D1C.9040105@redhat.com> <4DFB2F3A.3040706@codesourcery.com> <20110617105527.GA23535@kam.mff.cuni.cz> <20110617111306.GA26510@kam.mff.cuni.cz> Date: Fri, 17 Jun 2011 13:01:00 -0000 Message-ID: Subject: Re: [PATCH PR45098] Disallow NULL pointer in pointer arithmetic From: Richard Guenther To: Zdenek Dvorak Cc: Tom de Vries , Jeff Law , 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/msg01335.txt.bz2 2011/6/17 Zdenek Dvorak : > Hi, > >> >> > Index: tree-vrp.c >> >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> >> > --- tree-vrp.c =A0(revision 173703) >> >> > +++ tree-vrp.c =A0(working copy) >> >> > @@ -2273,7 +2273,12 @@ extract_range_from_binary_expr (value_ra >> >> > =A0 =A0 =A0 =A0{ >> >> > =A0 =A0 =A0 =A0 =A0/* For pointer types, we are really only interes= ted in asserting >> >> > =A0 =A0 =A0 =A0 =A0 =A0 whether the expression evaluates to non-NUL= L. =A0*/ >> >> > - =A0 =A0 =A0 =A0 if (range_is_nonnull (&vr0) || range_is_nonnull (= &vr1)) >> >> > + =A0 =A0 =A0 =A0 if (flag_delete_null_pointer_checks && nowrap_typ= e_p (expr_type)) >> >> >> >> the latter would always return true >> >> >> >> Btw, I guess you'll "miscompile" a load of code that is strictly >> >> undefined. =A0So I'm not sure we want to do this against our users ... >> > >> > Probably not, at least unless the user explicitly asks for it -- for e= xample, >> > we could have -fdelete-null-pointer-checks=3D2. =A0In fact, it might b= e a good idea >> > to implement this flag anyway, since some current uses of flag_delete_= null_pointer_checks >> > can lead to "miscompilations" when user makes an error in their code a= nd would >> > probably appreciate more having their program crash. >> > >> >> Oh, and of course it's even wrong. =A0I thing it needs && >> >> !range_includes_zero (&vr1) (which we probably don't have). =A0The >> >> offset may be 0 and NULL + 0 >> >> is still NULL. >> > >> > actually, the result of NULL + 0 is undefined (pointer arithmetics is = only defined >> > for pointers to actual objects, and NULL cannot point to one). >> >> It's maybe undefined in C, but is it undefined in the middle-end? =A0Thu= s, >> are you sure we never generate it from (void *)((uintptr_t)p + obfuscate= d_0)? >> I'm sure we simply fold that to p + obfuscated_0. > > if we do, we definitely should not -- the only point of such a constructi= on is > to bypass the pointer arithmetics restrictions, Ok, we don't. Where does the C standard say that NULL + 0 is undefined? Richard. > Zdenek >