From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 072413856940 for ; Mon, 5 Sep 2022 07:26:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 072413856940 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x430.google.com with SMTP id bz13so6669044wrb.2 for ; Mon, 05 Sep 2022 00:26:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date; bh=zOPisR5PzZeQveDsiRKTVhTUabYhE5urG83N3nxEzAA=; b=RK6fvF+JY9Ar9Ym9Xh12YuC8Hbc6Ht30PsrElxwQ3AngIC09nXhULUvqYrz/CWQ9Ui T3Vm/lpFrPrjTyhvhdoo8MBBiKk0c4MCPbaHNxtRHvZrddoB04aL+LTdVMZGnD8PgSQd FocOGKpFluo2b5QOWCMO0e+5jf+6SJ+Ce5JpdjgDEBsXcSE7lM+b4VhwP8EWWbJZbjRz JvKQ6//IEtslTU6Yp4/oR3XAJaeJP8D9WGze2OxNk+JILJaaqK25SIP3yIEUgjsjdFsQ pmHxB4w6KpYSEfHrUOSHCJbN76DHhpNC0p+Nbd3+OapKMmNoJBOTglch6PnWFMjkJK65 05hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=zOPisR5PzZeQveDsiRKTVhTUabYhE5urG83N3nxEzAA=; b=ORkEQj3xfoITAaFn/S0/GsnDb/IqP93xU7V8cfVIaOxfWBJAmGCVfxrcnFdzK7kesT Cbz0wZ8EOw6ZkwZ7r98tiV+skDrIgySpj0/ClHR8f74qv3ePRSbGPTcyON5YykWlxjWF KlBNPRZwZ/zLTjDmlY0QxcwSVDqf2GSr6M8i6F2/0Jz9lkdWKKXxeg8ZQw59rNWdP5Db v4uGmrvArKsls9o22qkEXnSNEHhHUSWu8F22kajNJBmDDWCvp3xc+oo1V1fSdVSmyPKd UJQoFy3Gs+4i7Avvg7S4Ae8gRcfJ000x37jp7K4f/A5hFc/N6buP6fDGoxU0gmzFc8q7 pgqw== X-Gm-Message-State: ACgBeo2ZEwTg3vthdEcz9aYska8bh9UiOFDWXvJ4UeTWBMz+lCwVLVcC 0j022ddR92SSAiX2EeCuzrMPS81h18lgsQ== X-Google-Smtp-Source: AA6agR4SqTt6tj6CYXbeM3qPIz79Lt31HQuNP2ZfrejI1+Z39KId/DJ8HN51IJbgTrMPL08ag1el5w== X-Received: by 2002:adf:e383:0:b0:228:9a53:612b with SMTP id e3-20020adfe383000000b002289a53612bmr1434386wrm.651.1662362761858; Mon, 05 Sep 2022 00:26:01 -0700 (PDT) Received: from poulhies-Precision-5550 (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id k1-20020adff281000000b00223b8168b15sm8060207wro.66.2022.09.05.00.26.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:26:01 -0700 (PDT) Date: Mon, 5 Sep 2022 09:26:00 +0200 From: Marc =?iso-8859-1?Q?Poulhi=E8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [Ada] Fix resolution of iterated component association Message-ID: <20220905072600.GA1174639@poulhies-Precision-5550> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ikeVEW9yuYc//A+q" Content-Disposition: inline X-Spam-Status: No, score=-12.4 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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --ikeVEW9yuYc//A+q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline For iterator specification appearing inside an iterated component association, we just did ad-hoc, incomplete checks and delayed a proper analysis until the iterated component association is expanded into loop (and then reanalyzed). However, when the iterated component association is not expanded, e.g. because we are in semantic checking mode, GNATprove mode or inside a generic, then the AST lacked any processing or error reporting. This is fixed by reusing the existing analysis of iterator specifications, as they also appear in other constructs, e.g. in quantified expressions. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_aggr.adb (Resolve_Iterated_Component_Association): Split processing of cases with and without iterator specification; reuse analysis of iterator specification; improve diagnostics for premature usage of iterator index in discrete choices. --ikeVEW9yuYc//A+q Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb --- a/gcc/ada/sem_aggr.adb +++ b/gcc/ada/sem_aggr.adb @@ -1742,8 +1742,6 @@ package body Sem_Aggr is Loc : constant Source_Ptr := Sloc (N); Id : constant Entity_Id := Defining_Identifier (N); - Id_Typ : Entity_Id := Any_Type; - ----------------------- -- Remove_References -- ----------------------- @@ -1779,37 +1777,29 @@ package body Sem_Aggr is begin Error_Msg_Ada_2022_Feature ("iterated component", Loc); - if Present (Iterator_Specification (N)) then - Analyze (Name (Iterator_Specification (N))); + -- Create a scope in which to introduce an index, to make it visible + -- for the analysis of component expression. - -- We assume that the domain of iteration cannot be overloaded. + Scop := New_Internal_Entity (E_Loop, Current_Scope, Loc, 'L'); + Set_Etype (Scop, Standard_Void_Type); + Set_Parent (Scop, Parent (N)); + Push_Scope (Scop); - declare - Domain : constant Node_Id := Name (Iterator_Specification (N)); - D_Type : constant Entity_Id := Etype (Domain); - Elt : Entity_Id; - begin - if Is_Array_Type (D_Type) then - Id_Typ := Component_Type (D_Type); + -- If there is iterator specification, then its preanalysis will make + -- the index visible. - else - if Has_Aspect (D_Type, Aspect_Iterable) then - Elt := - Get_Iterable_Type_Primitive (D_Type, Name_Element); - if No (Elt) then - Error_Msg_N - ("missing Element primitive for iteration", Domain); - else - Id_Typ := Etype (Elt); - end if; - else - Error_Msg_N ("cannot iterate over", Domain); - end if; - end if; - end; + if Present (Iterator_Specification (N)) then + Preanalyze (Iterator_Specification (N)); + + -- Otherwise, analyze discrete choices and make the index visible else - Id_Typ := Index_Typ; + -- Insert index name into current scope but don't decorate it yet, + -- so that a premature usage of this name in discrete choices will + -- be nicely diagnosed. + + Enter_Name (Id); + Choice := First (Discrete_Choices (N)); while Present (Choice) loop @@ -1835,25 +1825,13 @@ package body Sem_Aggr is Next (Choice); end loop; - end if; - - -- Create a scope in which to introduce an index, which is usually - -- visible in the expression for the component, and needed for its - -- analysis. - Scop := New_Internal_Entity (E_Loop, Current_Scope, Loc, 'L'); - Set_Etype (Scop, Standard_Void_Type); - Set_Parent (Scop, Parent (N)); - Push_Scope (Scop); + -- Decorate the index variable - -- Insert and decorate the index variable in the current scope. - -- The expression has to be analyzed once the index variable is - -- directly visible. - - Enter_Name (Id); - Set_Etype (Id, Id_Typ); - Mutate_Ekind (Id, E_Variable); - Set_Scope (Id, Scop); + Set_Etype (Id, Index_Typ); + Mutate_Ekind (Id, E_Variable); + Set_Scope (Id, Scop); + end if; -- Analyze expression without expansion, to verify legality. -- When generating code, we then remove references to the index --ikeVEW9yuYc//A+q--