From patchwork Tue Jun 15 10:20:52 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: 1492111 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4G44MN3pBSz9sTD for ; Tue, 15 Jun 2021 20:30:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 93BEC399BC14 for ; Tue, 15 Jun 2021 10:30:05 +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 DBC5B398B409 for ; Tue, 15 Jun 2021 10:20:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DBC5B398B409 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 A2B7A117B4C; Tue, 15 Jun 2021 06:20:52 -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 pEe325HktXOS; Tue, 15 Jun 2021 06:20:52 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 73E1B117B31; Tue, 15 Jun 2021 06:20:52 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 72E7C1CA; Tue, 15 Jun 2021 06:20:52 -0400 (EDT) Date: Tue, 15 Jun 2021 06:20:52 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] AI12-0138: Iterators and other nonoverridable aspects Message-ID: <20210615102052.GA3795@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, 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: Ed Schonberg Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This Ada202X AI, as well as AI12-0396 and AI12-0423, clarifies the notion of nonoverridable aspects, as well as the rules for confirming inheritance of such aspects. This patch refines the check for confirming specifications to allow, e.g. renamed discriminants to carry an Implicit_Dereference aspect specification on a type extension. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.adb (Is_Confirming): Separate the handling of Implicit_Dereference, for which no pragma is generated but which is already checked for legality in Sem_Ch13, including renamed discriminants in a derived type. (Is_Confirming, Same_Name): For expanded names, only check matching of selector, because prefix may correspond to original and derived types with different names and/or scopes. Semantic checks on aspect expression have already verified its legality. Add comments regarding possible gaps in RM description of the feature. 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 @@ -15886,18 +15886,32 @@ package body Sem_Util is Aspect_Spec_1, Aspect_Spec_2 : Node_Id) return Boolean is function Names_Match (Nm1, Nm2 : Node_Id) return Boolean; + + ----------------- + -- Names_Match -- + ----------------- + function Names_Match (Nm1, Nm2 : Node_Id) return Boolean is begin if Nkind (Nm1) /= Nkind (Nm2) then return False; + -- This may be too restrictive given that visibility + -- may allow an identifier in one case and an expanded + -- name in the other. end if; case Nkind (Nm1) is when N_Identifier => return Name_Equals (Chars (Nm1), Chars (Nm2)); + when N_Expanded_Name => - return Names_Match (Prefix (Nm1), Prefix (Nm2)) - and then Names_Match (Selector_Name (Nm1), - Selector_Name (Nm2)); + -- An inherited operation has the same name as its + -- ancestor, but they may have different scopes. + -- This may be too permissive for Iterator_Element, which + -- is intended to be identical in parent and derived type. + + return Names_Match (Selector_Name (Nm1), + Selector_Name (Nm2)); + when N_Empty => return True; -- needed for Aggregate aspect checking @@ -15925,8 +15939,7 @@ package body Sem_Util is when Aspect_Default_Iterator | Aspect_Iterator_Element | Aspect_Constant_Indexing - | Aspect_Variable_Indexing - | Aspect_Implicit_Dereference => + | Aspect_Variable_Indexing => declare Item_1 : constant Node_Id := Aspect_Rep_Item (Aspect_Spec_1); Item_2 : constant Node_Id := Aspect_Rep_Item (Aspect_Spec_2); @@ -15942,6 +15955,13 @@ package body Sem_Util is Expression (Item_2)); end; + -- A confirming aspect for Implicit_Derenfence on a derived type + -- has already been checked in Analyze_Aspect_Implicit_Dereference, + -- including the presence of renamed discriminants. + + when Aspect_Implicit_Dereference => + return True; + -- one of a kind when Aspect_Aggregate => declare