]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Ensure validity checks for private scalar types
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 9 Aug 2024 15:52:51 +0000 (17:52 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 29 Aug 2024 13:06:27 +0000 (15:06 +0200)
To check validity of data values, we must strip privacy from their
types.

gcc/ada/

* checks.adb (Expr_Known_Valid): Use Validated_View, which strips
type derivation and privacy.
* exp_ch3.adb (Simple_Init_Private_Type): Kill checks inside
unchecked conversions, just like in Simple_Init_Scalar_Type.

gcc/ada/checks.adb
gcc/ada/exp_ch3.adb

index 83879a519f7df3ad8aedfa354b74d0521ceeeb78..2fb750c3ba47fcf024011469832dab9522d2d8c4 100644 (file)
@@ -6833,7 +6833,7 @@ package body Checks is
    ----------------------
 
    function Expr_Known_Valid (Expr : Node_Id) return Boolean is
-      Typ : constant Entity_Id := Etype (Expr);
+      Typ : constant Entity_Id := Validated_View (Etype (Expr));
 
    begin
       --  Non-scalar types are always considered valid, since they never give
index bf04ea9d70a56c48b5f714c279b9b55008357c8f..4f6fa4cf6b71d24a9ed28e2f9102c03ffe0620f3 100644 (file)
@@ -10248,7 +10248,8 @@ package body Exp_Ch3 is
          if Nkind (Expr) = N_Unchecked_Type_Conversion
            and then Is_Scalar_Type (Under_Typ)
          then
-            Set_No_Truncation (Expr);
+            Set_Kill_Range_Check (Expr);
+            Set_No_Truncation    (Expr);
          end if;
 
          return Expr;