From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 1101F3858C36; Tue, 3 Jan 2023 09:33:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1101F3858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672738439; bh=WjMwHgTyEZkCmRMOSZox/37/8CMgq0PYoS6SXFhGyCQ=; h=From:To:Subject:Date:From; b=fFz+WFbH77c/tirIKy8gQsPEPc3nU8ztY/Jk9v9fFwH3Zspz6oXOedXqwA6Wwj671 S6YPqW4OG3vagmoPfrSGI3sDD6W4kAqbrvzmQfHpExHNm+1L/nfU5V65FzBMVXdmO6 NLqooLcNcjUkU990CDo2gChjsTWbjMgyxhXZRUng= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4963] ada: Make Sem_Util.Is_Aliased_View predicate more robust X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/master X-Git-Oldrev: 1fc93c2437dd3bc5cfd19b1397b9b0ca4c5f4064 X-Git-Newrev: 83d52e6de23f65cefde615183cdef1eb94d18b1f Message-Id: <20230103093359.1101F3858C36@sourceware.org> Date: Tue, 3 Jan 2023 09:33:59 +0000 (GMT) List-Id: https://gcc.gnu.org/g:83d52e6de23f65cefde615183cdef1eb94d18b1f commit r13-4963-g83d52e6de23f65cefde615183cdef1eb94d18b1f Author: Eric Botcazou Date: Wed Dec 7 17:26:27 2022 +0100 ada: Make Sem_Util.Is_Aliased_View predicate more robust The predicate implements the rules of the language so it needs to cope with constructs rewritten by the expander, in particular explicit dereferences that the expander uses liberally for various purposes. This change makes the detection of rewritten calls more robust, plugging an existing loophole for specific objects and exposing a missing propagation of the Is_Aliased flag for certain build-in-place objects, as well as adds the detection of rewritten return objects. It also contains a small enhancement to Set_Debug_Info_Defining_Id aimed at making it easier to debug the generated code by means of -gnatD. gcc/ada/ * sem_util.ads (Set_Debug_Info_Defining_Id): Adjust comment. * sem_util.adb (Is_Aliased_View) : Return false for more artificial dereferences generated by the expander. (Set_Debug_Info_Defining_Id): Set Debug_Info_Needed unconditionally in -gnatD mode. * exp_ch6.adb (Replace_Renaming_Declaration_Id): Also preserve the Is_Aliased flag. Diff: --- gcc/ada/exp_ch6.adb | 4 ++++ gcc/ada/sem_util.adb | 13 +++++++++++-- gcc/ada/sem_util.ads | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 0bc2559751b..975a96668df 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -9378,6 +9378,10 @@ package body Exp_Ch6 is Preserve_Comes_From_Source (Orig_Id, Orig_Decl); Set_Comes_From_Source (New_Id, False); + + -- Preserve aliased indication + + Set_Is_Aliased (Orig_Id, Is_Aliased (New_Id)); end Replace_Renaming_Declaration_Id; --------------------------------- diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index a1cebb08291..3132446515b 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -15255,8 +15255,15 @@ package body Sem_Util is then return Is_Aliased_View (Expression (Obj)); + -- The dereference of an access-to-object value denotes an aliased view, + -- but this routine uses the rules of the language so we need to exclude + -- rewritten constructs that introduce artificial dereferences. + elsif Nkind (Obj) = N_Explicit_Dereference then - return Nkind (Original_Node (Obj)) /= N_Function_Call; + return not Is_Captured_Function_Call (Obj) + and then not + (Nkind (Parent (Obj)) = N_Object_Renaming_Declaration + and then Is_Return_Object (Defining_Entity (Parent (Obj)))); else return False; @@ -27394,7 +27401,9 @@ package body Sem_Util is procedure Set_Debug_Info_Defining_Id (N : Node_Id) is begin - if Comes_From_Source (Defining_Identifier (N)) then + if Comes_From_Source (Defining_Identifier (N)) + or else Debug_Generated_Code + then Set_Debug_Info_Needed (Defining_Identifier (N)); end if; end Set_Debug_Info_Defining_Id; diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index b61695ea729..dc1bb084b54 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -3096,8 +3096,8 @@ package Sem_Util is -- associated name (i.e. the Node_Id associated with its name). procedure Set_Debug_Info_Defining_Id (N : Node_Id); - -- Call Set_Debug_Info_Needed on Defining_Identifier (N) if it comes - -- from source. + -- Call Set_Debug_Info_Needed on Defining_Identifier (N) if it comes from + -- source or we are in -gnatD mode, where we are debugging generated code. procedure Set_Debug_Info_Needed (T : Entity_Id); -- Sets the Debug_Info_Needed flag on entity T , and also on any entities