]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Binder respects Ada version for checksum of runtime files
authorJose Ruiz <ruiz@adacore.com>
Fri, 23 Aug 2024 16:25:13 +0000 (16:25 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 5 Sep 2024 08:10:12 +0000 (10:10 +0200)
The parsing to compute the checksums of runtime files (within the
binder) was done using the default Ada version (Ada 2012 currently),
while the creation of the checksum, when the runtime files are
compiled, is performed in a more recent Ada version (Ada 2022
currently). This change forces the checksum computation for runtime
files to be done with the same Ada version as when they were created.

gcc/ada/

* ali-util.adb (Get_File_Checksum): Force the parsing for
the checksum computation of runtime files to be done in
the corresponding recent Ada version.

gcc/ada/ali-util.adb

index 61dddb94e85283c58735e381256c4af75d807856..4bcb06e6a1f660672e1e3fcaa51d2120296dae59 100644 (file)
@@ -29,6 +29,7 @@ with Opt;     use Opt;
 with Output;  use Output;
 with Osint;   use Osint;
 with Scans;   use Scans;
+with Fname;   use Fname;
 with Scng;
 with Sinput.C;
 with Stringt;
@@ -87,8 +88,10 @@ package body ALI.Util is
    -----------------------
 
    function Get_File_Checksum (Fname : File_Name_Type) return Word is
-      Full_Name    : File_Name_Type;
-      Source_Index : Source_File_Index;
+      Full_Name           : File_Name_Type;
+      Source_Index        : Source_File_Index;
+      Ada_Version_Current : Ada_Version_Type;
+      Internal_Unit       : constant Boolean := Is_Internal_File_Name (Fname);
 
    begin
       Full_Name := Find_File (Fname, Osint.Source);
@@ -109,6 +112,15 @@ package body ALI.Util is
 
       Scanner.Initialize_Scanner (Source_Index);
 
+      --  The runtime files are precompiled with an implicitly defined Ada
+      --  version that we set here to improve the parsing required to compute
+      --  the checksum.
+
+      if Internal_Unit then
+         Ada_Version_Current := Ada_Version;
+         Ada_Version := Ada_Version_Runtime;
+      end if;
+
       --  Scan the complete file to compute its checksum
 
       loop
@@ -116,6 +128,12 @@ package body ALI.Util is
          exit when Token = Tok_EOF;
       end loop;
 
+      --  Restore the Ada version if we changed it
+
+      if Internal_Unit then
+         Ada_Version := Ada_Version_Current;
+      end if;
+
       return Scans.Checksum;
    end Get_File_Checksum;