From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9060 invoked by alias); 17 Jun 2011 10:57:52 -0000 Received: (qmail 9052 invoked by uid 22791); 17 Jun 2011 10:57:51 -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 10:57:25 +0000 Received: by wye20 with SMTP id 20so1975869wye.20 for ; Fri, 17 Jun 2011 03:57:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.199.19 with SMTP id eq19mr2001849wbb.75.1308308244073; Fri, 17 Jun 2011 03:57:24 -0700 (PDT) Received: by 10.227.28.69 with HTTP; Fri, 17 Jun 2011 03:57:24 -0700 (PDT) In-Reply-To: <20110617105527.GA23535@kam.mff.cuni.cz> References: <4DF9A526.9060906@codesourcery.com> <4DFA7D1C.9040105@redhat.com> <4DFB2F3A.3040706@codesourcery.com> <20110617105527.GA23535@kam.mff.cuni.cz> Date: Fri, 17 Jun 2011 11:13: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/msg01331.txt.bz2 2011/6/17 Zdenek Dvorak : >> >> Interesting. =A0I'd never thought about the generation/use angle to p= rove >> >> a pointer was non-null. =A0ISTM we could use that same logic to infer= that >> >> more pointers are non-null in extract_range_from_binary_expr. >> >> >> >> Interested in tackling that improvement, obviously as an independent = patch? >> >> >> > >> > I'm not familiar with vrp code, but.. something like this? >> > >> > 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 interested= in asserting >> > =A0 =A0 =A0 =A0 =A0 =A0 whether the expression evaluates to non-NULL. = =A0*/ >> > - =A0 =A0 =A0 =A0 if (range_is_nonnull (&vr0) || range_is_nonnull (&vr= 1)) >> > + =A0 =A0 =A0 =A0 if (flag_delete_null_pointer_checks && nowrap_type_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 exam= ple, > we could have -fdelete-null-pointer-checks=3D2. =A0In fact, it might be a= good idea > to implement this flag anyway, since some current uses of flag_delete_nul= l_pointer_checks > can lead to "miscompilations" when user makes an error in their code and = 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 onl= y 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? Thus, are you sure we never generate it from (void *)((uintptr_t)p + obfuscated_0= )? I'm sure we simply fold that to p + obfuscated_0. Richard. > Zdenek >