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
Cc: Ed Schonberg <schonberg@adacore.com>
Subject: [Ada] Fix scopes for local variables in task/protected bodies
Date: Tue, 09 Jul 2019 07:52:00 -0000	[thread overview]
Message-ID: <20190709075159.GA102829@adacore.com> (raw)

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

No impact on compilation with GCC.

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

2019-07-09  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* sem_util.adb (Scope_Within_Or_Same): Handle properly task
	bodies and protected bodies, so that local variables within have
	their proper scopes after these constructs have been rewritten
	during expansion. This patch resembles but is not identical to
	the code in Scope_Within.

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

--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -24268,13 +24268,32 @@ package body Sem_Util is
      (Inner : Entity_Id;
       Outer : Entity_Id) return Boolean
    is
-      Curr : Entity_Id;
-
+      Curr : Entity_Id := Inner;
    begin
-      Curr := Inner;
+      --  Similar to the above, but check for scope identity first.
+
       while Present (Curr) and then Curr /= Standard_Standard loop
          if Curr = Outer then
             return True;
+
+         elsif Ekind (Curr) = E_Task_Type
+           and then Outer = Task_Body_Procedure (Curr)
+         then
+            return True;
+
+         elsif Is_Subprogram (Curr)
+           and then Outer = Protected_Body_Subprogram (Curr)
+         then
+            return True;
+
+         elsif Is_Private_Type (Curr)
+           and then Present (Full_View (Curr))
+         then
+            if Full_View (Curr) = Outer then
+               return True;
+            else
+               return Scope_Within (Full_View (Curr), Outer);
+            end if;
          end if;
 
          Curr := Scope (Curr);


                 reply	other threads:[~2019-07-09  7:52 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=20190709075159.GA102829@adacore.com \
    --to=derodat@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=schonberg@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).