https://gcc.gnu.org/g:92fcd5740aefe9dc65d45e714e01edfc421e49f5

commit r16-6625-g92fcd5740aefe9dc65d45e714e01edfc421e49f5
Author: Viljar Indus <[email protected]>
Date:   Tue Nov 25 14:46:08 2025 +0200

    ada: Print gnat diagnostics with the gnat command
    
    Remove the support for printing the diagnostic report
    in the compiler when -gnatd_E is used. Instead print it
    when the "gnat --diagnostics" command is used.
    
    gcc/ada/ChangeLog:
    
            * debug.adb: remove use case for -gnatd_E
            * errout.adb (Output_Messages): remove printing of
            the diagnostic repository when -gnatd_E is used.
            * gnatcmd.adb: Add support for printing the diagnostic repository.

Diff:
---
 gcc/ada/debug.adb   |  2 +-
 gcc/ada/errout.adb  | 23 -----------------------
 gcc/ada/gnatcmd.adb | 30 ++++++++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/gcc/ada/debug.adb b/gcc/ada/debug.adb
index 4c0435e0bd52..f6acb2644944 100644
--- a/gcc/ada/debug.adb
+++ b/gcc/ada/debug.adb
@@ -169,7 +169,7 @@ package body Debug is
    --  d_B  Warn on build-in-place function calls
    --  d_C
    --  d_D
-   --  d_E  Print diagnostics and switch repository
+   --  d_E
    --  d_F  Encode full invocation paths in ALI files
    --  d_G
    --  d_H
diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index a5c68dd87183..59993da9608b 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -2889,7 +2889,6 @@ package body Errout is
 
       Sarif_File_Name       : constant String :=
         Get_First_Main_File_Name & ".gnat.sarif";
-      Diagnostics_File_Name : constant String := "gnat_diagnostics.sarif";
 
       Printer : Erroutc.SARIF_Emitter.SARIF_Printer;
 
@@ -2997,28 +2996,6 @@ package body Errout is
          end if;
       end if;
 
-      if Debug_Flag_Underscore_EE then
-
-         --  Print the diagnostics repository to a file
-
-         System.OS_Lib.Delete_File (Diagnostics_File_Name, Dummy);
-         declare
-            Output_FD : constant System.OS_Lib.File_Descriptor :=
-              System.OS_Lib.Create_New_File
-                (Diagnostics_File_Name,
-                 Fmode => System.OS_Lib.Text);
-
-         begin
-            Set_Output (Output_FD);
-
-            Print_Diagnostic_Repository;
-
-            Set_Standard_Output;
-
-            System.OS_Lib.Close (Output_FD);
-         end;
-      end if;
-
       --  Full source listing case
 
       if Full_List then
diff --git a/gcc/ada/gnatcmd.adb b/gcc/ada/gnatcmd.adb
index 5e3802e7f8ae..adfea9c7bd35 100644
--- a/gcc/ada/gnatcmd.adb
+++ b/gcc/ada/gnatcmd.adb
@@ -24,11 +24,13 @@
 ------------------------------------------------------------------------------
 
 with Gnatvsn;
+with Errid;    use Errid;
 with Namet;    use Namet;
 with Opt;      use Opt;
 with Osint;    use Osint;
 with Output;   use Output;
 with Switch;   use Switch;
+with System.OS_Lib;
 with Table;
 with Usage;
 
@@ -47,6 +49,10 @@ procedure GNATCmd is
    Ada_Help_Switch : constant String := "--help-ada";
    --  Flag to display available build switches
 
+   Ada_Diagnostics_Switch : constant String := "--diagnostics";
+
+   Diagnostics_File_Name : constant String := "gnat_diagnostics.sarif";
+
    Error_Exit : exception;
    --  Raise this exception if error detected
 
@@ -113,6 +119,7 @@ procedure GNATCmd is
 
    My_Exit_Status : Exit_Status := Success;
    --  The exit status of the spawned tool
+   Dummy : Boolean;
 
    type Command_Entry is record
       Cname : String_Access;
@@ -347,6 +354,29 @@ begin
             Keep_Temporary_Files := True;
             Command_Arg := Command_Arg + 1;
 
+         elsif Command_Arg <= Argument_Count
+           and then Argument (Command_Arg) = Ada_Diagnostics_Switch
+         then
+            --  Print the diagnostics repository to a file
+
+            System.OS_Lib.Delete_File (Diagnostics_File_Name, Dummy);
+            declare
+               Output_FD : constant System.OS_Lib.File_Descriptor :=
+                 System.OS_Lib.Create_New_File
+                   (Diagnostics_File_Name, Fmode => System.OS_Lib.Text);
+
+            begin
+               Set_Output (Output_FD);
+               Print_Diagnostic_Repository;
+               Set_Standard_Output;
+               System.OS_Lib.Close (Output_FD);
+            end;
+
+            Write_Line
+              ("gnat diagnostic information exported to "
+               & Diagnostics_File_Name);
+            Exit_Program (E_Success);
+
          elsif Command_Arg <= Argument_Count
            and then Argument (Command_Arg) = Ada_Help_Switch
          then

Reply via email to