From patchwork Tue Jan 3 09:35:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 38340 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4525201wrt; Tue, 3 Jan 2023 01:41:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXv33EP6qDaQAJRPi5ywHcDQtwHzWbG+FT4Pb8UVc2qjdgXaq8/0eaMTGGHbuQFVfd6+l1QG X-Received: by 2002:a17:907:7f24:b0:7c0:e0d9:d1b7 with SMTP id qf36-20020a1709077f2400b007c0e0d9d1b7mr47778809ejc.0.1672738897378; Tue, 03 Jan 2023 01:41:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672738897; cv=none; d=google.com; s=arc-20160816; b=HT2vRX4GjbDSWWJVeTMWlHY2WOlO3s/j2DJsyv2NbPBdJDmIRFQRLws+lSBZqghMlf xxCMbGrrybxZLRJTc7OIvsjr+W8jTRjHVOE2MfAjCLGE865Ol7Fy4Djn/rbKqniuMFBZ h1RESeC/4Q9uvUs601BCb/yR+m4lXw35K044UYL+1k1pGpFYyKXOcSOV4DK/a/o43lVB lBu23Ytplru2zb87ooOqMw27ODvJpKI+OmNeQU7OsgSk3OJHHJ2ZXA3C8i8koEoa5BaT M07baroWeurPmFHqx7xqlB2qJ/ij0TSpao7REs9LoGRr0z8Tkx4d+IM2K40aPUsIv4Oh 2G/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:delivered-to:dkim-signature:dkim-filter; bh=WVzLZ8s4mD4o6sdIBQ62XwD+TjyzkRQw0nvr0ZNzZZ8=; b=CvTHGDwVXLzKwXVZ1zqdxRnk+56zHO6iAlFT447gS23MNhRcD6/E4uQFXseQS1MT1S QYRKF6MiJukQXagHk85LyvyL1H3ms6aRGFllN97+ara1vPd4XkRSv63hpfJwrgdQ8uEs QOxA6+W++zC5c9Iaux+tJ7hIPcXRKRWfAT2kmAI1VSGv14tteHHprZmc70DT8+M2qr17 7VsRjSTybTgBEDnZVSj3vjxbe074cxKzHMhbBAaMci/67e/nIj8tktsgxT0tTSoxzB4f qaTvojeBNq+zcJ5hgFOdTcV5/fELhQafRCs9B4s8pI69iyGkxK/PbcI9AXqfvYSw3gff 32qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IFT1ECD4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hv15-20020a17090760cf00b0079800b81747si28047741ejc.735.2023.01.03.01.41.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 01:41:37 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IFT1ECD4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A36513888C55 for ; Tue, 3 Jan 2023 09:39:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A36513888C55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672738744; bh=WVzLZ8s4mD4o6sdIBQ62XwD+TjyzkRQw0nvr0ZNzZZ8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=IFT1ECD4ME50hgGFJ5kKmdn5fKC/2d2syY5wGioD9bS8097JIbFCCRji5CBgK3s0X t98qM8PCMrw2Sux/00s++TvRJF31XlADgeQvXqX3nux513o/SUJ8COUP2pqL4dBv7w hQBV4zghwb3MAgXPxPAFjMU5oR773mH0/d+51BVw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id C2122385781A for ; Tue, 3 Jan 2023 09:35:37 +0000 (GMT) Received: by mail-wm1-x330.google.com with SMTP id m26-20020a05600c3b1a00b003d9811fcaafso16099137wms.5 for ; Tue, 03 Jan 2023 01:35:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WVzLZ8s4mD4o6sdIBQ62XwD+TjyzkRQw0nvr0ZNzZZ8=; b=vxLlGRMxqR3N/MZ9Gy/35yH4FwxG1b/QHFMQY9kEutNARpbXg2adu6ljyYy7fST3Kj Q9UALzMX5Gtuy4qvjUuuH/HTYfkXDaBPc7pUGU+C54zYkX48kDPHrLUDLJulaqxQ7hVz dOAtiDFQfAP3t6Erx9KRB57RJ770TwamTV8bzVkVynMkN7CKAorGHUzbL9PdsMVadhyS HoWrhV188HIdREFWttWOBSvXMJtwjYVPOpfN8RCNe9UOl3yGUIHmxw2mjGrTZ0MmTX/9 mHXe3v8RynUbDDvYj02hQACyw1yC18sp2GyhKC/SXeokN5fpLDt9Rn0nuyy2jj4EvnUq 5Glw== X-Gm-Message-State: AFqh2ko/gDc6mRIGLac7eahjVnG4yQZioRUT5d85Pfe47V7g47yVz2wZ CNp+tHxd85o7+9+9RaAT6NaRYIu+xE/AgK+CgnQ= X-Received: by 2002:a05:600c:1f18:b0:3cf:5583:8b3f with SMTP id bd24-20020a05600c1f1800b003cf55838b3fmr29683813wmb.20.1672738536647; Tue, 03 Jan 2023 01:35:36 -0800 (PST) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id u13-20020a05600c19cd00b003d1d5a83b2esm48656116wmq.35.2023.01.03.01.35.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 01:35:36 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Make Sem_Util.Is_Aliased_View predicate more robust Date: Tue, 3 Jan 2023 10:35:34 +0100 Message-Id: <20230103093534.76368-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753993861911894526?= X-GMAIL-MSGID: =?utf-8?q?1753993861911894526?= From: Eric Botcazou 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. Tested on x86_64-pc-linux-gnu, committed on master. --- 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