From patchwork Tue Sep 21 15:26:04 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: 1530764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=Q8QNBO4p; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HDQM70cwLz9sW5 for ; Wed, 22 Sep 2021 01:29:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE8F83858020 for ; Tue, 21 Sep 2021 15:29:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 1DF02385843B for ; Tue, 21 Sep 2021 15:26:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1DF02385843B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x42b.google.com with SMTP id t8so40393080wrq.4 for ; Tue, 21 Sep 2021 08:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=AzdjsI7W7CB6F90nLIg98TSy7QFnAV++YjcYxLsx/Ww=; b=Q8QNBO4pYswjZYskfrzQWQl3Y3H3gxUe5M/TvJDJy4bvxYIjo0ix4TvM9Mi42nGRg3 lsB4esBsUKe0I2DZnxEKDRAdaCSPETWjmTyrvnRUtyDzdoe+ikvQS+dB57vFOEKF9OMA yQfW5FZ4B3YdkK7FkrLK2cGv/1BLuT+eYNujHV2hKgOCvbznhaGzctVUuYB0HcPLm5Hn PvE2aF2iY1uIvdITVN08A9TZjj8R6F5Ou+q+ShgyWG6WvnjtXykipQRKEcBLri+xjIY9 igq3X6PhWOCRm61Z9ruk96MeadqCsAl1jvIhHtqNOUH7839LEwVJGParB7w8hXAco8kA dMOw== 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=AzdjsI7W7CB6F90nLIg98TSy7QFnAV++YjcYxLsx/Ww=; b=YUmwMficOTYvKn3dvLfOSIWfNs4E3+PiV+zE45AzZ+ErmJ2N30QMT74I1/GY+jQgzc /VR3YMgBLSOW1r1gsNGv1HieP8r4cT7M2VOq9kjRzuZIOeo0liWKuMJhc7KpAlp8+RZp Bu8As2j2JjLHIWBcJK/CnAM+WDGddcoRfPaEeR0XDg9gQ9p56XlTLo4k6P20SCmY/3ml koDkD+QZ9WRjDUhfX3o7WyXYnli36xtdJQ+WZhC90ara2SsGXudt9PmaYZo9nqHRlMhw M//0GNXW3SBuZK0u27Qgt0byJF4Z2eym6V/KbuJkMO7g1c+0Espk6s10NRc0E7HbmoXD nCHw== X-Gm-Message-State: AOAM532gueaMt/w1IL33JaMCgWS1YZ3E9RYV6O1ArlU8X4ZhnUVlFjmj J+EaWTavpmkMqw5VV8WjM5Tl782lLOHnjA== X-Google-Smtp-Source: ABdhPJxjQLEck1LSX6KPXUf2gA47cwlENF3EANLfHYb5PzuibEd10aESXDNJ1+4BicO0CSpK+GBo+A== X-Received: by 2002:a5d:64e2:: with SMTP id g2mr32692170wri.20.1632237966187; Tue, 21 Sep 2021 08:26:06 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id l7sm2980539wmp.48.2021.09.21.08.26.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 08:26:05 -0700 (PDT) Date: Tue, 21 Sep 2021 15:26:04 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Enforce legality rule for Predicate_Failure aspect specifications Message-ID: <20210921152604.GA3094581@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, 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: , Cc: Steve Baird Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" If a Predicate_Failure aspect is specified for a type or subtype, Ada requires that either the Static_Predicate aspect or the Dynamic_Predicate aspect must also be specified for that same type or subtype. [The GNAT-defined Predicate aspect can also be used to meet this requirement.] The point is that an aspect inherited from some other source does not meet this requirment. Add enforcement of this legality rule. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch13.adb (Analyze_Aspect_Specifications): Add a new nested function, Directly_Specified, and then use it in the implementation of the required check. 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 @@ -1884,6 +1884,11 @@ package body Sem_Ch13 is -- expression is allowed. Includes checking that the expression -- does not raise Constraint_Error. + function Directly_Specified + (Id : Entity_Id; A : Aspect_Id) return Boolean; + -- Returns True if the given aspect is directly (as opposed to + -- via any form of inheritance) specified for the given entity. + function Make_Aitem_Pragma (Pragma_Argument_Associations : List_Id; Pragma_Name : Name_Id) return Node_Id; @@ -2777,6 +2782,18 @@ package body Sem_Ch13 is end if; end Check_Expr_Is_OK_Static_Expression; + ------------------------ + -- Directly_Specified -- + ------------------------ + + function Directly_Specified + (Id : Entity_Id; A : Aspect_Id) return Boolean + is + Aspect_Spec : constant Node_Id := Find_Aspect (Id, A); + begin + return Present (Aspect_Spec) and then Entity (Aspect_Spec) = Id; + end Directly_Specified; + ----------------------- -- Make_Aitem_Pragma -- ----------------------- @@ -3342,6 +3359,15 @@ package body Sem_Ch13 is ("Predicate_Failure requires previous predicate" & " specification", Aspect); goto Continue; + + elsif not (Directly_Specified (E, Aspect_Dynamic_Predicate) + or else Directly_Specified (E, Aspect_Static_Predicate) + or else Directly_Specified (E, Aspect_Predicate)) + then + Error_Msg_N + ("Predicate_Failure requires accompanying" & + " noninherited predicate specification", Aspect); + goto Continue; end if; -- Construct the pragma