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: Piotr Trojanek <trojanek@adacore.com>
Subject: [COMMITTED] ada: Raise Tag_Error when Ada.Tags operations are called with No_Tag
Date: Tue,  8 Nov 2022 09:41:33 +0100	[thread overview]
Message-ID: <20221108084133.300737-1-poulhies@adacore.com> (raw)

From: Piotr Trojanek <trojanek@adacore.com>

Implement missing behavior of RM 13.9 (25.1/3): Tag_Error is raised by a
call of Interface_Ancestor_Tags and Is_Descendant_At_Same_Level, if any
tag passed is No_Tag. This change also fixes Descendant_Tag, which
relies on Is_Descendant_At_Same_Level. The remaining operations already
worked properly.

gcc/ada/

	* libgnat/a-tags.adb
	(Interface_Ancestor_Tags): Raise Tag_Error on No_Tag.
	(Is_Descendant_At_Same_Level): Likewise.

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

---
 gcc/ada/libgnat/a-tags.adb | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/libgnat/a-tags.adb b/gcc/ada/libgnat/a-tags.adb
index d663a41f5a8..a9af942fc64 100644
--- a/gcc/ada/libgnat/a-tags.adb
+++ b/gcc/ada/libgnat/a-tags.adb
@@ -554,13 +554,18 @@ package body Ada.Tags is
    -----------------------------
 
    function Interface_Ancestor_Tags (T : Tag) return Tag_Array is
-      TSD_Ptr     : constant Addr_Ptr :=
-                      To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
-      TSD         : constant Type_Specific_Data_Ptr :=
-                      To_Type_Specific_Data_Ptr (TSD_Ptr.all);
-      Iface_Table : constant Interface_Data_Ptr := TSD.Interfaces_Table;
-
+      TSD_Ptr     : Addr_Ptr;
+      TSD         : Type_Specific_Data_Ptr;
+      Iface_Table : Interface_Data_Ptr;
    begin
+      if T = No_Tag then
+         raise Tag_Error;
+      end if;
+
+      TSD_Ptr     := To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
+      TSD         := To_Type_Specific_Data_Ptr (TSD_Ptr.all);
+      Iface_Table := TSD.Interfaces_Table;
+
       if Iface_Table = null then
          declare
             Table : Tag_Array (1 .. 0);
@@ -731,7 +736,10 @@ package body Ada.Tags is
       Ancestor   : Tag) return Boolean
    is
    begin
-      if Descendant = Ancestor then
+      if Descendant = No_Tag or else Ancestor = No_Tag then
+         raise Tag_Error;
+
+      elsif Descendant = Ancestor then
          return True;
 
       else
-- 
2.34.1


                 reply	other threads:[~2022-11-08  8:41 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=20221108084133.300737-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=trojanek@adacore.com \
    /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).