public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Illegal selection of first object in a task type's body not detected
@ 2019-08-14  9:53 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-08-14  9:53 UTC (permalink / raw)
  To: gcc-patches; +Cc: Gary Dismukes

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

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.

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

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.

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

--- gcc/ada/sem_ch4.adb
+++ gcc/ada/sem_ch4.adb
@@ -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;
 

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/task5.adb
@@ -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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-14  9:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-14  9:53 [Ada] Illegal selection of first object in a task type's body not detected Pierre-Marie de Rodat

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).