From patchwork Mon Sep 5 07:26:17 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: 988 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp60032wrt; Mon, 5 Sep 2022 00:41:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Gdb74B/kUbDPtFKC1wzxP5PrgrEbS6NBEMvk5wV/VBai1PgybmCGUSr2TbL+yK/KkJ/rC X-Received: by 2002:a17:907:1c12:b0:741:a0bc:bd2c with SMTP id nc18-20020a1709071c1200b00741a0bcbd2cmr22862677ejc.241.1662363697545; Mon, 05 Sep 2022 00:41:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662363697; cv=none; d=google.com; s=arc-20160816; b=OoAQAZ0UE06QFHEge8qfKl5cVwPXo83JarrO5o3TYg78heUESecvNYnKClc+4UYy8a IBUwcuZcglxs2m2X/1i9HHwlvJ4oRjZ8W/JlGR7xsV8m97kkjHRLTHP31co+KYIT+zQr JodljeV6E79OdcI8lG9E7uxGEFRHI7aXkg0uF7eX3gvHbTbJK2FdkD/pbQBiIPdvTT2I 50jG/n6pLsqDIbq/fwoqlluH877qpmBtZI61vFY+lsEI+flBTH/adFj1G+ugetAl16tQ yU5RRIc7Eb7QTDPeL4Qu9GJMrppEIAFW896k8XuysdoIacmkYqzO2XebOuTF/5tM3X8p qG/Q== 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=dt/pc8vKor8QI92/SBLEypTEROnsGMWXnM6a9NovVvw=; b=EUUVfnx47/X4ePZPbUF8xxCEhpo3vvu3NboTerOYuGBl31UCo9Xg8rnu0sCPo827fL Nnd/rqLEJ94IxUpQaykLB4va8TqOtcjwQTetj4mTt1PZDJ3RVvvAVBKUlbh16Kwox/de O11XMk41RrwS4icbqvPyZJr89NyJmlkWDCtj2UskVlciWIG0RkdZ7xsC7brgCNPcrYtY sFHCtNHRbLRpEytt6kkRBoAGe3HSwOwoP9B41WiaQUL6X35l53giLX6AuiT7kNSQ3F3/ IW1MPg7QCjNzkWoCIEkPHxYx/IfFxBGaJZOf6pLLZhtT9z4ipXh9eL9ZV4TqphWllTY9 qr/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZLcyHdzY; 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 x22-20020a170906b09600b0073d71079711si6127915ejy.491.2022.09.05.00.41.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:41:37 -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=ZLcyHdzY; 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 2EBB8385483C for ; Mon, 5 Sep 2022 07:36:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2EBB8385483C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662363396; bh=dt/pc8vKor8QI92/SBLEypTEROnsGMWXnM6a9NovVvw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ZLcyHdzYKc4vwUWmwXqys4pL1Ie4ijN3wwSd1iYFvCFTJIAcaBCW0YejKzdyjzueg P5VwZLw5x9C/waBi4nqMGxEk/5gMbnRADF9oaTskK5DzJvhd0UUi1L0CcWkImXRROu HWwE5LoV35O3sc5nEfSn9Y6KbZhmQasmHdB2DggY= 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 DFE7E385AC30 for ; Mon, 5 Sep 2022 07:26:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DFE7E385AC30 Received: by mail-wr1-x430.google.com with SMTP id e13so10101487wrm.1 for ; Mon, 05 Sep 2022 00:26:18 -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=dt/pc8vKor8QI92/SBLEypTEROnsGMWXnM6a9NovVvw=; b=T/o7RVN/K0TPWJLQj5dqVkwsbkoGoug0A+E+RBLYNiU0EG/SJbIQ8sbiyK8aVgxcxi Ly3Mq6Y+OeFO6etOW65UDkM3RgbTjbm5OuFKOkv4q5MWeI56eGzGBsZvS802i2aywtLi 1Jf6l+Xo5kip70lWqRUZ8CEKjqQUkQfeRomcj5WqH7LB9+zuQeQ0TwtMYgIloikgnvkk c7ZvCjjWkk8wJ1LQbDvNVDeZYUu4yEojoerbTE7GlxLCL6SlZm13a6ngCTAXZvDB9wjp +JvIjaHZJZnyN6JNd7CPtfBW0G85DYsZhVCUKVTSLaKcnWo8XSjgl9+EtWYdTpZ+DdfJ +bcQ== X-Gm-Message-State: ACgBeo0d5x2T6UWFYy2K45fN+pwguXT4kIhZCOLBzFD6Xu4FGR4nlaR1 ga2qsROaX+pnc48si3fFlvqbBJljLv+K+A== X-Received: by 2002:adf:e781:0:b0:228:b44c:d0f7 with SMTP id n1-20020adfe781000000b00228b44cd0f7mr667881wrm.243.1662362778558; Mon, 05 Sep 2022 00:26:18 -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 m11-20020a056000180b00b002287d99b455sm2671297wrh.15.2022.09.05.00.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:26:18 -0700 (PDT) Date: Mon, 5 Sep 2022 09:26:17 +0200 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix inconsistent building of itypes for null array aggregates Message-ID: <20220905072617.GA1174888@poulhies-Precision-5550> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.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, 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?1743114676172636135?= X-GMAIL-MSGID: =?utf-8?q?1743114676172636135?= To analyze Ada 2022 null array aggregates we introduced a dedicated routine and bypassed the code for ordinary array aggregates. However, the types for the array indexes created by this dedicated routine differed from the types created for ordinary array aggregates, i.e. itypes for null array aggregates were associated with the array subtype declaration, while itypes for ordinary array aggregates were associated with the aggregate itself. These differences cause trouble for various routines in GNATprove. This patch reduces the special handling of null array aggregates and reuses the building of itypes for ordinary array aggregates. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_aggr.adb (Array_Aggr_Subtype): Bypass call to Collect_Aggr_Bound with dedicated code for null array aggregates. (Resolve_Array_Aggregate): Remove special handling of null array aggregates. (Resolve_Array_Aggregate): Create bounds, but let Array_Aggr_Subtype create itype entities. 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 @@ -567,7 +567,29 @@ package body Sem_Aggr is end if; Set_Parent (Index_Constraints, N); - Collect_Aggr_Bounds (N, 1); + + -- When resolving a null aggregate we created a list of aggregate bounds + -- for the consecutive dimensions. The bounds for the first dimension + -- are attached as the Aggregate_Bounds of the aggregate node. + + if Is_Null_Aggregate (N) then + declare + This_Range : Node_Id := Aggregate_Bounds (N); + begin + for J in 1 .. Aggr_Dimension loop + Aggr_Range (J) := This_Range; + Next_Index (This_Range); + + -- Remove bounds from the list, so they can be reattached as + -- the First_Index/Next_Index again by the code that also + -- handles non-null aggregates. + + Remove (Aggr_Range (J)); + end loop; + end; + else + Collect_Aggr_Bounds (N, 1); + end if; -- Build the list of constrained indexes of our aggregate itype @@ -1203,9 +1225,6 @@ package body Sem_Aggr is Aggr_Subtyp := Any_Composite; - elsif Is_Null_Aggr then - Aggr_Subtyp := Etype (N); - else Aggr_Subtyp := Array_Aggr_Subtype (N, Typ); end if; @@ -4084,16 +4103,16 @@ package body Sem_Aggr is Typ : constant Entity_Id := Etype (N); Check : Node_Id; - Decl : Node_Id; Index : Node_Id; Lo, Hi : Node_Id; Constr : constant List_Id := New_List; - Subt : constant Entity_Id := - Create_Itype (Ekind => E_Array_Subtype, - Related_Nod => N, - Suffix => 'S'); begin + -- Attach the list of constraints at the location of the aggregate, so + -- the individual constraints can be analyzed. + + Set_Parent (Constr, N); + -- Create a constrained subtype with null dimensions Index := First_Index (Typ); @@ -4120,25 +4139,14 @@ package body Sem_Aggr is Insert_Action (N, Check); - Append (Make_Range (Loc, Lo, Hi), Constr); + Append (Make_Range (Loc, New_Copy_Tree (Lo), Hi), Constr); + Analyze_And_Resolve (Last (Constr), Etype (Index)); Index := Next_Index (Index); end loop; - Decl := Make_Subtype_Declaration (Loc, - Defining_Identifier => Subt, - Subtype_Indication => - Make_Subtype_Indication (Loc, - Subtype_Mark => - New_Occurrence_Of (Base_Type (Typ), Loc), - Constraint => - Make_Index_Or_Discriminant_Constraint (Loc, Constr))); - - Insert_Action (N, Decl); - Analyze (Decl); - Set_Etype (N, Subt); Set_Compile_Time_Known_Aggregate (N); - Set_Aggregate_Bounds (N, New_Copy_Tree (First_Index (Etype (N)))); + Set_Aggregate_Bounds (N, First (Constr)); return True; end Resolve_Null_Array_Aggregate;