From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 519053850843; Wed, 13 Jul 2022 10:03:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 519053850843 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1659] [Ada] Fix if expression returning slice X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 94425248c769d45b5932079321311392e4d8e952 X-Git-Newrev: 7a03001cd2dadbe845f109382e4c0dc2dbb50820 Message-Id: <20220713100301.519053850843@sourceware.org> Date: Wed, 13 Jul 2022 10:03:01 +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: Wed, 13 Jul 2022 10:03:01 -0000 https://gcc.gnu.org/g:7a03001cd2dadbe845f109382e4c0dc2dbb50820 commit r13-1659-g7a03001cd2dadbe845f109382e4c0dc2dbb50820 Author: Marc Poulhiès Date: Thu Jun 30 13:35:10 2022 +0200 [Ada] Fix if expression returning slice The compiler incorrectly assumed the prefix for a slice returned in one branch of an if expression has its bounds known at compile time and would crash when this is not true. gcc/ada/ * exp_ch4.adb (Expand_N_If_Expression): Test for compile time known bounds when handling slices. Diff: --- gcc/ada/exp_ch4.adb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 911bdf31b78..18fb88f3f9f 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -6174,7 +6174,13 @@ package body Exp_Ch4 is Slice_Bnd : Node_Id) return Node_Id is begin - if Nkind (Elsex) = N_Slice then + -- We need to use the special processing for slices only if + -- they do not have compile-time known bounds; if they do, they + -- can be treated like any other expressions. + + if Nkind (Elsex) = N_Slice + and then not Compile_Time_Known_Bounds (Etype (Elsex)) + then if Compile_Time_Known_Value (Slice_Bnd) and then Expr_Value (Slice_Bnd) = Then_Bnd then @@ -6230,7 +6236,11 @@ package body Exp_Ch4 is begin Get_First_Index_Bounds (Etype (Thenx), Then_Lo, Then_Hi); - if Nkind (Elsex) = N_Slice then + -- See the rationale in Build_New_Bound + + if Nkind (Elsex) = N_Slice + and then not Compile_Time_Known_Bounds (Etype (Elsex)) + then Slice_Lo := Low_Bound (Discrete_Range (Elsex)); Slice_Hi := High_Bound (Discrete_Range (Elsex)); Get_First_Index_Bounds @@ -6289,7 +6299,11 @@ package body Exp_Ch4 is Set_Suppress_Assignment_Checks (Last (Then_List)); - if Nkind (Elsex) = N_Slice then + -- See the rationale in Build_New_Bound + + if Nkind (Elsex) = N_Slice + and then not Compile_Time_Known_Bounds (Etype (Elsex)) + then Else_List := New_List ( Make_Assignment_Statement (Loc, Name =>