From patchwork Mon Sep 5 07:26:18 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: 983 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp59401wrt; Mon, 5 Sep 2022 00:39:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR5IenLYFmPlsR05dnDy72EwIArPAIhlWItZRFCdmt99gFDUOzvnOj/W+jOAaRJWlbm9vybM X-Received: by 2002:a17:906:cc13:b0:73d:d22d:63cd with SMTP id ml19-20020a170906cc1300b0073dd22d63cdmr35338962ejb.741.1662363548774; Mon, 05 Sep 2022 00:39:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662363548; cv=none; d=google.com; s=arc-20160816; b=pJ08iGtLLe+ttwn91e3jp5FXitEv31vr8W4ZchhH76DG3UwrLQrfbWyGk0Va4KHM+O O/oc59R5hYrQUDbo3TAg0sMRFtLQHKDwH8+pkAdvc1sHJgegyyQj8jHub8Jp9dWBNiW4 36TdNeAY/IbupPsm74f0eG9X/ciAvtMyx3nw/0h4VV9pJjnwH2UBVlwPKUg5ZLfWn7zX NWHIv6cfnhcbwpmTbLCd3XdPVJgQad1XDuCK47l4uSLOah6s5xzPbZ+NWE/WTyOD65Kj /Soo3zX5y3DTsgykSE4xEaFxoDEecKkczqv3uHkx9uLrBrrVUADC6zRkK4LrrLaphgtq rHVQ== 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=O8mH5RD4LfDkApG6YMriU0XxjMhNdUQYj9o3bpvHSv4=; b=Ne1Un3EqYoa+nLbifd8op3QiPZqrSBS6XLshFJ3lDBBHDPpI/li5a/nKZVRaBnGpzN /42PnTTakW+sGLP1BeRu7tb7FmV49GE1RvNMPTld/TcOMbQCBO+wdmrmzXun2FAUBVDA QYNUQvC6FLUo8ylFeQm1uACNBLCFUjh+Mi6jd6S2X8IUpTpZSEeXoqY1baef57G1dexU WRkq8JDwg5ta7pAiRNWwwsU7BqXg+RD6PVTuaCSpadl9MZOdGJvYNI0v8ntFpffl5Jxf mrqwvdDXEYgoj2XrOcbvWuuzbTYwTebtZ9DbZ/NAWuKKwgivMuuxW43cW525ilu2jqlR VVtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=k8V86o5N; 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 t21-20020a05640203d500b0044e80c043c7si1648826edw.296.2022.09.05.00.39.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:39:08 -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=k8V86o5N; 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 2BEC338348B3 for ; Mon, 5 Sep 2022 07:32:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BEC338348B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662363160; bh=O8mH5RD4LfDkApG6YMriU0XxjMhNdUQYj9o3bpvHSv4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=k8V86o5N76oeGBbJRQSw+KVpRrfl0TMdgT2HEcbVnGuPXgNMVp2OW8zEjt/Kef3UA DVO3we09AbljQSKxVXMM1TfqsRINIYiIwZoNwjPSjYZE8CGvxcNwOpobBcICBdzpUS rzt1LeOFK07Ctk0RIEjXm6BzYESoeZsMOQ+nfD8A= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id C5CDB3853572 for ; Mon, 5 Sep 2022 07:26:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C5CDB3853572 Received: by mail-wr1-x429.google.com with SMTP id e13so10101533wrm.1 for ; Mon, 05 Sep 2022 00:26:20 -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=O8mH5RD4LfDkApG6YMriU0XxjMhNdUQYj9o3bpvHSv4=; b=NeD/A2w/VWvp2oXr7ND6rr2IN6sNWKY5QtfPjpt7ZGPJrY7vLNillbu1jbVG4GXGXc mpACZPxHjIevKSXRARI80GFQ6XU7/Qhmacwr3R/nAOsDDevoR32f50ocdOgOCcOJDqxh c0uETV3EOY5M7D90qhwbpfd3aKrebcvlwGwAU9kNnrDbawKLdR87kQ7vhqqIUT6Za0mD +ObE3Nzc1wJbmU6QRtX8nYR44BPNjpmmGHVecIEefa6gebOckr21m9Eq0wuPUmfbLDbz EXdbjXa7aaYpPb4SUMt8Rnmq6zNqXZeL4DUFEMSXjxLrQvgKck7r+wTg1dHe8KbN7yq4 2C9Q== X-Gm-Message-State: ACgBeo2NUTp1TlRWw6Jyd3tSXcg/p3sbZKhlWXl/usd9NLSitmGgLz5P l7pnxjiofMnU/0kMtuQrV/eino+h9m1YlQ== X-Received: by 2002:a05:6000:1867:b0:21f:f2cf:74a8 with SMTP id d7-20020a056000186700b0021ff2cf74a8mr23870878wri.344.1662362779640; Mon, 05 Sep 2022 00:26:19 -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 w10-20020a05600c474a00b003a608d69a64sm16577648wmo.21.2022.09.05.00.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:26:19 -0700 (PDT) Date: Mon, 5 Sep 2022 09:26:18 +0200 To: gcc-patches@gcc.gnu.org Subject: [Ada] Move check for null array aggregates to expansion Message-ID: <20220905072618.GA1174903@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?1743114520468895537?= X-GMAIL-MSGID: =?utf-8?q?1743114520468895537?= Despite recent changes to runtime checks for null array aggregates, GNATprove still struggles with N_Raise_Constraint_Error nodes inserted into AST by aggregate resolution. The ultimate fix is to move these checks to expansion (which is disabled in GNATprove mode) and explicitly emit a proof check in the GNATprove backend. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_aggr.adb (Check_Bounds): Move code and comment related to check for null array aggregate from Resolve_Null_Array_Aggregate. * sem_aggr.ads (Is_Null_Aggregate): Move spec from unit body. * sem_aggr.adb (Resolve_Null_Array_Aggregate): Move check to expansion. 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 @@ -5734,7 +5734,8 @@ package body Exp_Aggr is procedure Check_Bounds (Aggr_Bounds_Node, Index_Bounds_Node : Node_Id); -- Checks that the bounds of Aggr_Bounds are within the bounds defined - -- by Index_Bounds. + -- by Index_Bounds. For null array aggregate (Ada 2022) check that the + -- aggregate bounds define a null range. procedure Check_Same_Aggr_Bounds (Sub_Aggr : Node_Id; Dim : Pos); -- Checks that in a multidimensional array aggregate all subaggregates @@ -5850,6 +5851,22 @@ package body Exp_Aggr is Cond : Node_Id := Empty; begin + -- For a null array aggregate check that high bound (i.e., low + -- bound predecessor) exists. Fail if low bound is low bound of + -- base subtype (in all cases, including modular). + + if Is_Null_Aggregate (N) then + Insert_Action (N, + Make_Raise_Constraint_Error (Loc, + Condition => + Make_Op_Eq (Loc, + New_Copy_Tree (Aggr_Bounds.First), + New_Copy_Tree + (Type_Low_Bound (Base_Type (Etype (Ind_Bounds.First))))), + Reason => CE_Range_Check_Failed)); + return; + end if; + -- Generate the following test: -- [constraint_error when 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 @@ -404,10 +404,6 @@ package body Sem_Aggr is -- The bounds of the aggregate itype are cooked up to look reasonable -- (in this particular case the bounds will be 1 .. 2). - function Is_Null_Aggregate (N : Node_Id) return Boolean; - -- Returns True for a "[]" aggregate (an Ada 2022 feature), even after - -- it has been transformed by expansion. Returns False otherwise. - procedure Make_String_Into_Aggregate (N : Node_Id); -- A string literal can appear in a context in which a one dimensional -- array of characters is expected. This procedure simply rewrites the @@ -419,9 +415,6 @@ package body Sem_Aggr is -- is constrained). If the subtype is unconstrained, then the bounds -- are determined in much the same way as the bounds for a null string -- literal with no applicable index constraint. - -- Emit a check that the bounds for each dimension define a null - -- range; no check is emitted if it is statically known that the - -- check would succeed. --------------------------------- -- Delta aggregate processing -- @@ -4102,7 +4095,6 @@ package body Sem_Aggr is Loc : constant Source_Ptr := Sloc (N); Typ : constant Entity_Id := Etype (N); - Check : Node_Id; Index : Node_Id; Lo, Hi : Node_Id; Constr : constant List_Id := New_List; @@ -4127,18 +4119,6 @@ package body Sem_Aggr is Attribute_Name => Name_Pred, Expressions => New_List (New_Copy_Tree (Lo))); - -- Check that high bound (i.e., low bound predecessor) exists. - -- Fail if low bound is low bound of base subtype (in all cases, - -- including modular). - - Check := - Make_Raise_Constraint_Error (Loc, - Condition => - Make_Op_Le (Loc, New_Copy_Tree (Lo), New_Copy_Tree (Hi)), - Reason => CE_Range_Check_Failed); - - Insert_Action (N, Check); - Append (Make_Range (Loc, New_Copy_Tree (Lo), Hi), Constr); Analyze_And_Resolve (Last (Constr), Etype (Index)); diff --git a/gcc/ada/sem_aggr.ads b/gcc/ada/sem_aggr.ads --- a/gcc/ada/sem_aggr.ads +++ b/gcc/ada/sem_aggr.ads @@ -43,6 +43,10 @@ package Sem_Aggr is -- WARNING: There is a matching C declaration of this subprogram in fe.h + function Is_Null_Aggregate (N : Node_Id) return Boolean; + -- Returns True for a "[]" aggregate (an Ada 2022 feature), even after + -- it has been transformed by expansion. Returns False otherwise. + function Is_Null_Array_Aggregate_High_Bound (N : Node_Id) return Boolean; -- Returns True for the high bound of a null array aggregate.