https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57438

--- Comment #25 from Iain Sandoe <iains at gcc dot gnu.org> ---
Created attachment 37324
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37324&action=edit
Avoid empty function bodies V1


So...
The #if TARGET_MACHO code in ix86_output_function_epilogue () is supposed to
prevent trailing labels on Darwin functions (because that creates another
problem if those are used in relocations).

However, the code doesn't work for multiple reasons - not least of which is
that ix86_output_function_epilogue() is called before the last function lables
are emitted.

Ironically, if it was working - it would have suppressed the current bug since
we typically get:
 …. globl foo
foo:
LFBxxx
 <=== ix86_output_function_epilogue() is called here.
LFExxx

and, in theory, the trailing LFBxxx should have fired the output of a nop. 
However, the presence of the barrier seems to undo this.

----

Given that the ifdef-d code cannot do what it intends (it would need to be
called later), it might as well be removed.

We can, however, detect empty function bodies at this point an emit some
instruction to avoid the circumstance.

At present, there doesn't seem to be any legitimate case where an empty
function body could be validly executed.  Note that the usal reason for
function bodies to be completely empty is when the code in the function is made
unreachable (with __builtin_unreachable()).  The GCC manual says that reaching
such code is UB, so we are free to do whatever seems most useful.  In this case
making the function one insn long and making that insn "hlt" seems useful - so
that if such a function is actually called it does something that will provide
a hint to the user.

Bootstrapped on trunk (and 5.3) testing as and when - folks, please comment/try
out.

Reply via email to