From patchwork Mon May 20 07:48:56 2024 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: 90469 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8708E3858C35 for ; Mon, 20 May 2024 08:03:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 228683858D33 for ; Mon, 20 May 2024 07:49:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 228683858D33 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 228683858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191384; cv=none; b=VIz9Wpa7K1id2EFuCM55yTHgBxLszeK45M+OVMKJVQahRCpm2uCyHWBQQBATjDBTv2W2XRq2ThH2Cq2ewkNfURQG6Xc8MjndjM3XMzbHaui9l3Fdnhta6CLHCVVNVG+bvUzhZvyFiYEBHoVL3lvO4MWudJROQBKyP3N5FoZ9rS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191384; c=relaxed/simple; bh=va6izUnp+QtEIyDxE/1XbPPBLEq0jVPrL5kaTCgtkGo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xLqVnbQ7uFc75Sao7yrkF+qtVLjGTAQRlR1lyIKHbivGHzNy03oQ9eCstp8NTGi3j7FgwQvP2Lgq45Cxr4xcamQ2D7K33Ac9sLhLwKXudtG/Lm2vOTZJM8oJd+lmuM1+Be7nRwnuAqsOcWnK5td8trSFsSYNBnJssIqNA3ve2g8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-41fd5dc04f0so13004615e9.0 for ; Mon, 20 May 2024 00:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1716191375; x=1716796175; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VK8kGZq2fvD06owPMIYiYUvlDP2mk/H7F0GqY8udCvo=; b=NpW8Ueos3BHC/bysr/UtC7I45svIzXmE0PigHozFKnseRQ7ApnvrAkLRW2mux6PJgR ONthzBcsqcg0MHZMUI5YAu8wXs1LCpDfx6BLum1emR5/pDv3u+5C0KDfOQ7wQQQIrxOe 2dSn7tUc7Mu6y6gUNCmfCEba22QlnsHRwNlbB82t7Kw+SojnzyGOCmulMtK4LyyZRQGU mvuyrpT59vXM5wuKlcv+mtZ3JXnUKJDAI4bILdZyq6ibCdYgfUlK+h7pr1OhoPTB3zck M5fSDSC5yh07YDbOiLcJTIEkYMA/sVEylSrKQ8g1Klnn1AVO1jGGeEkCc5ZBC5gZ2PKW lL/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716191375; x=1716796175; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VK8kGZq2fvD06owPMIYiYUvlDP2mk/H7F0GqY8udCvo=; b=r2Ux7xiaKC7lAKIV9Qh4CKIX0RS52KLhGldbbWWB9xmJ+XDE1vewa5pHNGsNIYHPer 2pOFOL6ILLnZKjGMESHQsN+T3R0QfyftYXzZRIvcSdjp5ydQeq3xA+gk47ahOkheIpCM rLELBiBzZ/3KiQwCmH+1ojhWOasUiRoYqpLEk3K+2ipFzlZlTkNUaQQ/N0OQ7RXBjBiG XTYYo/lmEnZvIrgWdOBs6IvJ+bNAlImod8YheF4vctkSJ6KQECzhfq0h3j9bOq26A4n9 HcZHUg8Tzg8temkDNuABi0zy/Q4D1fehPvFM5q0idQufa352Uozzxzug5W/Qx3LqRxVp ZPIg== X-Gm-Message-State: AOJu0Yz+KWWwUhoOn82DNVDDLwysB/9eYeOUy8gx0tEJGsUp7F69SGlg KMUAf67B+brlaWHGibMGGiLgeyYWTdwfRgE7CHaa2Mn1NXd1JR+SC7DVfdfRHkKnsQChvFUNDg8 = X-Google-Smtp-Source: AGHT+IEFWWIstQ12qqolnIyi5A66V2cLkMMNy8kQp+D4h8Pbam8/AmWtLHFg2CBB47APrrHq2mEDVw== X-Received: by 2002:a05:600c:1c29:b0:41b:39a3:cbf2 with SMTP id 5b1f17b1804b1-41fea931b48mr331414975e9.4.1716191374766; Mon, 20 May 2024 00:49:34 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:de37:8b1c:1f33:2610]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41f88111033sm446892175e9.34.2024.05.20.00.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 00:49:34 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [COMMITTED 30/30] ada: Allow 'others' in formal packages with overloaded formals Date: Mon, 20 May 2024 09:48:56 +0200 Message-ID: <20240520074858.222435-30-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240520074858.222435-1-poulhies@adacore.com> References: <20240520074858.222435-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org From: Bob Duff If a generic package has two or more generic formal parameters with the same defining name (which can happen only for formal subprograms), then RM-12.7(4.1/3) disallows named associations in a corresponding formal package. This is not intended to cover "others => <>". This patch allows "others => <>" even when it applies to such formals. Previously, the compiler incorrectly gave an error. Minor related cleanups involving type Text_Ptr. gcc/ada/ * sem_ch12.adb: Misc cleanups and comment fixes. (Check_Overloaded_Formal_Subprogram): Remove the Others_Choice error message. (Others_Choice): Remove this variable; no longer needed. * types.ads (Text_Ptr): Add a range constraint limiting the subtype to values that are actually used. This has the advantage that when the compiler is compiled with validity checks, uninitialized values of subtypes Text_Ptr and Source_Ptr will be caught. * sinput.ads (Sloc_Adjust): Use the base subtype; this is used as an offset, so we need to allow arbitrary negative values. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch12.adb | 27 ++++++++++----------------- gcc/ada/sinput.ads | 2 +- gcc/ada/types.ads | 7 +++---- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index 4ceddda2052..9919cda6340 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -1130,10 +1130,11 @@ package body Sem_Ch12 is Saved_Formal : Node_Id; Default_Formals : constant List_Id := New_List; - -- If an Others_Choice is present, some of the formals may be defaulted. - -- To simplify the treatment of visibility in an instance, we introduce - -- individual defaults for each such formal. These defaults are - -- appended to the list of associations and replace the Others_Choice. + -- If an N_Others_Choice is present, some of the formals may be + -- defaulted. To simplify the treatment of visibility in an instance, + -- we introduce individual defaults for each such formal. These + -- defaults are appended to the list of associations and replace the + -- N_Others_Choice. Found_Assoc : Node_Id; -- Association for the current formal being match. Empty if there are @@ -1145,9 +1146,8 @@ package body Sem_Ch12 is Num_Actuals : Nat := 0; Others_Present : Boolean := False; - Others_Choice : Node_Id := Empty; -- In Ada 2005, indicates partial parameterization of a formal - -- package. As usual an other association must be last in the list. + -- package. As usual an 'others' association must be last in the list. procedure Build_Subprogram_Wrappers; -- Ada 2022: AI12-0272 introduces pre/postconditions for formal @@ -1195,7 +1195,7 @@ package body Sem_Ch12 is procedure Process_Default (Formal : Node_Id); -- Add a copy of the declaration of a generic formal to the list of -- associations, and add an explicit box association for its entity - -- if there is none yet, and the default comes from an Others_Choice. + -- if there is none yet, and the default comes from an N_Others_Choice. function Renames_Standard_Subprogram (Subp : Entity_Id) return Boolean; -- Determine whether Subp renames one of the subprograms defined in the @@ -1314,14 +1314,8 @@ package body Sem_Ch12 is Error_Msg_N ("named association not allowed for overloaded formal", Found_Assoc); - - else - Error_Msg_N - ("named association not allowed for overloaded formal", - Others_Choice); + Abandon_Instantiation (Instantiation_Node); end if; - - Abandon_Instantiation (Instantiation_Node); end if; Next (Temp_Formal); @@ -1592,7 +1586,7 @@ package body Sem_Ch12 is Append (Decl, Assoc_List); - if No (Found_Assoc) then + if No (Found_Assoc) then -- i.e. 'others' Default := Make_Generic_Association (Loc, Selector_Name => @@ -1686,7 +1680,6 @@ package body Sem_Ch12 is while Present (Actual) loop if Nkind (Actual) = N_Others_Choice then Others_Present := True; - Others_Choice := Actual; if Present (Next (Actual)) then Error_Msg_N ("OTHERS must be last association", Actual); @@ -2311,7 +2304,7 @@ package body Sem_Ch12 is -- If this is a formal package, normalize the parameter list by adding -- explicit box associations for the formals that are covered by an - -- Others_Choice. + -- N_Others_Choice. Append_List (Default_Formals, Formals); diff --git a/gcc/ada/sinput.ads b/gcc/ada/sinput.ads index b22314770bd..1045acd3e2d 100644 --- a/gcc/ada/sinput.ads +++ b/gcc/ada/sinput.ads @@ -804,7 +804,7 @@ private -- The following fields are for internal use only (i.e. only in the -- body of Sinput or its children, with no direct access by clients). - Sloc_Adjust : Source_Ptr; + Sloc_Adjust : Source_Ptr'Base; -- can be (very) negative -- A value to be added to Sloc values for this file to reference the -- corresponding lines table. This is zero for the non-instantiation -- case, and set so that the addition references the ultimate template diff --git a/gcc/ada/types.ads b/gcc/ada/types.ads index 8a1d9054261..4fd75d46787 100644 --- a/gcc/ada/types.ads +++ b/gcc/ada/types.ads @@ -145,9 +145,8 @@ package Types is -- standard 32-bit integer as an index value, since we count on all index -- values being the same size. - type Text_Ptr is new Int; - -- Type used for subscripts in text buffer - + type Text_Ptr is new Int range -4 .. Int'Last; + -- -4 .. -1 are special; see constants below type Text_Buffer is array (Text_Ptr range <>) of Character; -- Text buffer used to hold source file or library information file @@ -265,7 +264,7 @@ package Types is -- the location is in System, but we don't know exactly what line. First_Source_Ptr : constant Source_Ptr := 0; - -- Starting source pointer index value for first source program + -- Starting source pointer index value for first source file ------------------------------------- -- Range Definitions for Tree Data --