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

Reply via email to