From patchwork Tue Nov 9 09:45:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 47250 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 26A183858018 for ; Tue, 9 Nov 2021 09:53:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26A183858018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636451625; bh=+b4z8x9+D8T3K7Sb89hEP/ejpv/Uv3gXyY0DxxtpQEY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=PeOmbDpy20GM+jsnop/++Frrh5KZJeJcUHpkZFSfV5+BemHeGw/meFju17ZL6Mn5A jL/aMh25KbprJhdbnSgs5+FSSwlgh2g/2WMHVz+W7Z8Orngcv3eXs15ynVvCCfYaP0 HBQK4PoTDeFTXa/XB6MGyTJfGyQTkXHUbeWya5PY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id B5ADA3858C60 for ; Tue, 9 Nov 2021 09:45:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B5ADA3858C60 Received: by mail-lj1-x22a.google.com with SMTP id 207so16938301ljf.10 for ; Tue, 09 Nov 2021 01:45:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=+b4z8x9+D8T3K7Sb89hEP/ejpv/Uv3gXyY0DxxtpQEY=; b=LjwvJSHF5W5be90qFUaejAm/p+mjpqaTpiiG27Uo4mSpXPJOzwXXID/DdkkYvZ+uR+ Z7tGFWX3DzZtXuP5s5AlIcry3JjujZvjuvX1V9tOF6fNocNgrLVxbUNSp24seroD4ChP wuqQh6n753szRZoKlvOatxUGnkFP9u9xAuyxhS8NcKqGQdQM9O8qLlhZhKA/6ExMgxmK DANP7WvONLIwbnV6U8z+xYg+I66E7VawtGkVLtaul50vdEOnsMSfKVOQzxHxV6AqwU3b mMFF+eTaW2mqSL2KVX2Yx0Zzh3wFI2GgzxlckwOov9j5zDwTd3SzEHLhXmxHo7nenOpF Cnyw== X-Gm-Message-State: AOAM530kWAIOYOVnN2KAa5+uWNdQooJFjCdTrSjAreXbcBHAdXKET+kL k4I1DeYjFL2hi7f516T5TKITbTBprn25OA== X-Google-Smtp-Source: ABdhPJy3E9KCWtYiZ/mB0YByEXpEJHQD/RrY3v+xrDYehtfRE3OnA1kU1Rr+/TNDI3wx8BJRsTbJ4w== X-Received: by 2002:a2e:9eca:: with SMTP id h10mr6022658ljk.138.1636451152609; Tue, 09 Nov 2021 01:45:52 -0800 (PST) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id h18sm1776354ljq.51.2021.11.09.01.45.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 01:45:51 -0800 (PST) Date: Tue, 9 Nov 2021 09:45:50 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Errors on globals in expressions of predicate aspects in generic bodies Message-ID: <20211109094550.GA830134@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.0 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Gary Dismukes Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When a predicate aspect is given on a declaration inside of a generic body and the expression of the aspect references entities declared outside of the generic, errors about those entities not being defined can be issued in instantiations of the generic. This happens because the expression of the Predicate pragma created for the aspect is not analyzed before the global references are captured by Save_Global_References. The pragma expression is now analyzed when the declaration is frozen in the generic. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch13.adb (Freeze_Entity_Checks): Analyze the expression of a pragma Predicate associated with an aspect at the freeze point of the type, to ensure that references to globals get saved when the aspect occurs within a generic body. Also, add Aspect_Static_Predicate to the choices of the membership test of the enclosing guard. diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -13162,6 +13162,7 @@ package body Sem_Ch13 is if Get_Aspect_Id (Ritem) in Aspect_CPU | Aspect_Dynamic_Predicate | Aspect_Predicate + | Aspect_Static_Predicate | Aspect_Priority then -- Retrieve the visibility to components and discriminants @@ -13169,6 +13170,34 @@ package body Sem_Ch13 is Push_Type (E); Check_Aspect_At_Freeze_Point (Ritem); + + -- In the case of predicate aspects, there will be + -- a corresponding Predicate pragma associated with + -- the aspect, and the expression of the pragma also + -- needs to be analyzed at this point, to ensure that + -- Save_Global_References will capture global refs in + -- expressions that occur in generic bodies, for proper + -- later resolution of the pragma in instantiations. + + if Is_Type (E) + and then Inside_A_Generic + and then Has_Predicates (E) + and then Present (Aspect_Rep_Item (Ritem)) + then + declare + Pragma_Args : constant List_Id := + Pragma_Argument_Associations + (Aspect_Rep_Item (Ritem)); + Pragma_Expr : constant Node_Id := + Expression (Next (First (Pragma_Args))); + begin + if Present (Pragma_Expr) then + Analyze_And_Resolve + (Pragma_Expr, Standard_Boolean); + end if; + end; + end if; + Pop_Type (E); else