aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch5.adb
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2021-06-05 20:05:31 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2021-07-08 13:34:24 +0000
commitd45ee636a8474217ed2ee2bc3305e7d1e715df96 (patch)
tree455f4513a29d8c00fb92c98cd6d2d5aa97e2b413 /gcc/ada/sem_ch5.adb
parent8de68eb37c7275735a8deb78f44fe6535b9462ec (diff)
downloadgcc-d45ee636a8474217ed2ee2bc3305e7d1e715df96.zip
gcc-d45ee636a8474217ed2ee2bc3305e7d1e715df96.tar.gz
gcc-d45ee636a8474217ed2ee2bc3305e7d1e715df96.tar.bz2
[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.
Diffstat (limited to 'gcc/ada/sem_ch5.adb')
-rw-r--r--gcc/ada/sem_ch5.adb40
1 files changed, 40 insertions, 0 deletions
diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index f9813a5..82c33a2 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;