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: Gary Dismukes <dismukes@adacore.com>
Subject: [COMMITED] ada: Accessibility error incorrectly flagged on call within Pre'Class expression
Date: Thu,  6 Oct 2022 11:28:47 +0200	[thread overview]
Message-ID: <20221006092847.260877-1-poulhies@adacore.com> (raw)

From: Gary Dismukes <dismukes@adacore.com>

The compiler was wrongly reporting an error on a function call within
a Pre'Class expression when a formal of the aspect's subprogram was
passed to an aliased formal. This occurred due to the call appearing
with the return statement of the wrapper function created for the
precondition, but the accessibility error check should only be done
for return statements that appear in the source program.

gcc/ada/

	* sem_ch4.adb (Analyze_Call): Add test of Comes_From_Source on the
	enclosing subprogram's Entity_Id for determining whether to
	perform the compile-time accessibility check on actuals passed to
	aliased formals in a function call occurring within a return
	statement. That test excludes cases where the call occurs within
	the return statement of a Pre'Class wrapper function.

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

---
 gcc/ada/sem_ch4.adb | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index ceaf66bd3e2..6824941fa34 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -1467,12 +1467,17 @@ package body Sem_Ch4 is
       end if;
 
       --  Check the accessibility level for actuals for explicitly aliased
-      --  formals.
+      --  formals when a function call appears within a return statement.
+      --  This is only checked if the enclosing subprogram Comes_From_Source,
+      --  to avoid issuing errors on calls occurring in wrapper subprograms
+      --  (for example, where the call is part of an expression of an aspect
+      --  associated with a wrapper, such as Pre'Class).
 
       if Nkind (N) = N_Function_Call
         and then Comes_From_Source (N)
         and then Present (Nam_Ent)
         and then In_Return_Value (N)
+        and then Comes_From_Source (Current_Subprogram)
       then
          declare
             Form : Node_Id;
-- 
2.34.1


                 reply	other threads:[~2022-10-06  9:29 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=20221006092847.260877-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=dismukes@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).