[Ada] tech debt: clean up Component_Size
authorBob Duff <duff@adacore.com>
Fri, 9 Apr 2021 12:56:23 +0000 (08:56 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 29 Jun 2021 14:23:46 +0000 (14:23 +0000)
gcc/ada/

* einfo.ads (Component_Bit_Offset, Component_Size): Update
documentation: Repinfo is the package where these negative
values are documented.
* einfo-utils.adb (Known_Component_Size,
Known_Static_Component_Size, Unknown_Component_Size): Remove
calls to Implementation_Base_Type, because Component_Size is an
Impl_Base_Type_Only field (see Gen_Entities).
* sem_ch13.ads, sem_ch13.adb (Check_Size): Do not set Esize and
RM_Size. This is unnecessary in the case of Size. For
Component_Size, it is wrong, because we would be setting the
Esize and RM_Size of the component type.

gcc/ada/einfo-utils.adb
gcc/ada/einfo.ads
gcc/ada/sem_ch13.adb
gcc/ada/sem_ch13.ads

index 0641862..02ccef1 100644 (file)
@@ -515,8 +515,8 @@ package body Einfo.Utils is
 
    function Known_Component_Size                  (E : Entity_Id) return B is
    begin
-      return Component_Size (Implementation_Base_Type (E)) /= Uint_0
-        and then Component_Size (Implementation_Base_Type (E)) /= No_Uint;
+      return Component_Size (E) /= Uint_0
+        and then Component_Size (E) /= No_Uint;
    end Known_Component_Size;
 
    function Known_Esize                           (E : Entity_Id) return B is
@@ -556,7 +556,7 @@ package body Einfo.Utils is
 
    function Known_Static_Component_Size           (E : Entity_Id) return B is
    begin
-      return Component_Size (Implementation_Base_Type (E)) > Uint_0;
+      return Component_Size (E) > Uint_0;
    end Known_Static_Component_Size;
 
    function Known_Static_Esize                    (E : Entity_Id) return B is
@@ -604,9 +604,7 @@ package body Einfo.Utils is
 
    function Unknown_Component_Size                (E : Entity_Id) return B is
    begin
-      return Component_Size (Implementation_Base_Type (E)) = Uint_0
-               or else
-             Component_Size (Implementation_Base_Type (E)) = No_Uint;
+      return not Known_Component_Size (E);
    end Unknown_Component_Size;
 
    function Unknown_Esize                         (E : Entity_Id) return B is
index 4c5a2da..5298998 100644 (file)
@@ -669,7 +669,7 @@ package Einfo is
 --       this field is always set. A negative value is used to represent
 --       a value which is not known at compile time, and must be computed
 --       at run-time (this happens if fields of a record have variable
---       lengths). See package Layout for details of these values.
+--       lengths). See package Repinfo for details of these values.
 --
 --       Note: Component_Bit_Offset is redundant with respect to the fields
 --       Normalized_First_Bit and Normalized_Position, and could in principle
@@ -691,8 +691,9 @@ package Einfo is
 --       by the front end in package Layout, or by the backend. A negative
 --       value is used to represent a value which is not known at compile
 --       time, and must be computed at run-time (this happens if the type
---       of the component has a variable length size). See package Layout
---       for details of these values.
+--       of the component has a variable length size). See package Repinfo
+--       for details of these values. Component_Size can also be negative in
+--       an illegal program that says e.g. "for T'Component_Size use -8;".
 
 --    Component_Type [implementation base type only]
 --       Defined in array types and string types. References component type.
index cfcbe14..76dac2c 100644 (file)
@@ -12479,8 +12479,6 @@ package body Sem_Ch13 is
 
             else
                Size_Too_Small_Error (Asiz);
-               Set_Esize   (T, Asiz);
-               Set_RM_Size (T, Asiz);
             end if;
          end;
 
@@ -12518,8 +12516,6 @@ package body Sem_Ch13 is
 
             if Siz < M then
                Size_Too_Small_Error (M);
-               Set_Esize   (T, M);
-               Set_RM_Size (T, M);
             else
                Biased := True;
             end if;
index 3869f92..7579812 100644 (file)
@@ -125,8 +125,7 @@ package Sem_Ch13 is
    --  set if the type is not currently biased, but biasing it is the only
    --  way to meet the requirement. If the type is currently biased, then
    --  this biased size is used in the initial check, and Biased is False.
-   --  If the size is too small, and an error message is given, then both
-   --  Esize and RM_Size are reset to the allowed minimum value in T.
+   --  For a Component_Size clause, T is the component type.
 
    function Has_Compatible_Representation
      (Target_Type, Operand_Type : Entity_Id) return Boolean;