]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Illegal selection of first object in a task type's body not detected
authorpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 14 Aug 2019 09:50:46 +0000 (09:50 +0000)
committerpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 14 Aug 2019 09:50:46 +0000 (09:50 +0000)
The compiler was improperly allowing selection of an object declared
within a task body when the prefix was of the task type, specifically in
the case where the object was the very first declared in the body
(selections of later body declarations were being flagged).  The flag
Is_Private_Op was only set at the point of the first "private"
declaration of the type in cases where the first declaration's name
didn't match the selector.

2019-08-14  Gary Dismukes  <dismukes@adacore.com>

gcc/ada/

* sem_ch4.adb (Analyze_Selected_Component): In the case where
the prefix is of a concurrent type, and the selected entity
matching the selector is the first private declaration of the
type (such as the first local variable in a task's body), set
Is_Private_Op.

gcc/testsuite/

* gnat.dg/task5.adb: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@274446 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/sem_ch4.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/task5.adb [new file with mode: 0644]

index 937ceccdd822610f5986e30a8c066f5e83c67731..8ad19833248ac8c767ea60fbd0faec6354ee5602 100644 (file)
@@ -1,3 +1,11 @@
+2019-08-14  Gary Dismukes  <dismukes@adacore.com>
+
+       * sem_ch4.adb (Analyze_Selected_Component): In the case where
+       the prefix is of a concurrent type, and the selected entity
+       matching the selector is the first private declaration of the
+       type (such as the first local variable in a task's body), set
+       Is_Private_Op.
+
 2019-08-14  Piotr Trojanek  <trojanek@adacore.com>
 
        * einfo.adb (Is_Generic_Actual_Subprogram): Replace repeated
index 627257875ddfb195d9d8a196b31bda28d547fc37..16614edd98584e843fbece134ad8ee734768a2c3 100644 (file)
@@ -4994,7 +4994,15 @@ package body Sem_Ch4 is
                if Comp = First_Private_Entity (Type_To_Use) then
                   if Etype (Sel) /= Any_Type then
 
-                     --  We have a candiate
+                     --  If the first private entity's name matches, then treat
+                     --  it as a private op: needed for the error check for
+                     --  illegal selection of private entities further below.
+
+                     if Chars (Comp) = Chars (Sel) then
+                        Is_Private_Op := True;
+                     end if;
+
+                     --  We have a candidate, so exit the loop
 
                      exit;
 
index 1b42e8d449a25152f48f59757a42d6f96344aacf..0c6852b87771338b0b0b321614aa8eac85c2f34d 100644 (file)
@@ -1,3 +1,7 @@
+2019-08-14  Gary Dismukes  <dismukes@adacore.com>
+
+       * gnat.dg/task5.adb: New testcase.
+
 2019-08-14  Richard Biener  <rguenther@suse.de>
 
        PR testsuite/91419
diff --git a/gcc/testsuite/gnat.dg/task5.adb b/gcc/testsuite/gnat.dg/task5.adb
new file mode 100644 (file)
index 0000000..cc8ec63
--- /dev/null
@@ -0,0 +1,26 @@
+procedure Task5 is
+
+   task type T is
+      entry E (V1, V2 : Integer);
+   end T;
+
+   T_Obj : T;
+
+   task body T is
+      V1 : Integer;
+      V2 : Integer;
+      V3 : Integer;
+   begin
+      accept E (V1, V2 : Integer) do
+         T.V1 := V1;
+         T.V2 := V2;
+
+         T_Obj.V1 := V1;  -- { dg-error "invalid reference to private operation of some object of type \"T\"" }
+         T_Obj.V2 := V2;  -- { dg-error "invalid reference to private operation of some object of type \"T\"" }
+         T_Obj.V3 := V3;  -- { dg-error "invalid reference to private operation of some object of type \"T\"" }
+      end E;
+   end T;
+
+begin
+   null;
+end Task5;