Ignore artificial fields in Ada

A user found an unusual Ada situation that DWARF does not readily
support.  Consider this type:

   type Discrete_Typ is tagged null record;
   type Int_Typ (Is_Static : Boolean) is new Discrete_Typ with null record;

   type Signed_Int_Typ (Is_Static : Boolean) is
      new Int_Typ (Is_Static => Is_Static)
                    with record
      case Is_Static is
         when True =>
            Field : Integer;
         when others =>
            null;
      end case;
   end record;

Here, Signed_Int_Typ has a variant part where the discriminant is
stored in a superclass.

Anyway, this code caused gnat-llvm to crash.  While fixing the crash,
I decided to fix this by emitting an anonymous field in Signed_Int_Typ
that represents the discriminant.  This would allow member DIEs to
refer to it -- which I suppose is possibly why DWARF specified that
the discriminant should be a member of the variant (though I don't
really know; this decision always seemed very strange to me).

Making the field anonymous lead to the strange error:

    Type ... is not a structure or union type.

... which comes from lookup_struct_elt, which fails when an anonymous
member of a structure has a non-composite type.  This patch includes a
fix for this issue.

After fixing that, though I decided it would be better if the
artificial discriminant were still given a name.  So, this patch
includes a change to ada_is_ignored_field to ignore artificial fields.

Approved-By: Andrew Burgess <aburgess@redhat.com>
This commit is contained in:
Tom Tromey
2025-10-03 10:59:29 -06:00
parent 6d3af8c9f6
commit 48b5669c2e
4 changed files with 134 additions and 9 deletions

View File

@@ -1821,12 +1821,18 @@ lookup_struct_elt (struct type *type, const char *name, int noerr)
}
else if (!t_field_name || *t_field_name == '\0')
{
struct_elt elt
= lookup_struct_elt (type->field (i).type (), name, 1);
if (elt.field != NULL)
struct type *field_type = type->field (i).type ();
enum type_code field_code = check_typedef (field_type)->code ();
if (field_code == TYPE_CODE_STRUCT || field_code == TYPE_CODE_UNION)
{
elt.offset += type->field (i).loc_bitpos ();
return elt;
struct_elt elt
= lookup_struct_elt (type->field (i).type (), name, 1);
if (elt.field != NULL)
{
elt.offset += type->field (i).loc_bitpos ();
return elt;
}
}
}
}