From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id CE46F3857432 for ; Tue, 17 May 2022 08:27:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CE46F3857432 Received: by mail-wr1-x42c.google.com with SMTP id r23so7637799wrr.2 for ; Tue, 17 May 2022 01:27:32 -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=T31Sa9Q7LUMJ2QIPe54V1bjoyjqDuT9vupo6XqVSKeA=; b=bqorMtZjXeMmgL+dabGiggfRjMmuoseCGJpYmphYs3Si9BOSZ2rar92YyIFm/iUJPg YwaB1z8sODUNpxsyY32ojz4DH/oqNr2vuzcYdCU36Ve9B4CNzrefatRR/fe9VNV/xkVY /KLCCMQBZs1T9+KzsUq1TprT6keMyU+dcs0eOQn6w/oUKijm5mB5V1FVglw5jaCMxaMt 8jMIJPM3Wy2kyz4ffX2AbwhXD5DczfFQKCpqThuex/NyCThg0LwmUHsWjwGyO9SKE6cc Aj4gs/ne7h0RfHPmjjDqDvzI9/xXOmKJvrJyaLrX+mBalmqcXFVUil/7XFKRTxMAlUOM 0RkQ== X-Gm-Message-State: AOAM531/zZT5UlwXdhf9o6vIMXDSc6NR91suRtLVP36a0w9m39eBp8g3 jc1+nXnszokD1JcOpBUF12CswuET7VfhS4fX X-Google-Smtp-Source: ABdhPJwHIHpkS2NMb6PtC42DHEz+9CSa6XunQbBh0Gzbt8zEWfX0zgdFi5p8dyqkTohUSo85J13mag== X-Received: by 2002:a05:6000:1569:b0:20c:4ed4:4ba8 with SMTP id 9-20020a056000156900b0020c4ed44ba8mr17086820wrz.270.1652776051521; Tue, 17 May 2022 01:27:31 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id p33-20020a05600c1da100b003945cdd0d55sm1267027wms.26.2022.05.17.01.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:27:31 -0700 (PDT) Date: Tue, 17 May 2022 08:27:30 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [Ada] Implement calls to abstract subprograms in class-wide pre/post-conditions Message-ID: <20220517082730.GA1087755@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="zhXaljGHf11kAtnf" 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-List-Received-Date: Tue, 17 May 2022 08:27:34 -0000 --zhXaljGHf11kAtnf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In some special cases involving class-wide pre/post conditions, Ada allows a non-dispatching call to an abstract function (which is usually illegal). Fix a bug in the implementation of Ada's rules about the run-time behavior of such a call. Thanks to Javier Miranda for producing this patch. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * contracts.adb (Build_Call_Helper_Body): Improve handling of the case of a (legal) non-dispatching call to an abstract subprogram. --zhXaljGHf11kAtnf Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb --- a/gcc/ada/contracts.adb +++ b/gcc/ada/contracts.adb @@ -3899,7 +3899,16 @@ package body Contracts is Set_Corresponding_Body (Helper_Decl, Body_Id); Set_Must_Override (Body_Spec, False); - if Present (Class_Preconditions (Subp_Id)) then + if Present (Class_Preconditions (Subp_Id)) + -- Evaluate the expression if we are building a dynamic helper + -- or we are building a static helper for a non-abstract tagged + -- type; for abstract tagged types the helper just returns True + -- since it is called by the indirect call wrapper (ICW). + and then + (Is_Dynamic + or else + not Is_Abstract_Type (Find_Dispatching_Type (Subp_Id))) + then Return_Expr := Copy_And_Update_References (Class_Preconditions (Subp_Id)); @@ -3910,7 +3919,8 @@ package body Contracts is -- enabled. else - pragma Assert (Present (Ignored_Class_Preconditions (Subp_Id))); + pragma Assert (Present (Ignored_Class_Preconditions (Subp_Id)) + or else Is_Abstract_Type (Find_Dispatching_Type (Subp_Id))); Return_Expr := New_Occurrence_Of (Standard_True, Loc); end if; --zhXaljGHf11kAtnf--