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: 70274 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 589033854E63 for ; Tue, 30 May 2023 07:21:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 589033854E63 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685431264; 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=LpO7D1f62vfT8FEj+f/HcNteuFALD4GAwTcnmLs9eZ7EmLYGroOFr8cE8AO1k+iFn 454daKQ8FmTJTMIvQSTU6//lZRluxKU3YbI/VVsr82m78SxVY5rXZD1FdbRpB64Aev WevwTQIcOFijmtBHRp6AOCsnoOAl6WKolAsWdFEA= 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-Google-Smtp-Source: ACHHUZ7G7X9E2Ty+o/L/mD6RGGhQM8j/B3Acl0aY6hfgXlcbG14L6QcGjRHjBTqp/kPO429eq8blnQ== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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.