From: Piotr Trojanek <troja...@adacore.com>

When validating instances of Ada.Unchecked_Conversion, we explicitly detected
null arrays, because a size of 0 was used to indicate both an unknown size and
an actual size of 0. This limitation has been lifted, so we can remove
detection of null arrays.

Code cleanup; behavior is unaffected.

gcc/ada/ChangeLog:

        * sem_ch13.adb (Validate_Unchecked_Conversions): Remove detection of
        null arrays; remove tests for sizes being present, which are redundant
        after calling Known_Static_RM_Size.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch13.adb | 42 +++---------------------------------------
 1 file changed, 3 insertions(+), 39 deletions(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index f425048222e..fe6429fea97 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -18870,39 +18870,6 @@ package body Sem_Ch13 is
    ------------------------------------
 
    procedure Validate_Unchecked_Conversions is
-      function Is_Null_Array (T : Entity_Id) return Boolean;
-      --  We want to warn in the case of converting to a wrong-sized array of
-      --  bytes, including the zero-size case. This returns True in that case,
-      --  which is necessary because a size of 0 is used to indicate both an
-      --  unknown size and a size of 0. It's OK for this to return True in
-      --  other zero-size cases, but we don't go out of our way; for example,
-      --  we don't bother with multidimensional arrays.
-
-      function Is_Null_Array (T : Entity_Id) return Boolean is
-      begin
-         if Is_Array_Type (T) and then Is_Constrained (T) then
-            declare
-               Index : constant Node_Id := First_Index (T);
-               R : Node_Id; -- N_Range
-            begin
-               case Nkind (Index) is
-                  when N_Range =>
-                     R := Index;
-                  when N_Subtype_Indication =>
-                     R := Range_Expression (Constraint (Index));
-                  when N_Identifier | N_Expanded_Name =>
-                     R := Scalar_Range (Entity (Index));
-                  when others =>
-                     raise Program_Error;
-               end case;
-
-               return Is_Null_Range (Low_Bound (R), High_Bound (R));
-            end;
-         end if;
-
-         return False;
-      end Is_Null_Array;
-
    begin
       for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
          declare
@@ -18933,9 +18900,8 @@ package body Sem_Ch13 is
                goto Continue;
             end if;
 
-            if (Known_Static_RM_Size (Source)
-                  and then Known_Static_RM_Size (Target))
-              or else Is_Null_Array (Target)
+            if Known_Static_RM_Size (Source)
+              and then Known_Static_RM_Size (Target)
             then
                --  This validation check, which warns if we have unequal sizes
                --  for unchecked conversion, and thus implementation dependent
@@ -18946,9 +18912,7 @@ package body Sem_Ch13 is
                Source_Siz := RM_Size (Source);
                Target_Siz := RM_Size (Target);
 
-               if Present (Source_Siz) and then Present (Target_Siz)
-                 and then Source_Siz /= Target_Siz
-               then
+               if Source_Siz /= Target_Siz then
                   Error_Msg
                     ("?z?types for unchecked conversion have different sizes!",
                      Eloc, Act_Unit);
-- 
2.43.0

Reply via email to