diff mbox series

[COMMITTED,05/35] ada: Check subtype to avoid a precondition failure

Message ID 20240517083207.130391-5-poulhies@adacore.com
State New
Headers show
Series [COMMITTED,01/35] ada: Add support for 'Object_Size to pragma Compile_Time_{Warning, Error} | expand

Commit Message

Marc Poulhiès May 17, 2024, 8:31 a.m. UTC
From: Viljar Indus <indus@adacore.com>

gcc/ada/

	* sem_ch3.adb (Analyze_Component_Declaration):
	Apply range checks only for Scalar_Types to
	ensure that they have the Scalar_Range attribute.

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

---
 gcc/ada/sem_ch3.adb | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 7ee4ca299d9..263be607ec1 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -2029,8 +2029,9 @@  package body Sem_Ch3 is
 
                   while Present (Target_Index) loop
                      if Nkind (Subt_Index) in N_Expanded_Name | N_Identifier
-                     and then Nkind
-                        (Scalar_Range (Entity (Subt_Index))) = N_Range
+                       and then Is_Scalar_Type (Entity (Subt_Index))
+                       and then
+                         Nkind (Scalar_Range (Entity (Subt_Index))) = N_Range
                      then
                         Apply_Range_Check
                            (Expr        => Scalar_Range (Entity (Subt_Index)),