This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Null pointer dereference and side effects
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Archie Cobbs <archie at dellroad dot org>
- Cc: gcc-help at gcc dot gnu dot org
- Date: 20 Jul 2004 06:55:06 -0300
- Subject: Re: Null pointer dereference and side effects
- Organization: Red Hat Global Engineering Services Compiler Team
- References: <200407181927.i6IJRV44038684@arch20m.dellroad.org>
Hi, Archie! Long time...
On Jul 18, 2004, Archie Cobbs <archie@dellroad.org> wrote:
> r2 = (void *)0; /* or (void *)1, etc. */
> if (*r1 != *r2)
> return 1;
> return 1;
> However, in my application I'm relying on the side effects of
> dereferencing a null pointer (ie., SEGV signal), so that causes
> bugs for me.
> I understand that according to the C standard dereferencing a null
> pointer results in "undefined" behavior, so gcc is not behaving
> incorrectly.
> However, is there some way to get the desired semantics?
If you insert an `asm ("" : "+X" (r2));' statement after the
assignment to r2, such that the compiler will no longer have any idea
that r2 is NULL, and won't optimize away the dereference.
--
Alexandre Oliva http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}