This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Q: Dead code elimination in the precense of addresses taken of local labels.



It appears gcc-2.95.2 will eliminate a section of code
even if it's address is passed to another function.
The question is what is correct/defined behavior
for this gcc in this case.  

My interpretation is that since the only valid use of
computed labels is for local gotos.  The value should
not be allowed to be passed out of a function and
somehow a diagnostic should be raised.  (A type 
other tha (void  *) would make this simple.

On the other hand if it is legal to pass an address of a code segment
to a another function (perhaps for a complicated variant of a switch
statement) then optimising out the jump target is very bad.

Since my bad example code fragment has no goto's yet it does
have a computed goto that is probably also a reasonable
excuse to generate a warning.

In particular dosemu had code segments that go like this:
(As part of a dynamic code generator).

void _a_ret(CodeObj *co)
{
  __label__ _cf_001;
  code_append_ins(co, 1, &&_cf_001);
  return;
/* everything after this point is optimized away */
  _cf_001: asm("ret\n");
}

Eric

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