[COMMITTED] ada: Move warnings switches -- initial work

Message ID 20221108084258.301710-1-poulhies@adacore.com
State Committed
Headers
Series [COMMITTED] ada: Move warnings switches -- initial work |

Commit Message

Marc Poulhiès Nov. 8, 2022, 8:42 a.m. UTC
  From: Bob Duff <duff@adacore.com>

This patch prepares to move warning switches from Opt into Warnsw.

gcc/ada/

	* warnsw.ads, warnsw.adb, fe.h, err_vars.ads, errout.ads: Move
	Warning_Doc_Switch from Err_Vars to Warnsw. Access
	Warn_On_Questionable_Layout on the C side via a function rather
	than a variable, because we plan to turn the variables into
	renamings, and you can't Export renamings.
	* erroutc.adb, switch-c.adb, errout.adb: Likewise.
	* gcc-interface/decl.cc: Use Get_Warn_On_Questionable_Layout
	instead of Warn_On_Questionable_Layout.
	* gcc-interface/Makefile.in (GNATMAKE_OBJS): Add warnsw.o, because
	it is indirectly imported via Errout.
	* gcc-interface/Make-lang.in (GNATBIND_OBJS): Likewise and remove
	restrict.o (not needed).

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/err_vars.ads               |  6 ------
 gcc/ada/errout.adb                 |  2 ++
 gcc/ada/errout.ads                 |  9 ---------
 gcc/ada/erroutc.adb                |  1 +
 gcc/ada/fe.h                       |  4 ++--
 gcc/ada/gcc-interface/Make-lang.in |  2 +-
 gcc/ada/gcc-interface/Makefile.in  |  2 +-
 gcc/ada/gcc-interface/decl.cc      |  2 +-
 gcc/ada/switch-c.adb               |  1 -
 gcc/ada/warnsw.adb                 |  1 -
 gcc/ada/warnsw.ads                 | 13 ++++++++++++-
 11 files changed, 20 insertions(+), 23 deletions(-)
  

Patch

diff --git a/gcc/ada/err_vars.ads b/gcc/ada/err_vars.ads
index 05329dc6f21..79d5f319f59 100644
--- a/gcc/ada/err_vars.ads
+++ b/gcc/ada/err_vars.ads
@@ -81,12 +81,6 @@  package Err_Vars is
    --  Source_Reference line, then this is initialized to No_Source_File,
    --  to force an initial reference to the real source file name.
 
-   Warning_Doc_Switch : Boolean := True;
-   --  If this is set True, then the ??/?x?/?x? sequences in error messages
-   --  are active (see errout.ads for details). If this switch is False, then
-   --  these sequences are ignored (i.e. simply equivalent to a single ?). The
-   --  -gnatw.d switch sets this flag True, -gnatw.D sets this flag False.
-
    ----------------------------------------
    -- Error Message Insertion Parameters --
    ----------------------------------------
diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index 5730a543ee1..19ea1553260 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -53,6 +53,8 @@  with Stand;          use Stand;
 with Stylesw;        use Stylesw;
 with System.OS_Lib;
 with Uname;          use Uname;
+with Warnsw; pragma Unreferenced (Warnsw);
+--  Will be referenced when various flags are moved to Warnsw.
 
 package body Errout is
 
diff --git a/gcc/ada/errout.ads b/gcc/ada/errout.ads
index 846a4a6c07b..aeb9a2fb912 100644
--- a/gcc/ada/errout.ads
+++ b/gcc/ada/errout.ads
@@ -59,15 +59,6 @@  package Errout is
    Error_Msg_Exception : exception renames Err_Vars.Error_Msg_Exception;
    --  Exception raised if Raise_Exception_On_Error is true
 
-   Warning_Doc_Switch : Boolean renames Err_Vars.Warning_Doc_Switch;
-   --  If this is set True, then the ??/?*?/?$?/?x?/?.x?/?_x? insertion
-   --  sequences in error messages generate appropriate tags for the output
-   --  error messages. If this switch is False, then these sequences are still
-   --  recognized (for the purposes of implementing the pattern matching in
-   --  pragmas Warnings (Off,..) and Warning_As_Error(...) but do not result
-   --  in adding the error message tag. The -gnatw.d switch sets this flag
-   --  True, -gnatw.D sets this flag False.
-
    Current_Node : Node_Id := Empty;
    --  Used by Error_Msg as a default Node_Id.
    --  Relevant only when Opt.Include_Subprogram_In_Messages is set.
diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb
index d0cbe9fdff1..9ecc97fb46d 100644
--- a/gcc/ada/erroutc.adb
+++ b/gcc/ada/erroutc.adb
@@ -44,6 +44,7 @@  with Stringt;  use Stringt;
 with Targparm;
 with Uintp;    use Uintp;
 with Widechar; use Widechar;
+with Warnsw;   use Warnsw;
 
 package body Erroutc is
 
diff --git a/gcc/ada/fe.h b/gcc/ada/fe.h
index 79a1b58836e..8102c6d5ec4 100644
--- a/gcc/ada/fe.h
+++ b/gcc/ada/fe.h
@@ -366,9 +366,9 @@  extern Boolean Stack_Check_Probes_On_Target;
 
 /* warnsw: */
 
-#define Warn_On_Questionable_Layout	warnsw__warn_on_questionable_layout
+#define Get_Warn_On_Questionable_Layout	warnsw__get_warn_on_questionable_layout
 
-extern Boolean Warn_On_Questionable_Layout;
+extern Boolean Get_Warn_On_Questionable_Layout ();
 
 // The following corresponds to Ada code in Einfo.Utils.
 
diff --git a/gcc/ada/gcc-interface/Make-lang.in b/gcc/ada/gcc-interface/Make-lang.in
index 02b2d1c6f2a..45a4168e890 100644
--- a/gcc/ada/gcc-interface/Make-lang.in
+++ b/gcc/ada/gcc-interface/Make-lang.in
@@ -601,7 +601,6 @@  GNATBIND_OBJS = \
  ada/osint-b.o    \
  ada/osint.o      \
  ada/output.o     \
- ada/restrict.o   \
  ada/rident.o     \
  ada/scans.o      \
  ada/scil_ll.o    \
@@ -629,6 +628,7 @@  GNATBIND_OBJS = \
  ada/uintp.o      \
  ada/uname.o      \
  ada/urealp.o     \
+ ada/warnsw.o     \
  ada/widechar.o   \
  ada/gnat.o       \
  ada/g-dynhta.o   \
diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in
index 6b19b8be58e..5137ebaa0c6 100644
--- a/gcc/ada/gcc-interface/Makefile.in
+++ b/gcc/ada/gcc-interface/Makefile.in
@@ -333,7 +333,7 @@  GNATMAKE_OBJS = a-except.o ali.o ali-util.o aspects.o s-casuti.o alloc.o \
  s-purexc.o s-htable.o scil_ll.o sem_aux.o sinfo.o sinput.o sinput-c.o \
  snames.o stand.o stringt.o styleg.o stylesw.o system.o validsw.o \
  switch.o switch-m.o table.o targparm.o tempdir.o types.o uintp.o \
- uname.o urealp.o usage.o widechar.o \
+ uname.o urealp.o usage.o widechar.o warnsw.o \
  seinfo.o einfo-entities.o einfo-utils.o sinfo-nodes.o sinfo-utils.o \
  $(EXTRA_GNATMAKE_OBJS)
 
diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index f8c76982de5..e25ce498f2c 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -8363,7 +8363,7 @@  components_to_record (Node_Id gnat_component_list, Entity_Id gnat_record_type,
        && !Debug_Flag_Dot_R);
   const bool w_reorder
     = (Convention (gnat_record_type) == Convention_Ada
-       && Warn_On_Questionable_Layout
+       && Get_Warn_On_Questionable_Layout ()
        && !(No_Reordering (gnat_record_type) && GNAT_Mode));
   tree gnu_zero_list = NULL_TREE;
   tree gnu_self_list = NULL_TREE;
diff --git a/gcc/ada/switch-c.adb b/gcc/ada/switch-c.adb
index a1a877716f0..364ff55a4a6 100644
--- a/gcc/ada/switch-c.adb
+++ b/gcc/ada/switch-c.adb
@@ -28,7 +28,6 @@ 
 --  circularities, especially for back ends using Adabkend.
 
 with Debug;    use Debug;
-with Errout;   use Errout;
 with Lib;      use Lib;
 with Osint;    use Osint;
 with Opt;      use Opt;
diff --git a/gcc/ada/warnsw.adb b/gcc/ada/warnsw.adb
index 733c9620631..dd40c8844c3 100644
--- a/gcc/ada/warnsw.adb
+++ b/gcc/ada/warnsw.adb
@@ -23,7 +23,6 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with Err_Vars; use Err_Vars;
 with Opt;      use Opt;
 with Output;   use Output;
 
diff --git a/gcc/ada/warnsw.ads b/gcc/ada/warnsw.ads
index 9edd6bea37e..645094509f4 100644
--- a/gcc/ada/warnsw.ads
+++ b/gcc/ada/warnsw.ads
@@ -38,6 +38,15 @@  package Warnsw is
    --  here as time goes by. And in fact a really nice idea would be to put
    --  them all in a Warn_Record so that they would be easy to save/restore.
 
+   Warning_Doc_Switch : Boolean := True;
+   --  If this is set True, then the ??/?*?/?$?/?x?/?.x?/?_x? insertion
+   --  sequences in error messages generate appropriate tags for the output
+   --  error messages. If this switch is False, then these sequences are still
+   --  recognized (for the purposes of implementing the pattern matching in
+   --  pragmas Warnings (Off,..) and Warning_As_Error(...) but do not result
+   --  in adding the error message tag. The -gnatw.d switch sets this flag
+   --  True, -gnatw.D sets this flag False.
+
    Warn_On_Anonymous_Allocators : Boolean := False;
    --  Warn when allocators for anonymous access types are present, which,
    --  although not illegal in Ada, may be confusing to users due to how
@@ -71,7 +80,9 @@  package Warnsw is
    --  efficiency reasons and would be improved by reordering the components.
    --  Off by default, modified by use of -gnatw.q/.Q (but not -gnatwa).
 
-   --  WARNING: There is a matching C declaration of this variable in fe.h
+   function Get_Warn_On_Questionable_Layout return Boolean is
+     (Warn_On_Questionable_Layout);
+   --  WARNING: There is a matching C declaration of this function in fe.h
 
    Warn_On_Record_Holes : Boolean := False;
    --  Warn when explicit record component clauses leave uncovered holes (gaps)