public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-2150] [Ada] Prevent crash on inspection point for unfrozen entity
Date: Thu,  8 Jul 2021 13:36:44 +0000 (GMT)	[thread overview]
Message-ID: <20210708133644.69F5E389853C@sourceware.org> (raw)

https://gcc.gnu.org/g:cd4341ef953bc5697917b3e6e43c59be03da0bee

commit r12-2150-gcd4341ef953bc5697917b3e6e43c59be03da0bee
Author: Ghjuvan Lacambre <lacambre@adacore.com>
Date:   Tue May 25 14:12:37 2021 +0200

    [Ada] Prevent crash on inspection point for unfrozen entity
    
    gcc/ada/
    
            * exp_prag.adb (Expand_Pragma_Inspection_Point): After expansion
            of the Inspection_Point pragma, check if referenced entities
            that have a freeze node are already frozen. If they aren't, emit
            a warning and turn the pragma into a no-op.

Diff:
---
 gcc/ada/exp_prag.adb | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/gcc/ada/exp_prag.adb b/gcc/ada/exp_prag.adb
index 2828f5a24db..f686395a9ef 100644
--- a/gcc/ada/exp_prag.adb
+++ b/gcc/ada/exp_prag.adb
@@ -2361,6 +2361,7 @@ package body Exp_Prag is
       S     : Entity_Id;
       E     : Entity_Id;
 
+      Remove_Inspection_Point : Boolean := False;
    begin
       if No (Pragma_Argument_Associations (N)) then
          A := New_List;
@@ -2400,6 +2401,36 @@ package body Exp_Prag is
          Expand (Expression (Assoc));
          Next (Assoc);
       end loop;
+
+      --  If any of the references have a freeze node, it must appear before
+      --  pragma Inspection_Point, otherwise the entity won't be available when
+      --  Gigi processes Inspection_Point.
+      --  When this requirement isn't met, turn the pragma into a no-op.
+
+      Assoc := First (Pragma_Argument_Associations (N));
+      while Present (Assoc) loop
+
+         if Present (Freeze_Node (Entity (Expression (Assoc)))) and then
+           not Is_Frozen (Entity (Expression (Assoc)))
+         then
+            Error_Msg_NE ("?inspection point references unfrozen object &",
+              Assoc,
+              Entity (Expression (Assoc)));
+            Remove_Inspection_Point := True;
+         end if;
+
+         Next (Assoc);
+      end loop;
+
+      if Remove_Inspection_Point then
+         Error_Msg_N ("\pragma will be ignored", N);
+
+         --  We can't just remove the pragma from the tree as it might be
+         --  iterated over by the caller. Turn it into a null statement
+         --  instead.
+
+         Rewrite (N, Make_Null_Statement (Sloc (N)));
+      end if;
    end Expand_Pragma_Inspection_Point;
 
    --------------------------------------


                 reply	other threads:[~2021-07-08 13:36 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=20210708133644.69F5E389853C@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@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).