public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Ada2020 AI12-0282: Shared variable control aspects in generics
@ 2020-06-09  8:10 Pierre-Marie de Rodat
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre-Marie de Rodat @ 2020-06-09  8:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

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

This patch further refines the checks and the corresponding error
messsages on the legality of instantiations where some formal types and
their corresponding actuals may carry Atomic,  Volatile, etc.  aspect
specifications. The legality rules stated in RN 6.1 (12/5) are in fact
backward-incompatible because they violate a basic language design rule,
namely that limited private formal types impose no constraint on the
corresponding formals. Pending further ARG discussions the current code
reverts the checking for an exact match between specified aspects to
fornal derived types only.

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

2020-06-09  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* sem_ch12.adb (Check_Shared_Variable_Control_Aspects): Require
	exact match between formal and actual for aspects Atomic and
	Volatile only for formal derived types.

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

--- gcc/ada/sem_ch12.adb
+++ gcc/ada/sem_ch12.adb
@@ -12394,19 +12394,38 @@ package body Sem_Ch12 is
 
       --  Ada 2020: Verify that shared variable control aspects (RM C.6)
       --  that may be specified for the formal are obeyed by the actual.
+      --  If the fornal is a derived type the aspect specifications must match.
+      --  NOTE: AI12-0282 implies that matching of aspects is required between
+      --  formal and actual in all cases, but this is too restrictive.
+      --  In particular it violates a language design rule: a limited private
+      --  indefinite formal can be matched by any actual. The current code
+      --  reflects an older and more permissve version of RM C.6 (12/5).
 
       procedure Check_Shared_Variable_Control_Aspects is
       begin
          if Ada_Version >= Ada_2020 then
-            if Is_Atomic (A_Gen_T) /= Is_Atomic (Act_T) then
+            if Is_Atomic (A_Gen_T) and then not Is_Atomic (Act_T) then
+               Error_Msg_NE
+                  ("actual for& must have Atomic aspect", Actual, A_Gen_T);
+
+            elsif Is_Derived_Type (A_Gen_T)
+              and then Is_Atomic (A_Gen_T) /= Is_Atomic (Act_T)
+            then
                Error_Msg_NE
                   ("actual for& has different Atomic aspect", Actual, A_Gen_T);
             end if;
 
-            if Is_Volatile (A_Gen_T) /= Is_Volatile (Act_T) then
+            if Is_Volatile (A_Gen_T) and then not Is_Volatile (Act_T) then
                Error_Msg_NE
                   ("actual for& has different Volatile aspect",
                     Actual, A_Gen_T);
+
+            elsif Is_Derived_Type (A_Gen_T)
+              and then Is_Volatile (A_Gen_T) /= Is_Volatile (Act_T)
+            then
+               Error_Msg_NE
+                  ("actual for& has different Volatile aspect",
+                     Actual, A_Gen_T);
             end if;
 
             --  We assume that an array type whose atomic component type


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Ada] Ada2020 AI12-0282: Shared variable control aspects in generics
@ 2020-06-09  8:10 Pierre-Marie de Rodat
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre-Marie de Rodat @ 2020-06-09  8:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

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

This patch refines the checks and the corresponding error messsages on
the legality of instantiations where some formal objects and their
corresponding actuals may carry Atomic, Atonic_Components,  Volatile,
Volatile_Components, Independent, or Independent_Components aspect
specifications. The legality rules require exact match between formal
and actual for the first four aspects, but not for the last two.  For
Atomic_Components and Volatile_Components we also check whether the
actual is of an array type with the corresponding: aspect on its
component type.

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

2020-06-09  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* sem_ch12.adb (Check_Shared_Variable_Control_Aspects): Require
	exact match between formal and actual for aspects Atomic,
	Atomic_Component, Volatile, and Volatile_Components.

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

--- gcc/ada/sem_ch12.adb
+++ gcc/ada/sem_ch12.adb
@@ -12398,21 +12398,15 @@ package body Sem_Ch12 is
       procedure Check_Shared_Variable_Control_Aspects is
       begin
          if Ada_Version >= Ada_2020 then
-            if Is_Atomic (A_Gen_T) and then not Is_Atomic (Act_T) then
+            if Is_Atomic (A_Gen_T) /= Is_Atomic (Act_T) then
                Error_Msg_NE
-                  ("actual for& must be an atomic type", Actual, A_Gen_T);
+                  ("actual for& has different Atomic aspect", Actual, A_Gen_T);
             end if;
 
-            if Is_Volatile (A_Gen_T) and then not Is_Volatile (Act_T) then
+            if Is_Volatile (A_Gen_T) /= Is_Volatile (Act_T) then
                Error_Msg_NE
-                  ("actual for& must be a Volatile type", Actual, A_Gen_T);
-            end if;
-
-            if
-              Is_Independent (A_Gen_T) and then not Is_Independent (Act_T)
-            then
-               Error_Msg_NE
-                 ("actual for& must be an Independent type", Actual, A_Gen_T);
+                  ("actual for& has different Volatile aspect",
+                    Actual, A_Gen_T);
             end if;
 
             --  We assume that an array type whose atomic component type
@@ -12420,43 +12414,51 @@ package body Sem_Ch12 is
             --  aspect Has_Atomic_Components. This is a reasonable inference
             --  from the intent of AI12-0282, and makes it legal to use an
             --  actual that does not have the identical aspect as the formal.
+            --  Ditto for volatile components.
 
-            if Has_Atomic_Components (A_Gen_T)
-               and then not Has_Atomic_Components (Act_T)
-            then
-               if Is_Array_Type (Act_T)
-                 and then Is_Atomic (Component_Type (Act_T))
-               then
-                  null;
+            declare
+               Actual_Atomic_Comp : constant Boolean :=
+               Has_Atomic_Components (Act_T)
+                      or else (Is_Array_Type (Act_T)
+                                and then Is_Atomic (Component_Type (Act_T)));
+            begin
+               if Has_Atomic_Components (A_Gen_T) /= Actual_Atomic_Comp then
+                  Error_Msg_NE
+                    ("formal and actual for& must agree on atomic components",
+                       Actual, A_Gen_T);
+               end if;
+            end;
 
-               else
+            declare
+               Actual_Volatile_Comp : constant Boolean :=
+                 Has_Volatile_Components (Act_T)
+                   or else (Is_Array_Type (Act_T)
+                             and then Is_Volatile (Component_Type (Act_T)));
+            begin
+               if Has_Volatile_Components (A_Gen_T) /= Actual_Volatile_Comp
+               then
                   Error_Msg_NE
-                    ("actual for& must have atomic components",
+                    ("actual for& must have volatile components",
                        Actual, A_Gen_T);
                end if;
-            end if;
+            end;
 
-            if Has_Independent_Components (A_Gen_T)
-               and then not Has_Independent_Components (Act_T)
+            --  The following two aspects do not require exact matching,
+            --  but only one-way agreement. See RM C.6.
+
+            if Is_Independent (A_Gen_T) and then not Is_Independent (Act_T)
             then
                Error_Msg_NE
-                 ("actual for& must have independent components",
-                    Actual, A_Gen_T);
+                 ("actual for& must have Independent aspect specified",
+                     Actual, A_Gen_T);
             end if;
 
-            if Has_Volatile_Components (A_Gen_T)
-               and then not Has_Volatile_Components (Act_T)
+            if Has_Independent_Components (A_Gen_T)
+              and then not Has_Independent_Components (Act_T)
             then
-               if Is_Array_Type (Act_T)
-                 and then Is_Volatile (Component_Type (Act_T))
-               then
-                  null;
-
-               else
-                  Error_Msg_NE
-                    ("actual for& must have volatile components",
-                       Actual, A_Gen_T);
-               end if;
+               Error_Msg_NE
+                 ("actual for& must have Independent_Components specified",
+                     Actual, A_Gen_T);
             end if;
          end if;
       end Check_Shared_Variable_Control_Aspects;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-09  8:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-09  8:10 [Ada] Ada2020 AI12-0282: Shared variable control aspects in generics Pierre-Marie de Rodat
  -- strict thread matches above, loose matches on Subject: below --
2020-06-09  8:10 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).