From patchwork Tue May 30 07:20:29 2023 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: 100577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1994746vqr; Tue, 30 May 2023 00:22:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4nQk2pvS6ZWaa2WVgHrVyFW8M466+YHzdy8EVMpBn1pREmf9oD0J3Fiqiz2XEImf/hEUw3 X-Received: by 2002:a17:907:930d:b0:973:92cc:fc78 with SMTP id bu13-20020a170907930d00b0097392ccfc78mr1616654ejc.49.1685431322581; Tue, 30 May 2023 00:22:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685431322; cv=none; d=google.com; s=arc-20160816; b=EjT9/gH/7GxU19CIcIEJMfPSqmJ/PR5SzeGXD5HDLwx4PTNUO9+3XqfeBh1wVXg/0N cw+0dGi3ryz9XMnzIzJv5LWgZ93qRfuFiqi7vFIKVD49PBqmrgbuvrs13bGKwQdf8OVb NkSqc+E2bL+aWCGE+YGEDAAHLW5MMlQKx8N0f5dC33LkdV01dMVi0pschP9snRzlm9+D YPysq9FA7G4zlgQU0UQ4qqveMCMc9IIXctCeOSPBO67DLVxZVESs6m+AXkv1UqJ2kRgS wq54sCVhkO7pyQ7/Bk+SkeKt7BZVJ3vhDlDLDSWtcVvSAeqsPnMQINX69U3s29XUtDtd OEXw== 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=+Ze5PNsleGa/0a2/CG6becORiMUQZQxnOt7DiMzWvCI=; b=NHmwYk35bRSN29Y//0UitcRZRaEmCVXOOGonp12OmfiRhES/kfFqJOyUwAecGfg3um AKUxLUdSEV9aBwSTcARpsfQVq4s6bXIAPv/yaHRqkhVGB7f+TcNTSVsV3J04cyCXFHmp ZTZbP8DhYOm0RG29MI3HPcyeuGHX2Blo8IGKIsVuCd6G/EZCLJkrzjERRCHCXFHKs22u f+C0hAWe2VPOE9tFxKb4h8ln0p2fJypDHIOaH+8pxuLZS8QyUPpBiVmP1mS7kI/Y1AKE V51EreAgcFcVTYxZKKzC7trJVDNJeesOBdDAGquCBSchZhuiE/1gekJSV4O1e4iUb24g aIKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ptxyFBZf; 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 s6-20020a170906500600b00932835201fesi9228918ejj.635.2023.05.30.00.22.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:22:02 -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=ptxyFBZf; 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 B0EB2384F9AD for ; Tue, 30 May 2023 07:21:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0EB2384F9AD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685431280; bh=+Ze5PNsleGa/0a2/CG6becORiMUQZQxnOt7DiMzWvCI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ptxyFBZfm++s/5w/KSJgNJdtQMOLkgjXvj0bbXngQtTLSWNxMSfnF9hFIVxpo85O5 j3g0hKPZfwwTsFsK8NgD7dKhiABscQ64bd/NE97ePfS5zaL9T9HEc2E+ow7AecybDL g04OKzjQDO7drhRTcASVC05MJx5LDTu8Knn/V1fQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 31E213858D20 for ; Tue, 30 May 2023 07:20:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 31E213858D20 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3f60b3f32b4so26566385e9.1 for ; Tue, 30 May 2023 00:20:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685431231; x=1688023231; 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=+Ze5PNsleGa/0a2/CG6becORiMUQZQxnOt7DiMzWvCI=; b=TKejxxXTYrjFTTBN4vYi/dTh6QsVNExjJeU8V6uwZFqcwyhbyUpsG6VrU84uNGyCLW lxqXlVRULsoCW4d9FmpYVURM0W8R8uxdKxswAX3ioQYUUS2rnUSVUz6/Zq4gWnV+QfK/ yHKRCGpS2j+OnSv7TyNsE8R/mDasnklanySU9x98DIMv30rfOEpV8yhe/KlqMvuejvtP m+WjN57PptC7jzk3CsfzHF6wBx2NSm7lOAtv+KQo8UFAiKdbFBqu2Aa4vIswXzy3owBg Kto7rVqt2/eLxV1j+pdD37F0D7jLlVGe8NsgpaefLCrGBREGYnao/AtEwp6YGR5pw82D JGAw== X-Gm-Message-State: AC+VfDxhETgMrVfl8JlANDyLcJHTeYKgydxvNr9P6JtuaWn1KZ/dPA3i pgQfd88XcVWqO+SVl+N5UaYpQPAnAO5KU7fZtIDVEw== X-Received: by 2002:a1c:7502:0:b0:3f4:2973:b8d0 with SMTP id o2-20020a1c7502000000b003f42973b8d0mr863835wmc.2.1685431231607; Tue, 30 May 2023 00:20:31 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:7733:a608:a415:6b2a]) by smtp.gmail.com with ESMTPSA id 24-20020a05600c021800b003f080b2f9f4sm19947816wmi.27.2023.05.30.00.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:20:31 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix visibility error with DIC or Type_Invariant aspect on generic type Date: Tue, 30 May 2023 09:20:29 +0200 Message-Id: <20230530072029.2499524-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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: =?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?1767302834516530126?= X-GMAIL-MSGID: =?utf-8?q?1767302834516530126?= From: Eric Botcazou The compiler fails to capture global references during the analysis of the aspect on the generic type because it analyzes a copy of the expression. gcc/ada/ * exp_util.adb (Build_DIC_Procedure_Body.Add_Own_DIC): When inside a generic unit, preanalyze the expression directly. (Build_Invariant_Procedure_Body.Add_Own_Invariants): Likewise. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_util.adb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index 2582524b1dd..4c4844594d2 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -1853,7 +1853,15 @@ package body Exp_Util is begin pragma Assert (Present (DIC_Expr)); - Expr := New_Copy_Tree (DIC_Expr); + + -- We need to preanalyze the expression itself inside a generic to + -- be able to capture global references present in it. + + if Inside_A_Generic then + Expr := DIC_Expr; + else + Expr := New_Copy_Tree (DIC_Expr); + end if; -- Perform the following substitution: @@ -3111,7 +3119,14 @@ package body Exp_Util is return; end if; - Expr := New_Copy_Tree (Prag_Expr); + -- We need to preanalyze the expression itself inside a generic + -- to be able to capture global references present in it. + + if Inside_A_Generic then + Expr := Prag_Expr; + else + Expr := New_Copy_Tree (Prag_Expr); + end if; -- Substitute all references to type T with references to the -- _object formal parameter.