[Ada] Expand renamings of subcomponents of an atomic or VFA object

Message ID 20191216103826.GA39378@adacore.com
State New
Headers show
Series
  • [Ada] Expand renamings of subcomponents of an atomic or VFA object
Related show

Commit Message

Pierre-Marie de Rodat Dec. 16, 2019, 10:38 a.m.
This change makes sure that the front-end expands the renamings of
subcomponents of atomic or Volatile_Full_Access objects, i.e. the
references in the renamed object are elaborated and the result is
substituted for the renaming in the expanded code.

This means that code generators implementing renaming by means of a
pointer can keep doing it in the presence of atomic (in Ada 2020) or
Volatile_Full_Access (in any version) objects in the source code.

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

2019-12-16  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* exp_ch8.adb (Expand_N_Object_Renaming_Declaration): Document
	third special case of renamings requiring special handling.
	(Evaluation_Required): Return true for an atomic or VFA prefix.

Patch

--- gcc/ada/exp_ch8.adb
+++ gcc/ada/exp_ch8.adb
@@ -72,7 +72,14 @@  package body Exp_Ch8 is
    --  clause applies (that can specify an arbitrary bit boundary), or where
    --  the enclosing record itself has a non-standard representation.
 
-   --  In these two cases, we pre-evaluate the renaming expression, by
+   --  In Ada 2020, a third case arises when the renamed object is a nonatomic
+   --  subcomponent of an atomic object, because reads of or writes to it must
+   --  access the enclosing atomic object. That's also the case for an object
+   --  subject to the Volatile_Full_Access GNAT aspect/pragma in any language
+   --  version. For the sake of simplicity, we treat any subcomponent of an
+   --  atomic or Volatile_Full_Access object in any language version this way.
+
+   --  In these three cases, we pre-evaluate the renaming expression, by
    --  extracting and freezing the values of any subscripts, and then we
    --  set the flag Is_Renaming_Of_Object which means that any reference
    --  to the object will be handled by macro substitution in the front
@@ -102,10 +109,10 @@  package body Exp_Ch8 is
       --  Determines whether it is necessary to do static name evaluation for
       --  renaming of Nam. It is considered necessary if evaluating the name
       --  involves indexing a packed array, or extracting a component of a
-      --  record to which a component clause applies. Note that we are only
-      --  interested in these operations if they occur as part of the name
-      --  itself, subscripts are just values that are computed as part of the
-      --  evaluation, so their form is unimportant.
+      --  record to which a component clause applies, or a subcomponent of an
+      --  atomic object. Note that we are only interested in these operations
+      --  if they occur as part of the name itself, subscripts are just values
+      --  that are computed as part of the evaluation, so they are unimportant.
       --  In addition, always return True for Modify_Tree_For_C since the
       --  code generator doesn't know how to handle renamings.
 
@@ -121,6 +128,10 @@  package body Exp_Ch8 is
          elsif Nkind_In (Nam, N_Indexed_Component, N_Slice) then
             if Is_Packed (Etype (Prefix (Nam))) then
                return True;
+
+            elsif Is_Atomic_Or_VFA_Object (Prefix (Nam)) then
+               return True;
+
             else
                return Evaluation_Required (Prefix (Nam));
             end if;
@@ -141,6 +152,9 @@  package body Exp_Ch8 is
                then
                   return True;
 
+               elsif Is_Atomic_Or_VFA_Object (Prefix (Nam)) then
+                  return True;
+
                else
                   return Evaluation_Required (Prefix (Nam));
                end if;