This is the mail archive of the 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]
Other format: [Raw text]

Re: Keeping unreachable code

On Feb  3, 2002, Casper Hornstrup <> wrote:

> On Sunday 03 February 2002 23:37, you wrote:

>> The compiler cannot throw away a function that could potentially be
>> called from some other file.

> It can if it thinks it is 'dead' code and it does since no jumps targets the 
> code. The address of the exception handler is kept in a table so the runtime 
> library can find it.

The difference is that a non-static function can be called from other
translation units, so GCC has to keep in it, whereas a label is not be
accessible from other translation units.  GCC assumes labels are only
reachable within the same function.  The only exception is for
non-local gotos from nested functions to labels in enclosing functions
(a GCC extension), and exception handling.  In the case of exception
handling, the compiler creates edges from call insns to the
corresponding handlers, such that they are not marked as dead.  Just
taking their addresses is not enough: there must be some live computed
goto within the same function to mark labels whose addresses are taken
as not dead.  Consider doing something like:

void *make_labels_live = 0;

#define register_EH_label(label, where) do { \
  if (__builtin_expect(make_labels_live, 0)) goto *make_labels_live; \
  really_register_EH_label(&&label, where);
} while (0)

foo() {
  register_EH_label(my_eh_label, ???);



Alexandre Oliva   Enjoy Guarana', see
Red Hat GCC Developer                  aoliva@{,}
CS PhD student at IC-Unicamp        oliva@{,}
Free Software Evangelist                Professional serial bug killer

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