This is the LTO bootstrap failure with -Werror=lto-type-mismatch introduced by 
the patch implementing the new aspect External_Initialization.

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 for the sake of LTO.

Tested on x86-64/Linux, applied on the mainline.


2024-10-09  Eric Botcazou  <ebotca...@adacore.com>

        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.

-- 
Eric Botcazou
diff --git a/gcc/ada/fe.h b/gcc/ada/fe.h
index 36f5e9bfe9e..e3e65fe18bd 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 a5f4319debf..04246dc04eb 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 f2e6dda1c99..2b7439f1036 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 ce47fef76db..d33c4708352 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