public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [COMMITTED] ada: Fix error and crash on imported function with precondition and 'Base
Date: Mon, 22 May 2023 10:49:53 +0200	[thread overview]
Message-ID: <20230522084953.1725838-1-poulhies@adacore.com> (raw)

From: Eric Botcazou <ebotcazou@adacore.com>

This fixes a spurious error on an imported function with a precondition
and a parameter declared with a 'Base formal type, and even a crash in
the case where this function is declared in a generic package.

gcc/ada/

	* freeze.adb (Wrap_Imported_Subprogram): Use Copy_Subprogram_Spec
	to copy the spec from the subprogram to the generated subprogram
	body.
	(Freeze_Entity): Do not wrap imported subprograms inside generics.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/freeze.adb | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index f54ae0503a1..df3b5ec944e 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -6127,8 +6127,7 @@ package body Freeze is
 
             Bod :=
               Make_Subprogram_Body (Loc,
-                Specification              =>
-                  Copy_Separate_Tree (Spec),
+                Specification              => Copy_Subprogram_Spec (Spec),
                 Declarations               => New_List (
                   Make_Subprogram_Declaration (Loc,
                     Specification => Copy_Separate_Tree (Spec)),
@@ -6438,7 +6437,9 @@ package body Freeze is
 
             --  Check for needing to wrap imported subprogram
 
-            Wrap_Imported_Subprogram (E);
+            if not Inside_A_Generic then
+               Wrap_Imported_Subprogram (E);
+            end if;
 
             --  Freeze all parameter types and the return type (RM 13.14(14)).
             --  However skip this for internal subprograms. This is also where
-- 
2.40.0


                 reply	other threads:[~2023-05-22  8:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230522084953.1725838-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).