]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Set DECL_NAMELESS in create_type_decl
authorTom Tromey <tromey@adacore.com>
Tue, 9 Jul 2024 15:36:26 +0000 (09:36 -0600)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 25 Oct 2024 09:09:04 +0000 (11:09 +0200)
When using minimal encodings, most artificial types do not need to
have their names emitted in the DWARF.  This patch changes the
compiler to generally omit these names.

However, a subset of names are needed: when the compiler creates an
artificial type for certain kinds of arrays, the name is needed by
gdb.  So, a new parameter is added to create_type_decl to allow this
omission to be disabled.

Note that simply passing 'false' as the artificial_p argument to
create_type_decl doesn't work properly -- other parts of the compiler
seem to rely on this flag being set, and so making this change causes
ICEs.

gcc/ada/ChangeLog:

* gcc-interface/decl.cc (gnat_to_gnu_entity): Update some calls to
create_type_decl.
* gcc-interface/gigi.h (create_type_decl): Add can_be_nameless parameter.
* gcc-interface/utils.cc (create_type_decl): Add can_be_nameless
parameter.  Set DECL_NAMELESS on type decl.

gcc/ada/gcc-interface/decl.cc
gcc/ada/gcc-interface/gigi.h
gcc/ada/gcc-interface/utils.cc

index ba75fa33093493d766cf454ad2d15a6850b466e4..372d72a18b60ab305b9c16aff37fdb716deacdd8 100644 (file)
@@ -2003,7 +2003,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
 
          /* Create a stripped-down declaration, mainly for debugging.  */
          t = create_type_decl (gnu_entity_name, gnu_type, true, debug_info_p,
-                               gnat_entity);
+                               gnat_entity, false);
 
          /* Now save it and build the enclosing record type.  */
          gnu_field_type = gnu_type;
@@ -2276,7 +2276,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
            ? create_concat_name (gnat_name, "XUP")
            : gnu_entity_name;
        create_type_decl (xup_name, gnu_fat_type, true, debug_info_p,
-                         gnat_entity);
+                         gnat_entity, false);
 
        /* Build a reference to the template from a PLACEHOLDER_EXPR that
           is the fat pointer.  This will be used to access the individual
@@ -3022,7 +3022,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
                = create_type_decl (gnu_entity_name, gnu_type,
                                    is_artificial (Etype (gnat_entity))
                                    && artificial_p, debug_info_p,
-                                   gnat_entity);
+                                   gnat_entity, false);
              /* Save it as our equivalent in case the call below elaborates
                 this type again.  */
              save_gnu_tree (gnat_entity, gnu_tmp_decl, false);
index 00f00d967c7370bb56a7a31994f7ec3711c8b7b5..875a3d6b87f02a9ff2051b1d5833f2af22d67acc 100644 (file)
@@ -625,9 +625,12 @@ extern tree create_type_stub_decl (tree name, tree type);
    used in the declaration.  ARTIFICIAL_P is true if the declaration was
    generated by the compiler.  DEBUG_INFO_P is true if we need to write
    debug information about this type.  GNAT_NODE is used for the position
-   of the decl.  */
+   of the decl.  Normally, an artificial type might be marked as
+   nameless.  However, if CAN_BE_NAMELESS is false, this marking is
+   disabled and the name will always be attached for the type.  */
 extern tree create_type_decl (tree name, tree type, bool artificial_p,
-                             bool debug_info_p, Node_Id gnat_node);
+                             bool debug_info_p, Node_Id gnat_node,
+                             bool can_be_nameless = true);
 
 /* Return a VAR_DECL or CONST_DECL node.
 
index a06366bf40e4a166e68d46272736b079a2c11377..3a571e0077bd37ee8e0209bfeb2794023ccb52aa 100644 (file)
@@ -2846,11 +2846,13 @@ create_type_stub_decl (tree name, tree type)
    used in the declaration.  ARTIFICIAL_P is true if the declaration was
    generated by the compiler.  DEBUG_INFO_P is true if we need to write
    debug information about this type.  GNAT_NODE is used for the position
-   of the decl.  */
+   of the decl.  Normally, an artificial type might be marked as
+   nameless.  However, if CAN_BE_NAMELESS is false, this marking is
+   disabled and the name will always be attached for the type.  */
 
 tree
 create_type_decl (tree name, tree type, bool artificial_p, bool debug_info_p,
-                 Node_Id gnat_node)
+                 Node_Id gnat_node, bool can_be_nameless)
 {
   enum tree_code code = TREE_CODE (type);
   bool is_named
@@ -2872,6 +2874,9 @@ create_type_decl (tree name, tree type, bool artificial_p, bool debug_info_p,
 
   DECL_ARTIFICIAL (type_decl) = artificial_p;
   TYPE_ARTIFICIAL (type) = artificial_p;
+  DECL_NAMELESS (type_decl) = (artificial_p
+                              && can_be_nameless
+                              && gnat_encodings != DWARF_GNAT_ENCODINGS_ALL);
 
   /* Add this decl to the current binding level.  */
   gnat_pushdecl (type_decl, gnat_node);