public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Guenther <richard.guenther@gmail.com>
To: Zdenek Dvorak <rakdver@kam.mff.cuni.cz>
Cc: Jeff Law <law@redhat.com>, Tom de Vries <vries@codesourcery.com>,
	gcc-patches@gcc.gnu.org
Subject: Re: [PATCH PR45098] Disallow NULL pointer in pointer arithmetic
Date: Mon, 20 Jun 2011 13:29:00 -0000	[thread overview]
Message-ID: <BANLkTinNuy6jFDh6x8eq9sLO5WN7=f-ZOA@mail.gmail.com> (raw)
In-Reply-To: <20110620122519.GA16457@kam.mff.cuni.cz>

On Mon, Jun 20, 2011 at 2:25 PM, Zdenek Dvorak <rakdver@kam.mff.cuni.cz> wrote:
>> > I don't think we should move this kind of undefinedness from C to
>> > the GIMPLE semantics.  What 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 (somewhat
>> informal) book.  On topic of pointer arithmetics, the case of addition
>> is not completely clear.  It does say that you can only subtract pointers
>> to members of the same array, though.
>>
>> On topic of addition of integer to a pointer, it says that "The construction
>> p + n means the address of the n-th object beyond the one p currently points to. This is true
>> regardless of the kind of object p points to; n is scaled according to the 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 could reasonably expect
> NULL + 0 to be valid.  In the example by Richard,
>
> int __attribute__((noinline)) foo (void *p, int i)
> {
>  return p + i != 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
>

  reply	other threads:[~2011-06-20 12:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-16  6:42 Tom de Vries
2011-06-16  6:51 ` Tom de Vries
2011-06-16  7:34 ` Zdenek Dvorak
2011-06-16 12:22   ` Tom de Vries
2011-06-16 15:33     ` Zdenek Dvorak
2011-06-16 15:42       ` Richard Guenther
2011-06-16 15:54         ` Zdenek Dvorak
2011-06-16 18:10           ` Tom de Vries
2011-06-16 22:03 ` Jeff Law
2011-06-17 10:44   ` Tom de Vries
2011-06-17 10:56     ` Richard Guenther
2011-06-17 10:57       ` Zdenek Dvorak
2011-06-17 11:13         ` Richard Guenther
2011-06-17 11:22           ` Zdenek Dvorak
2011-06-17 13:01             ` Richard Guenther
2011-06-17 14:57               ` Zdenek Dvorak
2011-06-17 18:24                 ` Jeff Law
2011-06-20 11:06                   ` Richard Guenther
2011-06-20 12:26                     ` Zdenek Dvorak
2011-06-20 12:41                       ` Zdenek Dvorak
2011-06-20 13:29                         ` Richard Guenther [this message]
2011-06-20 13:35                           ` Michael Matz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTinNuy6jFDh6x8eq9sLO5WN7=f-ZOA@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=rakdver@kam.mff.cuni.cz \
    --cc=vries@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).