https://gcc.gnu.org/g:299cd64b9e5f1c148b055bd2017a9473fa95227e
commit r15-3293-g299cd64b9e5f1c148b055bd2017a9473fa95227e Author: Piotr Trojanek <troja...@adacore.com> Date: Fri Aug 9 17:52:51 2024 +0200 ada: Ensure validity checks for private scalar types 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. Diff: --- 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 83879a519f7d..2fb750c3ba47 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 bf04ea9d70a5..4f6fa4cf6b71 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;