]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix calling convention of foreign functions returning limited type
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 8 Dec 2022 09:51:29 +0000 (10:51 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 3 Jan 2023 09:29:53 +0000 (10:29 +0100)
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.

gcc/ada/exp_ch6.adb
gcc/ada/sem_util.adb

index 975a96668df5f2e12f361a692c08cdf22749144f..d90ee41712e223fef138b6a93270f1cd8c3eb377 100644 (file)
@@ -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
index 3132446515bcd89bcd97035db7983d87f7f8ef34..a05ac74d35fa50c11f3ab525a2f2fc0f050ce6c5 100644 (file)
@@ -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;