From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19208 invoked by alias); 20 Jun 2011 12:41:22 -0000 Received: (qmail 19198 invoked by uid 22791); 20 Jun 2011 12:41:21 -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; Mon, 20 Jun 2011 12:41:05 +0000 Received: by wyb34 with SMTP id 34so1456554wyb.20 for ; Mon, 20 Jun 2011 05:41:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.55.67 with SMTP id t3mr4868351wbg.90.1308573664183; Mon, 20 Jun 2011 05:41:04 -0700 (PDT) Received: by 10.227.28.69 with HTTP; Mon, 20 Jun 2011 05:41:04 -0700 (PDT) In-Reply-To: <20110620122519.GA16457@kam.mff.cuni.cz> References: <4DFB2F3A.3040706@codesourcery.com> <20110617105527.GA23535@kam.mff.cuni.cz> <20110617111306.GA26510@kam.mff.cuni.cz> <20110617141246.GA6164@kam.mff.cuni.cz> <4DFB9652.7020107@redhat.com> <20110620122036.GA11662@kam.mff.cuni.cz> <20110620122519.GA16457@kam.mff.cuni.cz> Date: Mon, 20 Jun 2011 13:29:00 -0000 Message-ID: Subject: Re: [PATCH PR45098] Disallow NULL pointer in pointer arithmetic From: Richard Guenther To: Zdenek Dvorak Cc: Jeff Law , 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/msg01455.txt.bz2 On Mon, Jun 20, 2011 at 2:25 PM, Zdenek Dvorak wr= ote: >> > I don't think we should move this kind of undefinedness from C to >> > the GIMPLE semantics. =A0What do other languages allow that >> > we have to support (what did K&R C specify?). >> >> I don't think there is a formal specification of K&R C, just the (somewh= at >> informal) book. =A0On topic of pointer arithmetics, the case of addition >> is not completely clear. =A0It does say that you can only subtract point= ers >> to members of the same array, though. >> >> On topic of addition of integer to a pointer, it says that "The construc= tion >> p + n means the address of the n-th object beyond the one p currently po= ints to. This is true >> regardless of the kind of object p points to; n is scaled according to t= he size of the objects p >> points to, which is determined by the declaration of p." > > Anyway, I don't think that this should be a matter of lawyer scrutiny of = the specifications; > rather, we should consider whether there is a situation where a user coul= d reasonably expect > NULL + 0 to be valid. =A0In the example by Richard, > > int __attribute__((noinline)) foo (void *p, int i) > { > =A0return p + i !=3D NULL; > } > > I think it would be hard to argue that this construction is natural. Nor does it feel natural that 'p' is different from 'p + 0'. Richard. > Zdenek >