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

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.

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

---
 gcc/ada/checks.adb  | 2 +-
 gcc/ada/exp_ch3.adb | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index 83879a519f7..2fb750c3ba4 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -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
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index bf04ea9d70a..4f6fa4cf6b7 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -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;
-- 
2.45.2

Reply via email to