public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Reorder code for validity checks of unchecked conversions
@ 2021-06-16  8:43 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-06-16  8:43 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

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

The placement of check for types of an unchecked conversion being
generic was done in the middle of switching from their original to
underlying views, which was inconsistent and made the surrounding
comments confusing.

Code cleanup in preparation for a follow-up improvement; behaviour is
unaffected, because the flag Is_Generic_Type is present in all views.

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

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.

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

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -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;



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

only message in thread, other threads:[~2021-06-16  8:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-16  8:43 [Ada] Reorder code for validity checks of unchecked conversions 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).