]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Improve preprocessor error handling.
authorSteve Baird <baird@adacore.com>
Fri, 10 May 2024 22:03:37 +0000 (15:03 -0700)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 20 Jun 2024 08:50:49 +0000 (10:50 +0200)
In some cases, gnatprep would correctly emit an error message and then
incorrectly exit with a return code of zero, indicating success.
In some cases, a correct message about an error detected by the integrated
preprocessor would be accompanied by an incorrect message indicating that
a source file could not be found.

gcc/ada/

* gprep.adb (Process_Files.Process_One_File): When calling OS_Exit in an error
path, pass in a Status parameter of 1 instead of 0 (because 0
indicates success).
* lib-load.adb (Load_Main_Source): Do not emit a message about a missing source file
if other error messages were generated by calling Load_Source_File;
the file isn't missing - it failed preprocessing.

gcc/ada/gprep.adb
gcc/ada/lib-load.adb

index a95cd634cc143a02f7af83654a74fa66ceb20454..3cb8026a042dd9bfea7863028233cc220eac96ac 100644 (file)
@@ -552,7 +552,7 @@ package body GPrep is
 
             Errutil.Finalize (Source_Type => "input");
 
-            OS_Exit (0);
+            OS_Exit (1);
 
          --  Otherwise, close the output file, and we are done
 
index 59adabc612c746a998e99fa58a7c1363665b738b..d5ea087a4fa46fd995a08e18df380c3ed0fbe6ee 100644 (file)
@@ -313,6 +313,7 @@ package body Lib.Load is
         Is_Predefined_Renaming_File_Name (Fname);
       GNAT_Name : constant Boolean :=
         Is_GNAT_File_Name (Fname);
+      Saved_Error_Count : constant Nat := Total_Errors_Detected;
       Version : Word := 0;
 
    begin
@@ -336,7 +337,14 @@ package body Lib.Load is
          if Main_Source_File > No_Source_File then
             Version := Source_Checksum (Main_Source_File);
 
-         else
+         --  If we get here and Saved_Error_Count /= Total_Errors_Detected,
+         --  then an error occurred during preprocessing. In this case
+         --  we have already generated an error message during preprocessing
+         --  and we do not want to emit an incorrect "file foo.adb not found"
+         --  message here.
+
+         elsif Saved_Error_Count = Total_Errors_Detected then
+
             --  To avoid emitting a source location (since there is no file),
             --  we write a custom error message instead of using the machinery
             --  in errout.adb.