From 403bc026aca65b22159955dd4df81eb9b2b407f4 Mon Sep 17 00:00:00 2001 From: Pierre-Marie de Rodat Date: Thu, 16 Nov 2017 12:53:46 +0000 Subject: [PATCH] [multiple changes] 2017-11-16 Sylvain Dailler * sem_util.adb (Get_Enum_Lit_From_Pos): Add a condition for Pos lower than 0. 2017-11-16 Bob Duff * sem_ch13.adb (Check_Expr_Constants): Avoid error message in case of System'To_Address. From-SVN: r254818 --- gcc/ada/ChangeLog | 10 ++++++++++ gcc/ada/sem_ch13.adb | 9 +++++++++ gcc/ada/sem_util.adb | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 3f1e51f4acf..1f3cf290cd5 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,13 @@ +2017-11-16 Sylvain Dailler + + * sem_util.adb (Get_Enum_Lit_From_Pos): Add a condition for Pos + lower than 0. + +2017-11-16 Bob Duff + + * sem_ch13.adb (Check_Expr_Constants): Avoid error message in case of + System'To_Address. + 2017-11-16 Yannick Moy * sem_elab.adb (Include): Fix mode of parameter Curr to out. diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 83d31081fac..b501e14f31e 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -9783,6 +9783,15 @@ package body Sem_Ch13 is then Check_At_Constant_Address (Prefix (Nod)); + -- Normally, System'To_Address will have been transformed into + -- an Unchecked_Conversion, but in -gnatc mode, it will not, + -- and we don't want to give an error, because the whole point + -- of 'To_Address is that it is static. + + elsif Attribute_Name (Nod) = Name_To_Address then + pragma Assert (Operating_Mode = Check_Semantics); + null; + else Check_Expr_Constants (Prefix (Nod)); Check_List_Constants (Expressions (Nod)); diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 136505f23d5..576a7596180 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -9085,6 +9085,12 @@ package body Sem_Util is end if; Lit := First_Literal (Btyp); + + -- Position in the enumeration type starts at 0. + if UI_To_Int (Pos) < 0 then + raise Constraint_Error; + end if; + for J in 1 .. UI_To_Int (Pos) loop Next_Literal (Lit);