public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [Ada] Fix bug in node/entity kind numbers in sinfo/einfo.h
Date: Wed, 30 Jun 2021 05:30:45 -0400	[thread overview]
Message-ID: <20210630093045.GA147204@adacore.com> (raw)

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

This patch fixes a bug in the node/entity kinds that are generated by
Gen_IL in sinfo/einfo.h. These numbers should be the same as the 'Pos of
the corresponding enumeration literals in Node_Kind and Entity_Kind.

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

gcc/ada/

	* gen_il-gen.adb (Put_C_Type_And_Subtypes): Put the correct
	numbers.
	* gen_il-internals.ads, gen_il-internals.adb: (Pos): Remove this
	function. It was assuming that the order of the enumeration
	literals in Type_Enum is the same as the order of the generated
	types Node_Kind and Entity_Kind, which is not true.

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

diff --git a/gcc/ada/gen_il-gen.adb b/gcc/ada/gen_il-gen.adb
--- a/gcc/ada/gen_il-gen.adb
+++ b/gcc/ada/gen_il-gen.adb
@@ -2930,9 +2930,15 @@ package body Gen_IL.Gen is
       procedure Put_C_Type_And_Subtypes
         (S : in out Sink; Root : Root_Type) is
 
+         Cur_Pos : Root_Nat := 0;
+         --  Current Node_Kind'Pos or Entity_Kind'Pos to be printed
+
          procedure Put_Enum_Lit (T : Node_Or_Entity_Type);
          --  Print out the #define corresponding to the Ada enumeration literal
          --  for T in Node_Kind and Entity_Kind (i.e. concrete types).
+         --  This looks like "#define Some_Kind <pos>", where Some_Kind
+         --  is the Node_Kind or Entity_Kind enumeration literal, and
+         --  <pos> is Node_Kind'Pos or Entity_Kind'Pos of that literal.
 
          procedure Put_Kind_Subtype (T : Node_Or_Entity_Type);
          --  Print out the SUBTYPE macro call corresponding to an abstract
@@ -2941,7 +2947,8 @@ package body Gen_IL.Gen is
          procedure Put_Enum_Lit (T : Node_Or_Entity_Type) is
          begin
             if T in Concrete_Type then
-               Put (S, "#define " & Image (T) & " " & Image (Pos (T)) & "" & LF);
+               Put (S, "#define " & Image (T) & " " & Image (Cur_Pos) & LF);
+               Cur_Pos := Cur_Pos + 1;
             end if;
          end Put_Enum_Lit;
 
@@ -2961,7 +2968,7 @@ package body Gen_IL.Gen is
          Iterate_Types (Root, Pre => Put_Enum_Lit'Access);
 
          Put (S, "#define Number_" & Node_Or_Entity (Root) & "_Kinds " &
-              Image (Pos (Last_Concrete (Root)) + 1) & "" & LF & LF);
+              Image (Cur_Pos) & "" & LF & LF);
 
          Iterate_Types (Root, Pre => Put_Kind_Subtype'Access);
 


diff --git a/gcc/ada/gen_il-internals.adb b/gcc/ada/gen_il-internals.adb
--- a/gcc/ada/gen_il-internals.adb
+++ b/gcc/ada/gen_il-internals.adb
@@ -477,16 +477,4 @@ package body Gen_IL.Internals is
       Put (S, "--  End type hierarchy for " & N_Or_E & LF & LF);
    end Put_Type_Hierarchy;
 
-   ---------
-   -- Pos --
-   ---------
-
-   function Pos (T : Concrete_Type) return Root_Nat is
-      First : constant Concrete_Type :=
-        (if T in Concrete_Node then Concrete_Node'First
-         else Concrete_Entity'First);
-   begin
-      return Type_Enum'Pos (T) - Type_Enum'Pos (First);
-   end Pos;
-
 end Gen_IL.Internals;


diff --git a/gcc/ada/gen_il-internals.ads b/gcc/ada/gen_il-internals.ads
--- a/gcc/ada/gen_il-internals.ads
+++ b/gcc/ada/gen_il-internals.ads
@@ -202,7 +202,10 @@ package Gen_IL.Internals is
         Nil'Access);
    --  Iterate top-down on the type hierarchy. Call Pre and Post before and
    --  after walking child types. Note that this ignores union types, because
-   --  they are nonhierarchical.
+   --  they are nonhierarchical. The order in which concrete types are visited
+   --  matches the order of the generated enumeration types Node_Kind and
+   --  Entity_Kind, which is not the same as the order of the Type_Enum
+   --  type in Gen_IL.Types.
 
    function Is_Descendant (Ancestor, Descendant : Node_Or_Entity_Type)
      return Boolean;
@@ -212,9 +215,6 @@ package Gen_IL.Internals is
 
    procedure Put_Type_Hierarchy (S : in out Sink; Root : Root_Type);
 
-   function Pos (T : Concrete_Type) return Root_Nat;
-   --  Return Node_Kind'Pos (T) or Entity_Kind'Pos (T)
-
    ----------------
 
    type Field_Desc is record



                 reply	other threads:[~2021-06-30  9:30 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=20210630093045.GA147204@adacore.com \
    --to=derodat@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).