From patchwork Mon Sep 5 07:26:00 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: 968 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp56980wrt; Mon, 5 Sep 2022 00:30:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR4LkivB0Rk/Gi+eNKnNNxa44ziO82zjUx7EtMwtApYUMEVjgsNx7JkwtINbBBtsKiGKGWD5 X-Received: by 2002:a17:906:7714:b0:74f:f771:4e0 with SMTP id q20-20020a170906771400b0074ff77104e0mr9712051ejm.623.1662363001447; Mon, 05 Sep 2022 00:30:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662363001; cv=none; d=google.com; s=arc-20160816; b=HqYxfXKrjAxUYb/8oqgMZ9jMGo74pwHdOadmIeDXc0KiqtBEQKq1BQ49Flr68p/WbS oyCpfrb+oGEYT6Oj22Q6n9+a2oGdRub1mN2Eb1Myp9QMaWkXgyXlTsH/4Hc08cRDTXSw I1p3EjbCVwJQCBWz3bVWzBlh6cDPVqFaioInt9gW5k/GnGN0oAVxMXeNr6gOQ2EnPf41 0udxP+FEJR/Yj5JhQAe4KnOk9VGhhAgIbUX9NGUzYEMKhF8vnnC0t9T+/N6qeLvGYI8b E9m6t8bekN63O/kdEcu/1FQifJquktCWJstf2vSclUGZoEJaV4g3fV027njLXCQrhaFX GhTQ== 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=zOPisR5PzZeQveDsiRKTVhTUabYhE5urG83N3nxEzAA=; b=vyVWUo+D/g0aCEwmEtXo5iCpJGrllnGV+Grxl1BDtxBKRoOd5BKZSPRC5Pxn8/MARs IpafRLCg3qgVRnKlSic6LEjtAC5j5dTLoRzC6SVujMFXgA/fA1bNK60mtniagZpHlOjp o63KgEwxr0ts5pnJ0v0hdVJmo62yqqgdtgGrIxBc/zfljqk0qb2/fwZNcvUQDc3/THfw KjoQ6GFMaswlR2aEYUzVfh2Io9Jpbbss10Q7YnOr4Bup/Zhf6RXbyC1EyE+UjpJw6kDp yfp7VaJmyUz6gsVOt+hyeALd3dqK7FX1v8U3ci0nev4Iq1TAvDR/LHbTiefmPLfCwV7a DHYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ek3PoW1L; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dn11-20020a17090794cb00b00730bc62507csi7070346ejc.125.2022.09.05.00.30.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:30:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ek3PoW1L; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 330AD385114F for ; Mon, 5 Sep 2022 07:27:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 330AD385114F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662362877; bh=zOPisR5PzZeQveDsiRKTVhTUabYhE5urG83N3nxEzAA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ek3PoW1Luu9SD4ocF3mCzSFC3rmA5dnhCwnaTbS+SLc2KxEuEo3llEfbNATkyzNoj 3srcDku1oVOQRIQm04FCgqkWtsSyeOJmm8ll/HwvVzDPWYXa5/fxyf10Xk6BYsVoUl jXUGz65itpj9JIna/6Hpum3ewra+b/JvZapEgK1Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 Received: by mail-wr1-x430.google.com with SMTP id bz13so6669044wrb.2 for ; Mon, 05 Sep 2022 00:26:02 -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=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-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 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix resolution of iterated component association Message-ID: <20220905072600.GA1174639@poulhies-Precision-5550> MIME-Version: 1.0 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 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?1743113946585010870?= X-GMAIL-MSGID: =?utf-8?q?1743113946585010870?= 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. 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