public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Marc Poulhi?s <dkm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-4966] ada: Fix calling convention of foreign functions returning limited type
Date: Tue,  3 Jan 2023 09:34:14 +0000 (GMT)	[thread overview]
Message-ID: <20230103093414.5E09B3858C1F@sourceware.org> (raw)

https://gcc.gnu.org/g:bfe1ab222a8095b31c29d8f3530268f048fea00f

commit r13-4966-gbfe1ab222a8095b31c29d8f3530268f048fea00f
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Thu Dec 8 10:51:29 2022 +0100

    ada: Fix calling convention of foreign functions returning limited type
    
    Such functions use neither Ada 2005's build-in-place mechanism nor Ada 95's
    return-by-reference mechanism, but instead the common calling convention of
    functions returning a nonlimited by-reference type.
    
    gcc/ada/
    
            * exp_ch6.adb (Is_Build_In_Place_Function): Adjust comment.
            * sem_util.adb (Compute_Returns_By_Ref): Do not set Returns_By_Ref
            on functions with foreign convention.

Diff:
---
 gcc/ada/exp_ch6.adb  | 8 ++++----
 gcc/ada/sem_util.adb | 7 +++++--
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 975a96668df..d90ee41712e 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -7759,10 +7759,10 @@ package body Exp_Ch6 is
          return False;
       end if;
 
-      --  If the function is imported from a foreign language, we don't do
-      --  build-in-place, whereas Import (Ada) functions can do it. Note also
-      --  that it is OK for a build-in-place function to return a type with a
-      --  foreign convention because the machinery ensures there is no copying.
+      --  We never use build-in-place if the convention is other than Ada,
+      --  but note that it is OK for a build-in-place function to return a
+      --  type with a foreign convention because the machinery ensures there
+      --  is no copying.
 
       return (Kind in E_Function | E_Generic_Function
                or else
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 3132446515b..a05ac74d35f 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -6163,9 +6163,12 @@ package body Sem_Util is
       elsif Is_Build_In_Place_Function (Func) then
          Set_Returns_By_Ref (Func);
 
-      --  In Ada 95, limited types are returned by reference
+      --  In Ada 95, limited types are returned by reference, but not if the
+      --  convention is other than Ada.
 
-      elsif Is_Limited_View (Typ) then
+      elsif Is_Limited_View (Typ)
+        and then not Has_Foreign_Convention (Func)
+      then
          Set_Returns_By_Ref (Func);
       end if;
    end Compute_Returns_By_Ref;

                 reply	other threads:[~2023-01-03  9:34 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=20230103093414.5E09B3858C1F@sourceware.org \
    --to=dkm@gcc.gnu.org \
    --cc=gcc-cvs@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).