diff mbox series

[Ada] Cleanup condition for an effectively volatile array type

Message ID 20200715134518.GA23599@adacore.com
State New
Headers show
Series [Ada] Cleanup condition for an effectively volatile array type | expand

Commit Message

Pierre-Marie de Rodat July 15, 2020, 1:45 p.m. UTC
When we detect effectively volatile array type we only need to examine
the type of array component if the array itself has no
Has_Volatile_Components property.

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

gcc/ada/

	* sem_prag.adb (Atomic_Components): Simplify with Ekind_In.
	(Complex_Representation): Fix type of E_Id, which just like when
	for pragma Atomic_Components will hold an N_Identifier node, not
	an entity.
	* sem_util.adb (Is_Effectively_Volatile): Refactor to avoid
	unnecessary computation.
diff mbox series

Patch

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -13626,9 +13626,7 @@  package body Sem_Prag is
             if (Nkind (D) = N_Full_Type_Declaration and then Is_Array_Type (E))
               or else
                 (Nkind (D) = N_Object_Declaration
-                   and then (Ekind (E) = E_Constant
-                              or else
-                             Ekind (E) = E_Variable)
+                   and then Ekind_In (E, E_Constant, E_Variable)
                    and then Nkind (Object_Definition (D)) =
                                        N_Constrained_Array_Definition)
               or else
@@ -14258,7 +14256,7 @@  package body Sem_Prag is
          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
 
          when Pragma_Complex_Representation => Complex_Representation : declare
-            E_Id : Entity_Id;
+            E_Id : Node_Id;
             E    : Entity_Id;
             Ent  : Entity_Id;
 


diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -15615,22 +15615,24 @@  package body Sem_Util is
          --  effectively volatile.
 
          elsif Is_Array_Type (Id) then
-            declare
-               Anc : Entity_Id := Base_Type (Id);
-            begin
-               if Is_Private_Type (Anc) then
-                  Anc := Full_View (Anc);
-               end if;
+            if Has_Volatile_Components (Id) then
+               return True;
+            else
+               declare
+                  Anc : Entity_Id := Base_Type (Id);
+               begin
+                  if Is_Private_Type (Anc) then
+                     Anc := Full_View (Anc);
+                  end if;
 
-               --  Test for presence of ancestor, as the full view of a private
-               --  type may be missing in case of error.
+                  --  Test for presence of ancestor, as the full view of a
+                  --  private type may be missing in case of error.
 
-               return
-                 Has_Volatile_Components (Id)
-                   or else
-                 (Present (Anc)
-                   and then Is_Effectively_Volatile (Component_Type (Anc)));
-            end;
+                  return
+                    Present (Anc)
+                      and then Is_Effectively_Volatile (Component_Type (Anc));
+               end;
+            end if;
 
          --  A protected type is always volatile