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-2168] [Ada] Diagnose properly illegal uses of Target_Name
Date: Thu,  8 Jul 2021 13:38:16 +0000 (GMT)	[thread overview]
Message-ID: <20210708133816.6F72D398B864@sourceware.org> (raw)

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

commit r12-2168-gd45ee636a8474217ed2ee2bc3305e7d1e715df96
Author: Ed Schonberg <schonberg@adacore.com>
Date:   Sat Jun 5 20:05:31 2021 -0400

    [Ada] Diagnose properly illegal uses of Target_Name
    
    gcc/ada/
    
            * sem_ch5.adb (Analyze_Target_Name): Properly reject a
            Target_Name when it appears outside of an assignment statement,
            or within the left-hand side of one.

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

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index f9813a5e4fa..82c33a204a8 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -4233,10 +4233,50 @@ package body Sem_Ch5 is
    -------------------------
 
    procedure Analyze_Target_Name (N : Node_Id) is
+      procedure Report_Error;
+
+      ------------------
+      -- Report_Error --
+      ------------------
+
+      procedure Report_Error is
+      begin
+         Error_Msg_N
+           ("must appear in the right-hand side of an assignment statement",
+             N);
+         Rewrite (N, New_Occurrence_Of (Any_Id, Sloc (N)));
+      end Report_Error;
+
    begin
       --  A target name has the type of the left-hand side of the enclosing
       --  assignment.
 
+      --  First, verify that the context is the right-hand side of an
+      --  assignment statement.
+
+      if No (Current_Assignment) then
+         Report_Error;
+         return;
+
+      else
+         declare
+            P : Node_Id := N;
+         begin
+            while Present (P)
+              and then Nkind (Parent (P)) /= N_Assignment_Statement
+            loop
+               P := Parent (P);
+            end loop;
+
+            if No (P)
+              or else P /= Expression (Parent (P))
+            then
+               Report_Error;
+               return;
+            end if;
+         end;
+      end if;
+
       Set_Etype (N, Etype (Name (Current_Assignment)));
    end Analyze_Target_Name;


                 reply	other threads:[~2021-07-08 13:38 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=20210708133816.6F72D398B864@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).