From patchwork Mon Sep 5 07:26:04 2022 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: 978 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp58651wrt; Mon, 5 Sep 2022 00:36:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Ps7FbcqVJoYjfzXejR8E/1emTQFk9e/mm6jzrrBVONdH4WMMCjG8Qp5RTpvsmGCJvmZgU X-Received: by 2002:a05:6402:2789:b0:440:44b6:849b with SMTP id b9-20020a056402278900b0044044b6849bmr43694161ede.387.1662363374404; Mon, 05 Sep 2022 00:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662363374; cv=none; d=google.com; s=arc-20160816; b=kWwZk3TzD4grxtrKaTF5TyXZ3dSyvLBwNvx6pwVM2SwXp/c6RsBpSm3vqn9F8uxDTr /Chj09MbT9l+ja9dL7akTNkPsnWeZLb1FreXSQdJcUFtgaxOIqTtx41P+09ObvJTm3Gh FvJJd2F5SKKNzZzW+0hGemlvRV827wC9y9G1mmPVwo/EAG8WTHQBn+Mt1P7172W7TAmP lfubUrq+qcarNiGo0bu9wBq4y8G1RmxPQN6WofoEeYznaJzSsrlUHd5L/u9CZnecZiJS PKqvQJ4RY7bPgiVGLU+WGPVMp+N+lx2lCN0umwLPO5AAI2obhXigKMQlqv5SFQb+QyZd Wkew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=9iLeI3b3BYwza9IrwSP24Z9PdM9CkHlnJBFpiExGt+s=; b=rHRHaKiAJEanby6RFoYFZUcrZgVO9iarPNcdoTPTKIAA0ztAocmtusZr8Lmflhdyuz PgxYOxBp9XWrS+WkXdCSK8xO57mUS4y9EOjopmBPq88pQw7PSm/M6cuFOLm4yOmAV06J ffiG8lOI+LuSY6hr066J7uTJoLyY6J1mTn2TlzrXph4rnfgpKBoC7HuUpS3OZd08WRFI qw/Rpo3+60M5pTPKSec8LrOTvjFknol9RhPOxCLd+WadQR9ntyac/7cvFYOK0MTiHV+8 YREp5671cdKMVj2jwl4JWwM314/c+DBrYJn6FaXcvT9Gmoa5oKsrSeV4lyhqAoEuCnzK LidQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=y3Jc8vuR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z13-20020a056402274d00b00447ebf62410si6709894edd.2.2022.09.05.00.36.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:36:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=y3Jc8vuR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 2A85D382DB1E for ; Mon, 5 Sep 2022 07:30:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A85D382DB1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662363051; bh=9iLeI3b3BYwza9IrwSP24Z9PdM9CkHlnJBFpiExGt+s=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=y3Jc8vuRcJp6yO3Brn2C7Ncf9kKemPCJzbywT4Dov/ieXFatFC9fdZz3WIy0mfZac t5ICzS4hTFRT8O4IBA31pyRGH843nfm39M8JCUl0ytmyHxvzZt7K4HFhI1hvg4U4jT +G6ifx0k9KdKw5y3NIx/UJ2EmUrZWtFWzvui2QqM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 6068F385C301 for ; Mon, 5 Sep 2022 07:26:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6068F385C301 Received: by mail-wr1-x431.google.com with SMTP id w5so10049533wrn.12 for ; Mon, 05 Sep 2022 00:26:06 -0700 (PDT) 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=9iLeI3b3BYwza9IrwSP24Z9PdM9CkHlnJBFpiExGt+s=; b=y9WvBthq3HMa88w9iIXlkDqQfe8j4i8FQjLDDqkFrFUiwOJknS2Ephm4YirWqHKlHj jWSwY21/w7kzfBEEIiTpWW3648JRs0G5/E7FuRaUMFCDTxlKxOQC0DvwaFq8lqURbecH phWz0jQL879xV9RbydIoo+Ug6icRnE3Bzv9UXLBzim7HLrubWgyKwbPlt7g9f2GwQ2G3 EKoszrgNmlqIASH1GweP/d7W7zbWRjZeFPY8vF5mHW+cUD0ARaNW75fg4hfvzaeY/cE/ Afk5bvhvOFNyCN5tEJPK/7xQb9UyK+LgB7E1lctKOL08b+yN56SqVf0g8g5Bqjg76hWs PWYQ== X-Gm-Message-State: ACgBeo298xagLsLPNMdVP7FvmN4hLjB4uRyLEnUSto9RCYE59W6Ty4zt 4rixutkjvtSrHIiwV8rQtmJAg+vhVYzjwg== X-Received: by 2002:a5d:4e11:0:b0:225:8678:fa7c with SMTP id p17-20020a5d4e11000000b002258678fa7cmr24086562wrt.712.1662362766032; Mon, 05 Sep 2022 00:26:06 -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 k2-20020a5d6d42000000b00226f0a00348sm7949909wri.111.2022.09.05.00.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:26:05 -0700 (PDT) Date: Mon, 5 Sep 2022 09:26:04 +0200 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix double identifiers in iterated component association Message-ID: <20220905072604.GA1174699@poulhies-Precision-5550> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.6 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 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: Marc =?iso-8859-1?q?Poulhi=E8s?= Cc: Piotr Trojanek 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?1743114337690926040?= X-GMAIL-MSGID: =?utf-8?q?1743114337690926040?= The iterated_component_association grammar construct appears in Ada RM in two syntactic forms: with iterator_specification and with defining_identifier. This is now properly reflected in the GNAT AST, while previously we had two defining_identifiers regardless of the syntactic form. Cleanup related to handling of iterated_component_association in SPARK. Behavior of the compiler itself should not be affected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_aggr.adb (Two_Pass_Aggregate_Expansion): Expand iterated component association with an unanalyzed copy of iterated expression. The previous code worked only because the expanded loop used both an analyzed copy of the iterator_specification and an analyzed copy of the iterated expression. Now the iterated expression is reanalyzed in the context of the expanded loop. * par-ch4.adb (Build_Iterated_Component_Association): Don't set defining identifier when iterator specification is present. * sem_aggr.adb (Resolve_Iterated_Association): Pick index name from the iterator specification. * sem_elab.adb (Traverse_Potential_Scenario): Handle iterated element association just like iterated component association. Not strictly part of this fix, but still worth for the completeness. * sem_res.adb (Resolve): Pick index name from the iterator specification, when present. * sem_util.adb (Traverse_More): For completeness, just like the change in Traverse_Potential_Scenario. * sinfo.ads (ITERATED_COMPONENT_ASSOCIATION): Fix and complete description. (ITERATED_ELEMENT_ASSOCIATION): Likewise. diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -6536,7 +6536,7 @@ package body Exp_Aggr is Prefix => New_Occurrence_Of (TmpE, Loc), Expressions => New_List (New_Occurrence_Of (Index_Id, Loc))), - Expression => New_Copy_Tree (Expression (Assoc))); + Expression => Copy_Separate_Tree (Expression (Assoc))); -- Advance index position for insertion. @@ -7500,11 +7500,11 @@ package body Exp_Aggr is -- Iterated_Component_Association. - Loop_Id := - Make_Defining_Identifier (Loc, - Chars => Chars (Defining_Identifier (Comp))); - if Present (Iterator_Specification (Comp)) then + Loop_Id := + Make_Defining_Identifier (Loc, + Chars => Chars (Defining_Identifier + (Iterator_Specification (Comp)))); L_Iteration_Scheme := Make_Iteration_Scheme (Loc, Iterator_Specification => Iterator_Specification (Comp)); @@ -7513,6 +7513,9 @@ package body Exp_Aggr is -- Loop_Parameter_Specification is parsed with a choice list. -- where the range is the first (and only) choice. + Loop_Id := + Make_Defining_Identifier (Loc, + Chars => Chars (Defining_Identifier (Comp))); L_Range := Relocate_Node (First (Discrete_Choices (Comp))); L_Iteration_Scheme := diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb --- a/gcc/ada/par-ch4.adb +++ b/gcc/ada/par-ch4.adb @@ -3554,7 +3554,6 @@ package body Ch4 is when Tok_Of => Restore_Scan_State (State); Scan; -- past OF - Set_Defining_Identifier (Assoc_Node, Id); Iter_Spec := P_Iterator_Specification (Id); Set_Iterator_Specification (Assoc_Node, Iter_Spec); 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 @@ -3053,7 +3053,8 @@ package body Sem_Aggr is elsif Present (Iterator_Specification (Comp)) then Copy := Copy_Separate_Tree (Iterator_Specification (Comp)); - Id_Name := Chars (Defining_Identifier (Comp)); + Id_Name := + Chars (Defining_Identifier (Iterator_Specification (Comp))); Analyze (Copy); Typ := Etype (Defining_Identifier (Copy)); diff --git a/gcc/ada/sem_elab.adb b/gcc/ada/sem_elab.adb --- a/gcc/ada/sem_elab.adb +++ b/gcc/ada/sem_elab.adb @@ -3339,7 +3339,9 @@ package body Sem_Elab is Traverse_List (Else_Actions (Scen)); elsif Nkind (Scen) in - N_Component_Association | N_Iterated_Component_Association + N_Component_Association + | N_Iterated_Component_Association + | N_Iterated_Element_Association then Traverse_List (Loop_Actions (Scen)); diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -3163,9 +3163,21 @@ package body Sem_Res is = N_Iterated_Component_Association and then Is_Boolean_Type (Typ) then - Error_Msg_N -- CODEFIX - ("missing ALL or SOME in quantified expression", - Defining_Identifier (First (Component_Associations (N)))); + if Present + (Iterator_Specification + (First (Component_Associations (N)))) + then + Error_Msg_N -- CODEFIX + ("missing ALL or SOME in quantified expression", + Defining_Identifier + (Iterator_Specification + (First (Component_Associations (N))))); + else + Error_Msg_N -- CODEFIX + ("missing ALL or SOME in quantified expression", + Defining_Identifier + (First (Component_Associations (N)))); + end if; -- For an operator with no interpretation, check whether -- one of its operands may be a user-defined literal. 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 @@ -29500,6 +29500,9 @@ package body Sem_Util is when N_Iterated_Component_Association => Traverse_More (Loop_Actions (Node), Result); + when N_Iterated_Element_Association => + Traverse_More (Loop_Actions (Node), Result); + when N_Iteration_Scheme => Traverse_More (Condition_Actions (Node), Result); diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads --- a/gcc/ada/sinfo.ads +++ b/gcc/ada/sinfo.ads @@ -4183,11 +4183,15 @@ package Sinfo is -- ITERATED_COMPONENT_ASSOCIATION ::= -- for DEFINING_IDENTIFIER in DISCRETE_CHOICE_LIST => EXPRESSION + -- for ITERATOR_SPECIFICATION => EXPRESSION + + -- At most one of (Defining_Identifier, Iterator_Specification) + -- is present at a time, in which case the other one is empty. -- N_Iterated_Component_Association -- Sloc points to FOR -- Defining_Identifier - -- Iterator_Specification (set to Empty if no Iterator_Spec) + -- Iterator_Specification -- Expression -- Discrete_Choices -- Loop_Actions @@ -4207,9 +4211,13 @@ package Sinfo is -- Etype --------------------------------- - -- 3.4.5 Comtainer_Aggregates -- + -- 3.4.5 Container_Aggregates -- --------------------------------- + -- ITERATED_ELEMENT_ASSOCIATION ::= + -- for LOOP_PARAMETER_SPECIFICATION[ use KEY_EXPRESSION] => EXPRESSION + -- | for ITERATOR_SPECIFICATION[ use KEY_EXPRESSION] => EXPRESSION + -- N_Iterated_Element_Association -- Key_Expression -- Iterator_Specification