https://gcc.gnu.org/g:7ac96b05cfa7478706dce175e7c7b09cbf559451

commit r15-4221-g7ac96b05cfa7478706dce175e7c7b09cbf559451
Author: Eric Botcazou <ebotca...@adacore.com>
Date:   Wed Oct 9 21:31:13 2024 +0200

    Fix LTO bootstrap failure with -Werror=lto-type-mismatch
    
    In GNAT's implementation model, using convention C (or C_Pass_By_Copy) has
    no effect on the internal representation of types since the representation
    is identical to that of C by default.  It's even counter-productive given
    the implementation advice listed in B.3(63-71) so the interface between the
    front-end and gigi does not use it and instead uses structurally identical
    types on both sides.
    
    gcc/ada
            PR ada/117038
            * fe.h (struct c_array): Add 'const' to declaration of pointer.
            (C_Source_Buffer): Use consistent formatting.
            * par-ch3.adb (P_Component_Items): Properly set Aliased_Present on
            access definition.
            * sinput.ads: Remove clause for Interfaces.C.
            (C_Array): Change type of Length to Integer and make both components
            aliased.  Remove Convention aspect.
            (C_Source_Buffer): Remove all aspects.
            * sinput.adb (C_Source_Buffer): Adjust to above change.

Diff:
---
 gcc/ada/fe.h        |  6 +++---
 gcc/ada/par-ch3.adb |  2 +-
 gcc/ada/sinput.adb  |  6 ++----
 gcc/ada/sinput.ads  | 12 ++++++------
 4 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/gcc/ada/fe.h b/gcc/ada/fe.h
index 36f5e9bfe9ed..e3e65fe18bd1 100644
--- a/gcc/ada/fe.h
+++ b/gcc/ada/fe.h
@@ -348,17 +348,17 @@ extern void Set_Present_Expr              (Node_Id, Uint);
 /* sinput: */
 
 struct c_array {
-  char *pointer;
+  const char *pointer;
   int length;
 };
 
-#define C_Source_Buffer sinput__c_source_buffer
+#define C_Source_Buffer        sinput__c_source_buffer
 #define Debug_Source_Name      sinput__debug_source_name
 #define Get_Column_Number      sinput__get_column_number
 #define Get_Logical_Line_Number        sinput__get_logical_line_number
 #define Get_Source_File_Index  sinput__get_source_file_index
 
-extern struct c_array C_Source_Buffer (Source_File_Index);
+extern struct c_array C_Source_Buffer          (Source_File_Index);
 extern File_Name_Type Debug_Source_Name                (Source_File_Index);
 extern Column_Number_Type Get_Column_Number    (Source_Ptr);
 extern Line_Number_Type Get_Logical_Line_Number        (Source_Ptr);
diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb
index a5f4319debf6..04246dc04ebe 100644
--- a/gcc/ada/par-ch3.adb
+++ b/gcc/ada/par-ch3.adb
@@ -3841,7 +3841,7 @@ package body Ch3 is
                --  end if;
 
                Set_Subtype_Indication (CompDef_Node, Empty);
-               Set_Aliased_Present    (CompDef_Node, False);
+               Set_Aliased_Present    (CompDef_Node, Aliased_Present);
                Set_Access_Definition  (CompDef_Node,
                  P_Access_Definition (Not_Null_Present));
             else
diff --git a/gcc/ada/sinput.adb b/gcc/ada/sinput.adb
index f2e6dda1c991..2b7439f1036a 100644
--- a/gcc/ada/sinput.adb
+++ b/gcc/ada/sinput.adb
@@ -281,10 +281,8 @@ package body Sinput is
    ---------------------
 
    function C_Source_Buffer (S : SFI) return C_Array is
-      use type Interfaces.C.int;
-
-      Length : constant Interfaces.C.int :=
-        Interfaces.C.int (Source_Last (S) - Source_First (S));
+      Length : constant Integer :=
+        Integer (Source_Last (S) - Source_First (S));
 
       Text : constant Source_Buffer_Ptr := Source_Text (S);
 
diff --git a/gcc/ada/sinput.ads b/gcc/ada/sinput.ads
index ce47fef76db3..d33c47083526 100644
--- a/gcc/ada/sinput.ads
+++ b/gcc/ada/sinput.ads
@@ -56,7 +56,6 @@
 
 with Alloc;
 with Casing; use Casing;
-with Interfaces.C;
 with Namet;  use Namet;
 with System;
 with Table;
@@ -708,12 +707,13 @@ package Sinput is
    --  to avoid memory leaks.
 
    type C_Array is record
-      Pointer : access constant Character;
-      Length  : Interfaces.C.int range 0 .. Interfaces.C.int'Last;
-   end record with Convention => C_Pass_By_Copy;
+      Pointer : aliased access constant Character;
+      Length  : aliased Integer;
+   end record;
+   --  WARNING: There is a matching C declaration of this type in fe.h
 
-   function C_Source_Buffer (S : SFI) return C_Array with
-     Export, Convention => C, External_Name => "sinput__c_source_buffer";
+   function C_Source_Buffer (S : SFI) return C_Array;
+   --  WARNING: There is a matching C declaration of this subprogram in fe.h
 
 private
    pragma Inline (File_Name);

Reply via email to