public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Gengtype : strange code in output_type_enum
@ 2010-08-27 12:49 jeremie.salvucci
  2010-08-27 13:40 ` Laurynas Biveinis
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: jeremie.salvucci @ 2010-08-27 12:49 UTC (permalink / raw)
  To: gcc; +Cc: laurynas, basile

Hello all,

While hacking on gengtype with Basile, we noticed a strange piece of code at line 2539 in gcc/gengtype.c r162692

static void
output_type_enum (outf_p of, type_p s)
{
  if (s->kind == TYPE_PARAM_STRUCT && s->u.s.line.file != NULL) /* Strange code @@*/
    {
      oprintf (of, ", gt_e_");
      output_mangled_typename (of, s);
    }
  else if (UNION_OR_STRUCT_P (s) && s->u.s.line.file != NULL)
    {
      oprintf (of, ", gt_ggc_e_");
      output_mangled_typename (of, s);
    }
  else
    oprintf (of, ", gt_types_enum_last");
}

We think that the enum type_kind discriminates fields union in struct type. So for TYPE_PARAM_STRUCT we believe that 
the param_struct field of union u inside struct type is used. If this is true, the test s->u.s.line.file != NULL is meaningless when s->kind == TYPE_PARAM_STRUCT, it should be s->u.param_struct.line.file != NULL instead in our opinion.

However, the existing code appears to work but we don't understand why.

Or can a type have a kind TYPE_PARAM_STRUCT and only have s->u.s valid? It might be related to the code in new_structure near line  638 of gengtype.c which sets ls->kind = TYPE_LANG_STRUCT.

Perhaps TYPE_PARAM_STRUCT has two different roles. If that is indeed the case, we have to distinguish them when serializing gengtype's state.

Cheers.

-- 

Jeremie Salvucci & Basile Starynkevitch

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-08-27 18:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-27 12:49 Gengtype : strange code in output_type_enum jeremie.salvucci
2010-08-27 13:40 ` Laurynas Biveinis
2010-08-27 13:44 ` jeremie.salvucci
2010-08-27 14:25   ` jeremie.salvucci
2010-08-27 14:43     ` Arnaud Charlet
2010-08-27 14:47     ` Laurynas Biveinis
2010-08-27 18:25       ` Basile Starynkevitch
2010-08-27 18:29         ` Ian Lance Taylor
2010-08-27 15:02 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).