From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 092B83857C69; Fri, 7 Jan 2022 16:27:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 092B83857C69 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6349] [Ada] Check scalar range in arrays constructed by concatenation X-Act-Checkin: gcc X-Git-Author: Etienne Servais X-Git-Refname: refs/heads/master X-Git-Oldrev: b2f150304dc18af2f6b11005a140339f170d6fc2 X-Git-Newrev: 34b8a9b8c094a43566fe4fbe0f9252dcd4d92e70 Message-Id: <20220107162719.092B83857C69@sourceware.org> Date: Fri, 7 Jan 2022 16:27:19 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jan 2022 16:27:19 -0000 https://gcc.gnu.org/g:34b8a9b8c094a43566fe4fbe0f9252dcd4d92e70 commit r12-6349-g34b8a9b8c094a43566fe4fbe0f9252dcd4d92e70 Author: Etienne Servais Date: Tue Nov 30 17:47:52 2021 +0100 [Ada] Check scalar range in arrays constructed by concatenation gcc/ada/ * sem_res.adb (Resolve_Op_Concat_Arg): Check range when concatenating scalars. Diff: --- gcc/ada/sem_res.adb | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index 44b041431c8..d05da0d8dcc 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -10185,7 +10185,7 @@ package body Sem_Res is ("\\interpretation as call yields&", Arg, Typ); Error_Msg_NE ("\\interpretation as indexing of call yields&", - Arg, Component_Type (Typ)); + Arg, Ctyp); else Error_Msg_N ("ambiguous operand for concatenation!", Arg); @@ -10208,10 +10208,30 @@ package body Sem_Res is end; end if; - Resolve (Arg, Component_Type (Typ)); + Resolve (Arg, Ctyp); if Nkind (Arg) = N_String_Literal then - Set_Etype (Arg, Component_Type (Typ)); + Set_Etype (Arg, Ctyp); + + elsif Is_Scalar_Type (Etype (Arg)) + and then Compile_Time_Known_Value (Arg) + then + -- Determine if the out-of-range violation constitutes a + -- warning or an error according to the expression base type, + -- according to Ada 2022 RM 4.9 (35/2). + + if Is_Out_Of_Range (Arg, Base_Type (Ctyp)) then + Apply_Compile_Time_Constraint_Error + (Arg, "value not in range of}", CE_Range_Check_Failed, + Ent => Base_Type (Ctyp), + Typ => Base_Type (Ctyp)); + + elsif Is_Out_Of_Range (Arg, Ctyp) then + Apply_Compile_Time_Constraint_Error + (Arg, "value not in range of}??", CE_Range_Check_Failed, + Ent => Ctyp, + Typ => Ctyp); + end if; end if; if Arg = Left_Opnd (N) then