From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1285) id 3D0B53847EC7; Wed, 27 Sep 2023 08:26:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D0B53847EC7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695803204; bh=l+AD04FPDXbY52QwQxRTKQ7l3GRxTTH4kz2Tn2IBpQ4=; h=From:To:Subject:Date:From; b=ZlRndDykFxhyglzgtfdaR1mb1HEQVVzAny/3SlHw7k/okiWSmuM4htXngXQwQFQe2 HVxvFRkPFb6L2H+9Va38gb4PtgCWWwKn5t0JUWV6UBcQvn6oCYtuwfJ19+VjHU2Luc dZaGyG/yweLEsp+TdZpmJU0cKFfyXyb00Ww5kvkA= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Eric Botcazou To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-7885] ada: Fix internal error on imported function with post-condition X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 56170ef50be7fcd80b6d5dbe052dbde1216ef2b9 X-Git-Newrev: a0d76c325f0bfa29256072084182ee8c9c4457dd Message-Id: <20230927082644.3D0B53847EC7@sourceware.org> Date: Wed, 27 Sep 2023 08:26:44 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a0d76c325f0bfa29256072084182ee8c9c4457dd commit r13-7885-ga0d76c325f0bfa29256072084182ee8c9c4457dd Author: Eric Botcazou Date: Mon Apr 24 17:11:01 2023 +0200 ada: Fix internal error on imported function with post-condition The problem, which is also present for an expression function, is that the function is invoked in the initializing expression of a variable declared in the same declarative part as the function, which causes the freezing of its artificial body before the post-condition is analyzed on its spec. gcc/ada/ * contracts.adb (Analyze_Entry_Or_Subprogram_Body_Contract): For a subprogram body that has no contracts and does not come from source, make sure that contracts on its corresponding spec are analyzed, if any, before expanding them. Diff: --- gcc/ada/contracts.adb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb index b0a0ab20228..39c067300d6 100644 --- a/gcc/ada/contracts.adb +++ b/gcc/ada/contracts.adb @@ -584,6 +584,22 @@ package body Contracts is else Set_Analyzed (Items); end if; + + -- When this is a subprogram body not coming from source, for example an + -- expression function, it does not cause freezing of previous contracts + -- (see Analyze_Subprogram_Body_Helper), in particular not of those on + -- its spec if it exists. In this case make sure they have been properly + -- analyzed before being expanded below, as we may be invoked during the + -- freezing of the subprogram in the middle of its enclosing declarative + -- part because the declarative part contains e.g. the declaration of a + -- variable initialized by means of a call to the subprogram. + + elsif Nkind (Body_Decl) = N_Subprogram_Body + and then not Comes_From_Source (Original_Node (Body_Decl)) + and then Present (Corresponding_Spec (Body_Decl)) + and then Present (Contract (Corresponding_Spec (Body_Decl))) + then + Analyze_Entry_Or_Subprogram_Contract (Corresponding_Spec (Body_Decl)); end if; -- Due to the timing of contract analysis, delayed pragmas may be