[gcc r15-1157] ada: Derived type with convention C must override convention C_Pass_By_Copy

Marc Poulhi?s dkm@gcc.gnu.org
Mon Jun 10 09:09:20 GMT 2024


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

commit r15-1157-gf5e372e2a31c19ed0c784cfb3ebd373802a106ff
Author: Gary Dismukes <dismukes@adacore.com>
Date:   Wed Apr 17 23:44:41 2024 +0000

    ada: Derived type with convention C must override convention C_Pass_By_Copy
    
    If a type DT is derived from a record type T with convention C_Pass_By_Copy
    and explicitly specifies convention C (via aspect or pragma), then type DT
    should not be treated as a type with convention C_Pass_By_Copy. Any parameters
    of the derived type should be passed by reference rather than by copy. The
    compiler was incorrectly inheriting convention C_Pass_By_Copy, by inheriting
    the flag set on the parent type, but that flag needs to be unset in the case
    where the convention is overridden.
    
    gcc/ada/
    
            * sem_prag.adb (Set_Convention_From_Pragma): If the specified convention on
            a record type is not C_Pass_By_Copy, then force the C_Pass_By_Copy flag to
            False, to ensure that it's overridden.

Diff:
---
 gcc/ada/sem_prag.adb | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 9ccf1b9cf65..671b2a542ea 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -8498,6 +8498,15 @@ package body Sem_Prag is
                end if;
             end if;
 
+            --  If the convention of a record type is changed (such as to C),
+            --  this must override C_Pass_By_Copy if that flag was inherited
+            --  from a parent type where the latter convention was specified,
+            --  so we force the flag to False.
+
+            if Cname /= Name_C_Pass_By_Copy and then Is_Record_Type (E) then
+               Set_C_Pass_By_Copy (Base_Type (E), False);
+            end if;
+
             --  If the entity is a derived boolean type, check for the special
             --  case of convention C, C++, or Fortran, where we consider any
             --  nonzero value to represent true.


More information about the Gcc-cvs mailing list