From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id BE64C38582BC for ; Tue, 13 Jun 2023 07:38:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE64C38582BC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4f61b45ee0dso6287167e87.0 for ; Tue, 13 Jun 2023 00:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1686641900; x=1689233900; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vZbirhIPbeocnPwvy/5I62+1fqmDUh6SvjO4l/DCSGs=; b=Iunon9lE3LjIEbx3qT7aLbzmRs6eAEbOcV/Uv4T56xl34FrZMi5Xvnmv+cMxC2DAy5 mL3fzEveb/bf+qstpJkh5DtCHdIoQf/MDbdbZu2kC7yjGRxoqPjs/HYmcaUA/ZpQHPMD +mDohe1VNgdiI7XXYxYmRqWm3PuwarT9Ukt0PR84X8yQ93GRly+dhTEjjK2y/YaN0VMw b551NndytCOKBQ7WpGNMeaf8KQ6ZjGy2lsepFrqxA2aYPFH3vTzuWF8cZjAxTHq1M0F2 sMoChMCP+5j7DYm/saDjelichrc5OsfzUCDpoCfJWZWr6jD2Y6UuHOdviYB53ukfToOv cB1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686641900; x=1689233900; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vZbirhIPbeocnPwvy/5I62+1fqmDUh6SvjO4l/DCSGs=; b=KcW5qrIqCyH1sOQXBJeoh12P3m7Ps95ylxfSBDS8vaQkMfH4KXyQyx0kXoRd8gvYWc msGs7cAtnKq7WQME0NpI1TTSpTfVJeIb74y/J5nxanW6/HMK5qS7ddKNUa90AYsVcBtb TNtjga7Qz9iKxIjcr5Y9gF1dUvFtdA3r7mA38YPlnp+YM/Ybv0T8u9B/SLBP+XvUqSCs 7LwG/wga6/ibMvqxekwTbye8MIkIIKFDzlDPh03KAgOb7vg0VjSKZoREsiuxkPWYfTLM mn6Op1gMnLTnRTD7qSw3VABkZOyip8NZF6AgOxaI7B+i88drLpM/9IMWJ1ZqRmdcb7uv +Azg== X-Gm-Message-State: AC+VfDxL/N68ig1nvG8P6Zl4GmBzNjfqZag+m70pYB2BuXkOnkRMNKa5 CupJO3Bf3E6ZWasINwrXUnD/C8bSsTfqo89BXsfafA== X-Google-Smtp-Source: ACHHUZ79mKylRwnHyaywoqeEG0QTU++EvsLHp3xpFIi/tckTfpEukBedA/F4TAvVPGhyJmbK47W40g== X-Received: by 2002:a05:6512:521:b0:4f6:1190:aba9 with SMTP id o1-20020a056512052100b004f61190aba9mr6039181lfc.23.1686641900404; Tue, 13 Jun 2023 00:38:20 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:bfa8:5d29:40e5:cc66]) by smtp.gmail.com with ESMTPSA id i7-20020adffc07000000b0030631a599a0sm14645358wrr.24.2023.06.13.00.38.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 00:38:19 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix internal error on imported function with post-condition Date: Tue, 13 Jun 2023 09:38:18 +0200 Message-Id: <20230613073818.239995-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.6 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 List-Id: From: Eric Botcazou 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. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/contracts.adb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb index 7625abf9554..ae9e07ffc16 100644 --- a/gcc/ada/contracts.adb +++ b/gcc/ada/contracts.adb @@ -598,6 +598,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 -- 2.40.0