This is the mail archive of the gcc-bugs@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]

Tail recursion optimization bug


Hello ,


      In last binutils, file debug.c has following function (I cut
body to directly show problematic part):

  static struct debug_type *
debug_get_real_type (handle, type, list)
     PTR handle;
     debug_type type;
     struct debug_type_real_list *list;
{
  struct debug_type_real_list *l;
  struct debug_type_real_list rl;

  for (l = list; l != NULL; l = l->next)
[]
  
  rl.next = list;
  rl.t = type;

  switch (type->kind)
    {
      /* The default case is just here to avoid warnings.  */
    default:
    case DEBUG_KIND_INDIRECT:
      if (*type->u.kindirect->slot != NULL)
      return debug_get_real_type (handle, *type->u.kindirect->slot, &rl);
      return type;
    case DEBUG_KIND_NAMED:
    case DEBUG_KIND_TAGGED:
      return debug_get_real_type (handle, type->u.knamed->type, &rl);
    }
  /*NOTREACHED*/
}


  I was brave enough to compile it with -O (egcs 1.1). Baby turned
that tail recursion into loop, which results in rl.next pointing to rl
itself and hanging of code. It shouldn't do that when there automatic
variables and pointers to them, isn't it? By the way, I haven't found
how to turn tail-recursion optimization off, so gave up optimizing at
all ;-(

Best regards,
 Paul                          mailto:paul-ml@is.lg.ua



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