From patchwork Wed Dec 1 10:25:57 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: 48342 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 B055D385802E for ; Wed, 1 Dec 2021 10:46:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B055D385802E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638355561; bh=crUkb/7+jleMMiAgeMKM8XHpcMlXx+rapfF+dbVtlTY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=QJ/ob50YIbrGrLRE4qJ07jhb4b9WlOWz8s2kdx46tLhhsp7tP6DXFpTNBSW21eqgN baH5CRREU17ymhWCjGdi1cgRG81ASQ/vkTqc7wCcV/tC+zWvF9s1IzisEyUnibCsqm hvJVNHLx607ugBDN3s6ZWFXRorkDz7NVLAm2yxls= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 0ECFC3858002 for ; Wed, 1 Dec 2021 10:26:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0ECFC3858002 Received: by mail-wr1-x42e.google.com with SMTP id v11so51078666wrw.10 for ; Wed, 01 Dec 2021 02:26:00 -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=crUkb/7+jleMMiAgeMKM8XHpcMlXx+rapfF+dbVtlTY=; b=ucKhPSP4RFbJfjxgs7DzmRWxSnVq9JpWu4zM7xiNugepXJYB7WUQ/alRc+kt3zM3gH /gVQ+UOHe6MRj3q1fe9vLhtUalzBhEpcntTRWmfHDegUrD6GYrb8rLxy6f4k0iX81jlz NS91GZRZ29+ggyspLd+uHXUEtlyHWT1lPiwxSwrrAIrTr1yIvfF0W2o9AtEd90OBPHXy RvMpNN15Pxqw2NeVe0MPu3p6SVckbzcw8GtHaWud2gSnahvyo+55LwRBNG/m/xHp1Mml yWtXgwAgLta+X5GaIIKn60rxFY9oldJoIVvKTSVc49v50spk04+Ff7Nwb/wpxl4oQRmG T6fQ== X-Gm-Message-State: AOAM5333vlSp20yftSy2fE8rozBSzrcU4/JwuenBalH66Q2HWYWxY7yt maa8SElXBXrbzG+v5YpMUcYQ0yLrrF5Qjz3+ X-Google-Smtp-Source: ABdhPJzShbycKJFckD96jyXqCGRs/cyUZuBnXdANP7e8PvTstw3gTaE+3dTopBNq4toExHmtj9Hiug== X-Received: by 2002:a5d:6a8f:: with SMTP id s15mr5629329wru.544.1638354359072; Wed, 01 Dec 2021 02:25:59 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id i17sm668741wmq.48.2021.12.01.02.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 02:25:58 -0800 (PST) Date: Wed, 1 Dec 2021 10:25:57 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Syntax error on "not null procedure" Message-ID: <20211201102557.GA1635608@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.1 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: Bob Duff Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Give an error in the following cases: type T is access not null procedure ...; type T is access not null function ...; type T is access not null protected procedure ...; type T is access not null protected function ...; These are illegal syntax. Note that similar errors on access-to-object types, such as "type T is access not null Boolean;" were already detected. Note that "type T is access not null T2;" is legal if T2 is an access type. Minor comment fixes. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * par-ch3.adb (P_Access_Type_Definition): If Not_Null_Subtype is True, give an error in the access-to-subprogram cases. diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb --- a/gcc/ada/par-ch3.adb +++ b/gcc/ada/par-ch3.adb @@ -4201,14 +4201,6 @@ package body Ch3 is function P_Access_Type_Definition (Header_Already_Parsed : Boolean := False) return Node_Id is - Access_Loc : constant Source_Ptr := Token_Ptr; - Prot_Flag : Boolean; - Not_Null_Present : Boolean := False; - Not_Null_Subtype : Boolean := False; - Type_Def_Node : Node_Id; - Result_Not_Null : Boolean; - Result_Node : Node_Id; - procedure Check_Junk_Subprogram_Name; -- Used in access to subprogram definition cases to check for an -- identifier or operator symbol that does not belong. @@ -4235,22 +4227,32 @@ package body Ch3 is end if; end Check_Junk_Subprogram_Name; + Access_Loc : constant Source_Ptr := Token_Ptr; + Prot_Flag : Boolean; + Not_Null_Present : Boolean := False; + Not_Null_Subtype : Boolean := False; + Not_Null_Subtype_Loc : Source_Ptr; -- loc of second "not null" + Type_Def_Node : Node_Id; + Result_Not_Null : Boolean; + Result_Node : Node_Id; + -- Start of processing for P_Access_Type_Definition begin if not Header_Already_Parsed then - - -- NOT NULL ACCESS .. is a common form of access definition. - -- ACCESS NOT NULL .. is certainly rare, but syntactically legal. - -- NOT NULL ACCESS NOT NULL .. is rarer yet, and also legal. - -- The last two cases are only meaningful if the following subtype - -- indication denotes an access type (semantic check). The flag - -- Not_Null_Subtype indicates that this second null exclusion is - -- present in the access type definition. - - Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231) + -- NOT NULL ACCESS... is a common form of access definition. ACCESS + -- NOT NULL... is certainly rare, but syntactically legal. NOT NULL + -- ACCESS NOT NULL... is rarer yet, and also legal. The last two + -- cases are only meaningful if the following subtype indication + -- denotes an access type. We check below for "not null procedure" + -- and "not null function"; in the access-to-object case it is a + -- semantic check. The flag Not_Null_Subtype indicates that this + -- second null exclusion is present in the access type definition. + + Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231) Scan; -- past ACCESS - Not_Null_Subtype := P_Null_Exclusion; -- Might also appear + Not_Null_Subtype_Loc := Token_Ptr; + Not_Null_Subtype := P_Null_Exclusion; -- Might also appear end if; if Token_Name = Name_Protected then @@ -4269,6 +4271,20 @@ package body Ch3 is end if; end if; + -- Access-to-subprogram case + + if Token in Tok_Procedure | Tok_Function then + + -- Check for "not null [protected] procedure" and "not null + -- [protected] function". + + if Not_Null_Subtype then + Error_Msg + ("null exclusion must apply to access type", + Not_Null_Subtype_Loc); + end if; + end if; + if Token = Tok_Procedure then if Ada_Version = Ada_83 then Error_Msg_SC ("(Ada 83) access to procedure not allowed!"); @@ -4317,9 +4333,10 @@ package body Ch3 is Set_Result_Definition (Type_Def_Node, Result_Node); + -- Access-to-object case + else - Type_Def_Node := - New_Node (N_Access_To_Object_Definition, Access_Loc); + Type_Def_Node := New_Node (N_Access_To_Object_Definition, Access_Loc); Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present); Set_Null_Excluding_Subtype (Type_Def_Node, Not_Null_Subtype);