On Wed, Nov 09, 2011 at 10:53:34AM -0700, Jeff Law wrote: > > which is only different on undefined paths. But I'm not sure that > > more complicated cases, where there are other instructions between > > the "if" and "*p = 0", would also be allowed by the C standard. > > For example, I think a function call in the "else" branch, or > > between the PHI and the dereference should prevent the > > optimization, because the function call might never return for what > > we know. Probably a volatile asm too. Does your patch do that? > > (Testcases! :)). > My patch totally ignores the other code on the unexecutable path. So > we can miss externally visible side effects, if we were to somehow get > on the unexecutable path. But that's the whole point, in a conforming > program we can't ever get on the unexecutable path.
Well, side-effects that could be validly scheduled after the NULL pointer dereference are just fine to be omitted. But if there is a function call that might call exit (0); in it, or throw an exception and thus never reach the trap point, then omitting those would be an invalid optimization. Jakub