public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [Ada] Fix missing name for access type in generic instantiation
Date: Tue, 6 Sep 2022 09:16:03 +0200	[thread overview]
Message-ID: <20220906071603.GA1280545@poulhies-Precision-5550> (raw)

[-- Attachment #1: Type: text/plain, Size: 307 bytes --]

Pointer types aren't named types in C so we need to take extra care in Ada
to make sure that the name of access types is preserved.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* gcc-interface/utils.cc (gnat_pushdecl): Preserve named
	TYPE_DECLs consistently for all kind of pointer types.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2806 bytes --]

diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc
--- a/gcc/ada/gcc-interface/utils.cc
+++ b/gcc/ada/gcc-interface/utils.cc
@@ -868,6 +868,13 @@ gnat_pushdecl (tree decl, Node_Id gnat_node)
 	}
     }
 
+/* Pointer types aren't named types in the C sense so we need to generate a
+   typedef in DWARF for them.  Also do that for fat pointer types because,
+   even though they are named types in the C sense, they are still the XUP
+   types created for the base array type at this point.  */
+#define TYPE_IS_POINTER_P(NODE) \
+  (TREE_CODE (NODE) == POINTER_TYPE || TYPE_IS_FAT_POINTER_P (NODE))
+
   /* For the declaration of a type, set its name either if it isn't already
      set or if the previous type name was not derived from a source name.
      We'd rather have the type named with a real name and all the pointer
@@ -877,18 +884,14 @@ gnat_pushdecl (tree decl, Node_Id gnat_node)
     {
       tree t = TREE_TYPE (decl);
 
-      /* Pointer types aren't named types in the C sense so we need to generate
-         a typedef in DWARF for them and make sure it is preserved, unless the
-         type is artificial.  */
+      /* For pointer types, make sure the typedef is generated and preserved
+	 in DWARF, unless the type is artificial.  */
       if (!(TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
-	  && (TREE_CODE (t) != POINTER_TYPE || DECL_ARTIFICIAL (decl)))
+	  && (!TYPE_IS_POINTER_P (t) || DECL_ARTIFICIAL (decl)))
 	;
       /* For pointer types, create the DECL_ORIGINAL_TYPE that will generate
-	 the typedef in DWARF.  Also do that for fat pointer types because,
-	 even though they are named types in the C sense, they are still the
-	 XUP types created for the base array type at this point.  */
-      else if (!DECL_ARTIFICIAL (decl)
-	       && (TREE_CODE (t) == POINTER_TYPE || TYPE_IS_FAT_POINTER_P (t)))
+	 the typedef in DWARF.  */
+      else if (TYPE_IS_POINTER_P (t) && !DECL_ARTIFICIAL (decl))
 	{
 	  tree tt = build_variant_type_copy (t);
 	  TYPE_NAME (tt) = decl;
@@ -920,9 +923,8 @@ gnat_pushdecl (tree decl, Node_Id gnat_node)
 	 to all parallel types too thanks to gnat_set_type_context.  */
       if (t)
 	for (t = TYPE_MAIN_VARIANT (t); t; t = TYPE_NEXT_VARIANT (t))
-	  /* ??? Because of the previous kludge, we can have variants of fat
-	     pointer types with different names.  */
-	  if (!(TYPE_IS_FAT_POINTER_P (t)
+	  /* Skip it for pointer types to preserve the typedef.  */
+	  if (!(TYPE_IS_POINTER_P (t)
 		&& TYPE_NAME (t)
 		&& TREE_CODE (TYPE_NAME (t)) == TYPE_DECL))
 	    {
@@ -932,6 +934,8 @@ gnat_pushdecl (tree decl, Node_Id gnat_node)
 					 deferred_decl_context);
 	    }
     }
+
+#undef TYPE_IS_POINTER_P
 }
 
 /* Create a record type that contains a SIZE bytes long field of TYPE with a



                 reply	other threads:[~2022-09-06  7:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220906071603.GA1280545@poulhies-Precision-5550 \
    --to=poulhies@adacore.com \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).