]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Reorder code for validity checks of unchecked conversions
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 17 Feb 2021 22:32:25 +0000 (23:32 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 16 Jun 2021 08:42:58 +0000 (04:42 -0400)
gcc/ada/

* sem_ch13.adb (Validate_Unchecked_Conversion): Move detection
of generic types before switching to their private views; fix
style in using AND THEN.

gcc/ada/sem_ch13.adb

index a9770db6b61fc3e3e3833675843c627fe358445e..8aa62c89debcb11aa5172f699a687f6d8e0ebf6e 100644 (file)
@@ -16578,18 +16578,7 @@ package body Sem_Ch13 is
       --  here because the processing for generic instantiation always makes
       --  subtypes, and we want the original frozen actual types.
 
-      --  If we are dealing with private types, then do the check on their
-      --  fully declared counterparts if the full declarations have been
-      --  encountered (they don't have to be visible, but they must exist).
-
       Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
-
-      if Is_Private_Type (Source)
-        and then Present (Underlying_Type (Source))
-      then
-         Source := Underlying_Type (Source);
-      end if;
-
       Target := Ancestor_Subtype (Etype (Act_Unit));
 
       --  If either type is generic, the instantiation happens within a generic
@@ -16600,6 +16589,16 @@ package body Sem_Ch13 is
          return;
       end if;
 
+      --  If we are dealing with private types, then do the check on their
+      --  fully declared counterparts if the full declarations have been
+      --  encountered (they don't have to be visible, but they must exist).
+
+      if Is_Private_Type (Source)
+        and then Present (Underlying_Type (Source))
+      then
+         Source := Underlying_Type (Source);
+      end if;
+
       if Is_Private_Type (Target)
         and then Present (Underlying_Type (Target))
       then
@@ -16692,8 +16691,8 @@ package body Sem_Ch13 is
       --  in the same unit as the unchecked conversion, then set the flag
       --  No_Strict_Aliasing (no strict aliasing is implicit here)
 
-      if Is_Access_Type (Target) and then
-        In_Same_Source_Unit (Target, N)
+      if Is_Access_Type (Target)
+        and then In_Same_Source_Unit (Target, N)
       then
          Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
       end if;