On Thu, Dec 17, 2009 at 06:17:11PM +0100, Richard Guenther wrote: > On Thu, Dec 17, 2009 at 6:09 PM, David Daney <dda...@caviumnetworks.com> > wrote: > > Jamie Lokier wrote: > >> > >> Uwe Kleine-König wrote: > >>> > >>> Use the new unreachable() macro instead of for(;;); > >>> *(int *)0 = 0; > >>> /* Avoid "noreturn function does return" */ > >>> - for (;;); > >>> + unreachable(); > >> > >> Will GCC-4.5 remove ("optimise away") the *(int *)0 = 0 because it > >> knows the branch of the code leading to unreachable can never be reached? > >> > > > > I don't know the definitive answer, so I am sending to g...@... > > > > FYI: #define unreachable() __builtin_unreachable() > > It shouldn't as *(int *)0 = 0; might trap. But if you want to be sure > use > __builtin_trap (); > instead for the whole sequence (the unreachable is implied then). > GCC choses a size-optimal trap representation for your target then.
How is "size-optimal trap" defined? The point of "*(int *)0 = 0;" is to cause a NULL pointer dereference which is trapped by the kernel to produce a full post mortem and backtrace which is easily recognised as a result of this code. Having gcc decide on, maybe, an undefined instruction instead would be confusing. Let me put it another way: I want this function to terminate with an explicit NULL pointer dereference in every case.