From patchwork Mon May 16 08:43:07 2022 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: 54010 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 BC6453857815 for ; Mon, 16 May 2022 08:55:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC6453857815 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652691345; bh=70o2n4C401J3ukgEtbZ2JHJTOBtfWqIuNmHIxs5LHeQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=YZ9GTyF3Mx7Q+8/LwIuh/WvnPjNwFSFo+NeTgSOStj9oudpJqcz8DwLNGkxSllPYf KNAvpjrQHjOzsKajG1ylbTCfqYPsWPc71iXsTE4j11OxpQQDXx4DDBfoEa8CfyQM9A YifYq1j9EDTenl2zxggYmpzDe1DifOUNZlBerCUU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 9A8083857823 for ; Mon, 16 May 2022 08:43:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9A8083857823 Received: by mail-wm1-x329.google.com with SMTP id n6so524924wms.0 for ; Mon, 16 May 2022 01:43:09 -0700 (PDT) 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=70o2n4C401J3ukgEtbZ2JHJTOBtfWqIuNmHIxs5LHeQ=; b=SiM+R1+9h+EG1kl7iX0KmRYwZN3C69m8cbebd9N1tjJM9LPy5iCJ1gRp6ervC+UcJ8 6f8ScFFtA0VXhma/4pcAHX6hIOvEBj8DZN61srYreIEmf0Fd4IcLILNp9LydH0OkrpOf 0G+yPi1gcVrBUrZYh6qW/IuIEc9PIaswNS8thOTFnXvPqoOmhjbKgn7mo339wRCzZ4Z1 Vm5ux8DGJBRF0ule6brnLlL5ZK1O/ywZXVG92peIuXTybqBSPHIpyhcEorv4GaAphw5N j3m8081DwfkpPO2Le8AU2MwO6GTCBgtveqodE51rK8vJIpETNG8L5xXW8nx9aaD27u+9 tuew== X-Gm-Message-State: AOAM533Yqg1gHK4j0Z6BBlz40jfQ1SN80ioI5daTbncDz2M8cyl9+qrf 5aM35zbBFynHDmtomdLrSEePgNi7Ccb5Xw== X-Google-Smtp-Source: ABdhPJytDPMfYpLegLpjwzGdY4jTQd9TMA2KrNkgySSvPvURq3Juzz3y+xF9ZA6EREItK19HZ7P2gA== X-Received: by 2002:a1c:3b54:0:b0:394:3910:3cb9 with SMTP id i81-20020a1c3b54000000b0039439103cb9mr26257189wma.50.1652690588408; Mon, 16 May 2022 01:43:08 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id u10-20020adfc64a000000b0020c5253d8d4sm1672345wrg.32.2022.05.16.01.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 01:43:07 -0700 (PDT) Date: Mon, 16 May 2022 08:43:07 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Accept calls to abstract subprograms in class-wide pre/post-conditions Message-ID: <20220516084307.GA3843564@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Javier Miranda Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Fix a regression in the support for Ada 2022's treatment of calls to abstract subprograms in pre/post-conditions (thanks to Javier Miranda for producing this patch). Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_disp.adb (Check_Dispatching_Context): When checking to see whether an expression occurs in a class-wide pre/post-condition, also check for the possibility that it occurs in a class-wide preconditions subprogram that was introduced as part of expansion. Without this fix, some legal calls occuring in class-wide preconditions may be incorrectly flagged as violating the "a call to an abstract subprogram must be dispatching" rule. diff --git a/gcc/ada/sem_disp.adb b/gcc/ada/sem_disp.adb --- a/gcc/ada/sem_disp.adb +++ b/gcc/ada/sem_disp.adb @@ -751,14 +751,22 @@ package body Sem_Disp is elsif Is_Subprogram (Scop) and then not Is_Tag_Indeterminate (N) - and then In_Pre_Post_Condition (Call, Class_Wide_Only => True) + and then + -- The context is an internally built helper or an indirect + -- call wrapper that handles class-wide preconditions + (Present (Class_Preconditions_Subprogram (Scop)) - -- The tagged type associated with the called subprogram must be - -- the same as that of the subprogram with a class-wide aspect. + -- ... or the context is a class-wide pre/postcondition. + or else + (In_Pre_Post_Condition (Call, Class_Wide_Only => True) - and then Is_Dispatching_Operation (Scop) - and then - Find_Dispatching_Type (Subp) = Find_Dispatching_Type (Scop) + -- The tagged type associated with the called + -- subprogram must be the same as that of the + -- subprogram with a class-wide aspect. + + and then Is_Dispatching_Operation (Scop) + and then Find_Dispatching_Type (Subp) + = Find_Dispatching_Type (Scop))) then null;