From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTPS id C7087382C41F for ; Wed, 30 Jun 2021 09:30:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C7087382C41F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 4F43E116B29 for ; Wed, 30 Jun 2021 05:30:45 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id J2VxvNa6zJMv for ; Wed, 30 Jun 2021 05:30:45 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 3C053116B1B for ; Wed, 30 Jun 2021 05:30:45 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 3B44F1E7; Wed, 30 Jun 2021 05:30:45 -0400 (EDT) Date: Wed, 30 Jun 2021 05:30:45 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix bug in node/entity kind numbers in sinfo/einfo.h Message-ID: <20210630093045.GA147204@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="envbJBWh7q8WU6mo" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Jun 2021 09:30:47 -0000 --envbJBWh7q8WU6mo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. --envbJBWh7q8WU6mo Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" 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 ", where Some_Kind + -- is the Node_Kind or Entity_Kind enumeration literal, and + -- 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 --envbJBWh7q8WU6mo--