From patchwork Tue Nov 8 08:42:44 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: 16948 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2573314wru; Tue, 8 Nov 2022 00:54:23 -0800 (PST) X-Google-Smtp-Source: AMsMyM4tDhz977/zKH+ulWn2KQGbw193UDV0Wo8gRIwlCdDeX5cXXysHC/Vw0h9nvdq9VfkAhP/k X-Received: by 2002:a17:906:6a27:b0:7a6:c537:ba4 with SMTP id qw39-20020a1709066a2700b007a6c5370ba4mr50009014ejc.517.1667897662966; Tue, 08 Nov 2022 00:54:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667897662; cv=none; d=google.com; s=arc-20160816; b=FocFjWAJbbcY75nBlbP93f5wMbpqixu4Ob8lwaTmnaqc/uGKZuPhQZ9xBS6hQpa/B0 Q4ghbmrQws9xG4IsVsGEabChUy8U8uU6A1ch8RK1jjk5QoiDkCMiH82wVT5dNjiWjQJb pcDIyrN7Mqs3bamu9SVb5f6iteT5/sp77bxKgybykhf09h+c91SORB3is3C7p38NK4Jt 1vV16Doa2mhCD8+6ddAG+hHCxnIFSXGpaYT8anRALFYHEa5VtJ4oE3QMXTbRSvq6pk4j Oasq4s5v/0z0GXUkkkJnE65kSFp5lecKgE1T7pRDaii4jntEb/bYTJ/PEJxVYe8Eaq2A fV+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=IlW00jTComnDqDzNFY4L0EtoAeEWxDDwQQDq6Hujp7Y=; b=LSTQrHcMPEtvtqIJJxsNzHdrm2nJsCTBU48TfucYQJkahidHTYdoPQocb5/b0TkLlG tEJhF85f+BRJ7L59f9k3J58hh7/BqrDYp1sh93o5fgaN+rRCU8AUl5eBtGIpCvGrW2RB gz4z+YCDZxJGVESbaSm9QbUHPvx7VhPRB5dsz3YK9QGdJ1R6+zNnYPUgsfwugmJcZ5s7 QbT8YwlIGcPwZiZsnMHc00ZaltS6FLI1HLo41s8pq1f6xb/LK/YW6QjFK3StAHJjDCtD XQWx1PEq8kBlI55v6kQU2lWHsbTVFnW9yLOwiRrlGlLSu4Ma2CoiRIhCpCpiaOHfr4UB 8vAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sYRQjAzF; 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 hr14-20020a1709073f8e00b0078d878d8fb7si12414037ejc.920.2022.11.08.00.54.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 00:54:22 -0800 (PST) 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=sYRQjAzF; 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 71FA93829BFA for ; Tue, 8 Nov 2022 08:50:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71FA93829BFA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667897439; bh=IlW00jTComnDqDzNFY4L0EtoAeEWxDDwQQDq6Hujp7Y=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=sYRQjAzFuUDdJziW8qthm5xqwvod7bQ9moHLmMT7p4d5MXz8GHO21hJYgg4hmnJFW YMml13T8WEDYH8HflQXNpFl+y0kXy7D7lg31rDtqgI4cmmJUF7LcxAo+EtXSTyMkwP V010P2HdMbvMwFujEwtrui3BX9x7Fz4J6rVESNHo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 487DF385740F for ; Tue, 8 Nov 2022 08:42:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 487DF385740F Received: by mail-wr1-x436.google.com with SMTP id g12so19736888wrs.10 for ; Tue, 08 Nov 2022 00:42:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IlW00jTComnDqDzNFY4L0EtoAeEWxDDwQQDq6Hujp7Y=; b=jP2nu9R2lOUm+nabvE4l+B8xD/xhcgpRtRkoPOWdh4ByesMGbQyiSGcJDMBnifpfZl FllV9uEt0tDf6FtIEEAE0PIdCIbrhFUwKfBwciUEzSDC8AAgVtp2srQwLH2VI90Lnfit 36cdCoTyL9mPHl630oiA+NsVGKgBWHBTvs2s8DgWdTu6l0Jc0w/vAMipex9PfGErNJf0 VJXpm0KWNzuS7bQuoInXYSpsLcGuy7L1LqVwz3caa4DIvA4h22IXsNhwi/8KqFeQHkfc dkA+cbOrZG4iCk5RUxjmkInqlwMvQGwRf4qAV883BuwVtpqkugMMoQNdJAPn8FtqsH3V CCzg== X-Gm-Message-State: ACrzQf0ZSpGOsjCMwG67u4XoRTyHBdRjWB85AqAOWLGF5rc2gofvLwej R8nW9zuMZroVXQZTN9qDqoPUZSo1BqULoQ== X-Received: by 2002:a5d:4048:0:b0:236:659b:260e with SMTP id w8-20020a5d4048000000b00236659b260emr33127538wrp.445.1667896968114; Tue, 08 Nov 2022 00:42:48 -0800 (PST) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id v2-20020adfedc2000000b00228daaa84aesm9558147wro.25.2022.11.08.00.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 00:42:47 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [COMMITTED] ada: Improve handling of declare expressions in deferred-freezing contexts Date: Tue, 8 Nov 2022 09:42:44 +0100 Message-Id: <20221108084244.301581-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.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 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: =?utf-8?q?Marc_Poulhi=C3=A8s?= 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?1748917459453385985?= X-GMAIL-MSGID: =?utf-8?q?1748917459453385985?= From: Steve Baird In some cases where a declare expression occurs in a deferred-freezing context (e.g., within the default value for a discriminant or for a formal parameter, or within the expression of an expression function), the compiler generates a bugbox. gcc/ada/ * sem_ch3.adb (Analyze_Object_Declaration): Do not perform expansion actions if In_Spec_Expression is true. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch3.adb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 8f4e9f80eb8..95ffbe00ba4 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -4721,6 +4721,26 @@ package body Sem_Ch3 is Expand_Sliding_Conversion (E, T); end if; + if In_Spec_Expression and then In_Declare_Expr > 0 then + -- It is too early to be doing expansion-ish things, + -- so exit early. But we have to set Ekind (Id) now so + -- that subsequent uses of this entity are not rejected + -- via the same mechanism that (correctly) rejects + -- "X : Integer := X;". + + if Constant_Present (N) then + Mutate_Ekind (Id, E_Constant); + Set_Is_True_Constant (Id); + else + Mutate_Ekind (Id, E_Variable); + if Present (E) then + Set_Has_Initial_Value (Id); + end if; + end if; + + goto Leave; + end if; + Expand_Subtype_From_Expr (N => N, Unc_Type => T,