From: Zdenek Dvorak <rakdver@kam.mff.cuni.cz>
To: Richard Guenther <richard.guenther@gmail.com>
Cc: Tom de Vries <vries@codesourcery.com>, Jeff Law <law@redhat.com>,
gcc-patches@gcc.gnu.org
Subject: Re: [PATCH PR45098] Disallow NULL pointer in pointer arithmetic
Date: Fri, 17 Jun 2011 10:57:00 -0000 [thread overview]
Message-ID: <20110617105527.GA23535@kam.mff.cuni.cz> (raw)
In-Reply-To: <BANLkTikvh1rrjrEfDovAjXVAuh+K2s3XJg@mail.gmail.com>
> >> Interesting. Â I'd never thought about the generation/use angle to prove
> >> a pointer was non-null. Â ISTM 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
> > ===================================================================
> > --- tree-vrp.c  (revision 173703)
> > +++ tree-vrp.c  (working copy)
> > @@ -2273,7 +2273,12 @@ extract_range_from_binary_expr (value_ra
> > Â Â Â Â {
> > Â Â Â Â Â /* For pointer types, we are really only interested in asserting
> > Â Â Â Â Â Â whether the expression evaluates to non-NULL. Â */
> > - Â Â Â Â if (range_is_nonnull (&vr0) || range_is_nonnull (&vr1))
> > + Â Â Â Â 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. So I'm not sure we want to do this against our users ...
Probably not, at least unless the user explicitly asks for it -- for example,
we could have -fdelete-null-pointer-checks=2. In fact, it might be 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 and would
probably appreciate more having their program crash.
> Oh, and of course it's even wrong. I thing it needs &&
> !range_includes_zero (&vr1) (which we probably don't have). The
> 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).
Zdenek
next prev parent reply other threads:[~2011-06-17 10:55 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 [this message]
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
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=20110617105527.GA23535@kam.mff.cuni.cz \
--to=rakdver@kam.mff.cuni.cz \
--cc=gcc-patches@gcc.gnu.org \
--cc=law@redhat.com \
--cc=richard.guenther@gmail.com \
--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).