Re: Null pointer dereference and side effects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Jul 20, 2004, Archie Cobbs <archie@xxxxxxxxxxxx> wrote:

> It appears gcc is completely ignoring the possibility of
> "side effects" when it optimizes away the comparison.

Oh, rats.  That's because the reasoning about dereferencing NULL
invoking undefined behavior still applies.  Since both arms of the if
return the same value, the compare is optimized away, and the
dereference of the pointer can be removed because, if it was NULL or
any other bad pointer, it would invoke undefined behavior, and
otherwise, the dereference would be safe and unused.

I think you really need to make the pointer volatile to prevent the
dereference from being optimized out.

-- 
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}

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux