From 299cd64b9e5f1c148b055bd2017a9473fa95227e Mon Sep 17 00:00:00 2001 From: Piotr Trojanek Date: Fri, 9 Aug 2024 17:52:51 +0200 Subject: [PATCH] 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. --- 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.47.2