On Mon, Jan 26, 2009 at 11:52 PM,  <zol...@bendor.com.au> wrote:
> I was debugging a function and by inserting the debug statement crashed
> the system. Some investigation revealed that gcc 4.3.2 arm-eabi (compiled
> from sources) with -O2 under some circumstances assumes that if a pointer
> is dereferenced, it can not be NULL therefore explicite tests against
> NULL can be later eliminated.

That's an optimization permitted by the language standard, but
possibly unhelpful on your particular target.  It is a case of a more
general situation: the compiler can assume that code containing
"undefined behavior" (such as a null-pointer dereference) is not
executed, or equivalently that a condition that would lead to the
execution of UB is always false.

I don't know how much work it would be to disable this optimization in gcc.

-- James

Reply via email to