This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Is this expected gcc behaviour?


>I think I'm getting overly agressive optimization.
>
>When I compile this function:
>     extern unsigned long ptr;
>
>     int func(void)
>     {
>         unsigned long val = (unsigned long)&ptr;
>
>	 if (val == 0) {
>	     return 1;
>         } else {
>             return 0;
>         }
>     }
>
>with any optimization level > 0, I get this:
>    func:
>        clr.l %d0
>        rts
>
>It looks like it's assuming a pointer can't be NULL.

I think the compiler is assuming that the *address* of a pointer can't be
NULL, not the value.  If your code was:

>         unsigned long val = (unsigned long)ptr;

then I think the compiler would load the *value* of ptr instead of the
*address* of ptr and then test the *value* for NULL, not test its
*address* for NULL.

I don't think there is any case where an *address* of a pointer(not
its value) can be NULL?

-- 
Peter Barada
peter@the-baradas.com

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]