From patchwork Mon Jun 21 11:05:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1495071 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G7mws2gQpz9sPf for ; Mon, 21 Jun 2021 21:08:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3D05393C023 for ; Mon, 21 Jun 2021 11:08:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTPS id DF8A2389850C for ; Mon, 21 Jun 2021 11:05:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DF8A2389850C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id CE6BC116486; Mon, 21 Jun 2021 07:05:33 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Nt83dQdkrgY2; Mon, 21 Jun 2021 07:05:33 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id BAFF411646F; Mon, 21 Jun 2021 07:05:33 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id B8BA883; Mon, 21 Jun 2021 07:05:33 -0400 (EDT) Date: Mon, 21 Jun 2021 07:05:33 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix detection of overlapping actuals with renamings Message-ID: <20210621110533.GA41258@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Cc: Piotr Trojanek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Simplify detection of renamings within actuals that denote the same object. This code only needs to take object renamings and shouldn't care about renamings of subprogram, packages or exceptions. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.adb (Is_Object_Renaming): Rename from Is_Renaming; simplify; adapt callers. diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -7262,8 +7262,8 @@ package body Sem_Util is ------------------------- function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is - function Is_Renaming (N : Node_Id) return Boolean; - -- Return true if N names a renaming entity + function Is_Object_Renaming (N : Node_Id) return Boolean; + -- Return true if N names an object renaming entity function Is_Valid_Renaming (N : Node_Id) return Boolean; -- For renamings, return False if the prefix of any dereference within @@ -7271,35 +7271,16 @@ package body Sem_Util is -- renamed object_name contains references to variables or calls on -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3)) - ----------------- - -- Is_Renaming -- - ----------------- + ------------------------ + -- Is_Object_Renaming -- + ------------------------ - function Is_Renaming (N : Node_Id) return Boolean is + function Is_Object_Renaming (N : Node_Id) return Boolean is begin - if not Is_Entity_Name (N) then - return False; - end if; - - case Ekind (Entity (N)) is - when E_Variable | E_Constant => - return Present (Renamed_Object (Entity (N))); - - when E_Exception - | E_Function - | E_Generic_Function - | E_Generic_Package - | E_Generic_Procedure - | E_Operator - | E_Package - | E_Procedure - => - return Present (Renamed_Entity (Entity (N))); - - when others => - return False; - end case; - end Is_Renaming; + return Is_Entity_Name (N) + and then Ekind (Entity (N)) in E_Variable | E_Constant + and then Present (Renamed_Object (Entity (N))); + end Is_Object_Renaming; ----------------------- -- Is_Valid_Renaming -- @@ -7307,7 +7288,7 @@ package body Sem_Util is function Is_Valid_Renaming (N : Node_Id) return Boolean is begin - if Is_Renaming (N) + if Is_Object_Renaming (N) and then not Is_Valid_Renaming (Renamed_Entity (Entity (N))) then return False; @@ -7494,12 +7475,12 @@ package body Sem_Util is -- no references to variables nor calls on nonstatic functions (RM -- 6.4.1(6.11/3)). - elsif Is_Renaming (A1) + elsif Is_Object_Renaming (A1) and then Is_Valid_Renaming (A1) then return Denotes_Same_Object (Renamed_Entity (Entity (A1)), A2); - elsif Is_Renaming (A2) + elsif Is_Object_Renaming (A2) and then Is_Valid_Renaming (A2) then return Denotes_Same_Object (A1, Renamed_Entity (Entity (A2)));