[COMMITTED,34/35] ada: Set DECL_NAMELESS in create_type_decl

Message ID 20241025091107.485741-34-poulhies@adacore.com
State Committed
Commit a60e7289350d7b04d4c81187070d705f441e9c70
Headers
Series [COMMITTED,01/35] ada: Pass parameters of full access unconstrained array types by copy in calls |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Marc Poulhiès Oct. 25, 2024, 9:11 a.m. UTC
  From: Tom Tromey <tromey@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/gcc-interface/decl.cc  | 6 +++---
 gcc/ada/gcc-interface/gigi.h   | 7 +++++--
 gcc/ada/gcc-interface/utils.cc | 9 +++++++--
 3 files changed, 15 insertions(+), 7 deletions(-)
  

Patch

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index ba75fa33093..372d72a18b6 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -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);
diff --git a/gcc/ada/gcc-interface/gigi.h b/gcc/ada/gcc-interface/gigi.h
index 00f00d967c7..875a3d6b87f 100644
--- a/gcc/ada/gcc-interface/gigi.h
+++ b/gcc/ada/gcc-interface/gigi.h
@@ -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.
 
diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc
index a06366bf40e..3a571e0077b 100644
--- a/gcc/ada/gcc-interface/utils.cc
+++ b/gcc/ada/gcc-interface/utils.cc
@@ -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);