From patchwork Wed Jul 8 14:57:34 2020 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: 1325246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com 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 4B22Vj2FmFz9sRW for ; Thu, 9 Jul 2020 00:58:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 122DC3861968; Wed, 8 Jul 2020 14:57:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id 7B50C3861968 for ; Wed, 8 Jul 2020 14:57:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7B50C3861968 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=derodat@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 3726456101; Wed, 8 Jul 2020 10:57:34 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id vTsce7k7iGEj; Wed, 8 Jul 2020 10:57:34 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 2230856097; Wed, 8 Jul 2020 10:57:34 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 21627114; Wed, 8 Jul 2020 10:57:34 -0400 (EDT) Date: Wed, 8 Jul 2020 10:57:34 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Disallow Predicate_Failure without predicate Message-ID: <20200708145734.GA27518@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Bob Duff Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This patch checks RM-3.2.4(14.2/4), which requires Predicate_Failure to be specified only on a subtype with a previous predicate specification (for Static_Predicate or Dynamic_Predicate). We apply the same rule to the GNAT-specific Predicate aspect. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch13.adb (Predicate_Failure): Check that the type has predicates. Remove the setting of Has_Delayed_Aspects and Freeze_Node, because (if the code is legal) it should have already been done by the predicate aspect. 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 @@ -3120,6 +3120,12 @@ package body Sem_Ch13 is Error_Msg_N ("predicate cannot apply to incomplete view", Aspect); goto Continue; + + elsif not Has_Predicates (E) then + Error_Msg_N + ("Predicate_Failure requires previous predicate" & + " specification", Aspect); + goto Continue; end if; -- Construct the pragma @@ -3132,16 +3138,6 @@ package body Sem_Ch13 is Expression => Relocate_Node (Expr))), Pragma_Name => Name_Predicate_Failure); - -- If the type is private, indicate that its completion - -- has a freeze node, because that is the one that will - -- be visible at freeze time. - - if Is_Private_Type (E) and then Present (Full_View (E)) then - Set_Has_Predicates (Full_View (E)); - Set_Has_Delayed_Aspects (Full_View (E)); - Ensure_Freeze_Node (Full_View (E)); - end if; - -- Case 2b: Aspects corresponding to pragmas with two -- arguments, where the second argument is a local name -- referring to the entity, and the first argument is the