]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
build: enable C++11 narrowing warnings
authorJason Merrill <jason@redhat.com>
Thu, 19 Sep 2024 19:50:19 +0000 (15:50 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 24 Sep 2024 12:01:10 +0000 (08:01 -0400)
We've been using -Wno-narrowing since gcc 4.7, but at this point narrowing
diagnostics seem like a stable part of C++ and we should adjust.

This patch changes -Wno-narrowing to -Wno-error=narrowing so that narrowing
issues will still not break bootstrap, but we can see them.

The rest of the patch fixes the narrowing warnings I see in an
x86_64-pc-linux-gnu bootstrap.  In most of the cases, by adjusting the types
of various declarations so that we store the values in the same types we
compute them in, which seems worthwhile anyway.  This also allowed us to
remove a few -Wsign-compare casts.

gcc/ChangeLog:

* configure.ac (CXX_WARNING_OPTS): Change -Wno-narrowing
to -Wno-error=narrowing.
* configure: Regenerate.
* config/i386/i386.h (debugger_register_map)
(debugger64_register_map)
(svr4_debugger_register_map): Make unsigned.
* config/i386/i386.cc: Likewise.
* diagnostic-event-id.h (diagnostic_thread_id_t): Make int.
* vec.h (vec::size): Make unsigned int.
* ipa-modref.cc (escape_point::arg): Make unsigned.
(modref_lattice::add_escape_point): Use eaf_flags_t.
(update_escape_summary_1): Use eaf_flags_t, && for bool.
* pair-fusion.cc (pair_fusion_bb_info::track_access):
Make mem_size unsigned int.
* pretty-print.cc (format_phase_2): Cast va_arg to char.
* tree-ssa-loop-ch.cc (ch_base::copy_headers): Make nheaders
unsigned, remove cast.
* tree-ssa-structalias.cc (bitpos_of_field): Return unsigned.
(push_fields_onto_fieldstack):Make offset unsigned, remove cast.
* tree-vect-slp.cc (vect_prologue_cost_for_slp): Use nelt_limit.
* tree-vect-stmts.cc (vect_truncate_gather_scatter_offset):
Make scale unsigned.
(vectorizable_operation): Make ncopies unsigned.
* rtl-ssa/member-fns.inl: Make num_accesses unsigned int.

14 files changed:
gcc/config/i386/i386.cc
gcc/config/i386/i386.h
gcc/configure
gcc/configure.ac
gcc/diagnostic-event-id.h
gcc/ipa-modref.cc
gcc/pair-fusion.cc
gcc/pretty-print.cc
gcc/rtl-ssa/member-fns.inl
gcc/tree-ssa-loop-ch.cc
gcc/tree-ssa-structalias.cc
gcc/tree-vect-slp.cc
gcc/tree-vect-stmts.cc
gcc/vec.h

index 7dbae1d72e35649f719f450f62894abd53df6e3f..2f736a3b346ef83b28bf59bf86bbd17c1691cf51 100644 (file)
@@ -181,7 +181,7 @@ enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
 
 /* The "default" register map used in 32bit mode.  */
 
-int const debugger_register_map[FIRST_PSEUDO_REGISTER] =
+unsigned int const debugger_register_map[FIRST_PSEUDO_REGISTER] =
 {
   /* general regs */
   0, 2, 1, 3, 6, 7, 4, 5,
@@ -212,7 +212,7 @@ int const debugger_register_map[FIRST_PSEUDO_REGISTER] =
 
 /* The "default" register map used in 64bit mode.  */
 
-int const debugger64_register_map[FIRST_PSEUDO_REGISTER] =
+unsigned int const debugger64_register_map[FIRST_PSEUDO_REGISTER] =
 {
   /* general regs */
   0, 1, 2, 3, 4, 5, 6, 7,
@@ -294,7 +294,7 @@ int const debugger64_register_map[FIRST_PSEUDO_REGISTER] =
        17 for %st(6) (gcc regno = 14)
        18 for %st(7) (gcc regno = 15)
 */
-int const svr4_debugger_register_map[FIRST_PSEUDO_REGISTER] =
+unsigned int const svr4_debugger_register_map[FIRST_PSEUDO_REGISTER] =
 {
   /* general regs */
   0, 2, 1, 3, 6, 7, 5, 4,
index c1ec92ffb15093e58782807671652ac8e4292b61..751c250ddb311490e1a5c9e13c8302653697fe1e 100644 (file)
@@ -2091,9 +2091,9 @@ do {                                                      \
 #define DEBUGGER_REGNO(N) \
   (TARGET_64BIT ? debugger64_register_map[(N)] : debugger_register_map[(N)])
 
-extern int const debugger_register_map[FIRST_PSEUDO_REGISTER];
-extern int const debugger64_register_map[FIRST_PSEUDO_REGISTER];
-extern int const svr4_debugger_register_map[FIRST_PSEUDO_REGISTER];
+extern unsigned int const debugger_register_map[FIRST_PSEUDO_REGISTER];
+extern unsigned int const debugger64_register_map[FIRST_PSEUDO_REGISTER];
+extern unsigned int const svr4_debugger_register_map[FIRST_PSEUDO_REGISTER];
 
 /* Before the prologue, RA is at 0(%esp).  */
 #define INCOMING_RETURN_ADDR_RTX \
index 3d301b6ecd3df1352322260de69475012f04604b..5acc42c1e4d931f32655a0c272a6917dfdb86e4f 100755 (executable)
@@ -7146,7 +7146,6 @@ fi
 # * 'long long'
 # * variadic macros
 # * overlong strings
-# * C++11 narrowing conversions in { }
 # So, we only use -pedantic if we can disable those warnings.
 
 # In stage 1, disable -Wformat warnings from old GCCs about new % codes
@@ -7170,7 +7169,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 
 loose_warn=
 save_CXXFLAGS="$CXXFLAGS"
-for real_option in -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual $wf_opt; do
+for real_option in -W -Wall -Wno-error=narrowing -Wwrite-strings -Wcast-qual $wf_opt; do
   # Do the check with the no- prefix removed since gcc silently
   # accepts any -Wno-* option on purpose
   case $real_option in
@@ -21406,7 +21405,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 21409 "configure"
+#line 21408 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -21512,7 +21511,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 21515 "configure"
+#line 21514 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
index 8a2d2b0438e714f0fdb28457609607804b8d54e7..23f4884eff9e44b29a3b1f768ff7fed27676913e 100644 (file)
@@ -585,7 +585,6 @@ AC_SUBST(aliasing_flags)
 # * 'long long'
 # * variadic macros
 # * overlong strings
-# * C++11 narrowing conversions in { }
 # So, we only use -pedantic if we can disable those warnings.
 
 # In stage 1, disable -Wformat warnings from old GCCs about new % codes
@@ -595,7 +594,7 @@ AC_ARG_ENABLE(build-format-warnings,
 AS_IF([test $enable_build_format_warnings = no],
       [wf_opt=-Wno-format],[wf_opt=])
 ACX_PROG_CXX_WARNING_OPTS(
-       m4_quote(m4_do([-W -Wall -Wno-narrowing -Wwrite-strings ],
+       m4_quote(m4_do([-W -Wall -Wno-error=narrowing -Wwrite-strings ],
                       [-Wcast-qual $wf_opt])),
                       [loose_warn])
 ACX_PROG_CC_WARNING_OPTS(
index 8237ba34df331330507aa9b0c462c464d7eeed8d..06985d23c124d29c5b9b583d4e8fb238c8f6a3d1 100644 (file)
@@ -67,6 +67,6 @@ typedef diagnostic_event_id_t *diagnostic_event_id_ptr;
 /* A type for compactly referring to a particular thread within a
    diagnostic_path.  Typically there is just one thread per path,
    with id 0.  */
-typedef unsigned diagnostic_thread_id_t;
+typedef int diagnostic_thread_id_t;
 
 #endif /* ! GCC_DIAGNOSTIC_EVENT_ID_H */
index 400a8856de2d13f0387ab4a5a09f05221b3be599..19359662f8ffcce7ce9aedc066d565a6a79d1bf8 100644 (file)
@@ -1997,7 +1997,7 @@ struct escape_point
   /* Value escapes to this call.  */
   gcall *call;
   /* Argument it escapes to.  */
-  int arg;
+  unsigned int arg;
   /* Flags already known about the argument (this can save us from recording
      escape points if local analysis did good job already).  */
   eaf_flags_t min_flags;
@@ -2047,7 +2047,8 @@ public:
   bool merge_deref (const modref_lattice &with, bool ignore_stores);
   bool merge_direct_load ();
   bool merge_direct_store ();
-  bool add_escape_point (gcall *call, int arg, int min_flags, bool diret);
+  bool add_escape_point (gcall *call, unsigned int arg,
+                        eaf_flags_t min_flags, bool direct);
   void dump (FILE *out, int indent = 0) const;
 };
 
@@ -2101,8 +2102,8 @@ modref_lattice::dump (FILE *out, int indent) const
    point exists.  */
 
 bool
-modref_lattice::add_escape_point (gcall *call, int arg, int min_flags,
-                                 bool direct)
+modref_lattice::add_escape_point (gcall *call, unsigned arg,
+                                 eaf_flags_t min_flags, bool direct)
 {
   escape_point *ep;
   unsigned int i;
@@ -4415,12 +4416,12 @@ update_escape_summary_1 (cgraph_edge *e,
        continue;
       FOR_EACH_VEC_ELT (map[ee->parm_index], j, em)
        {
-         int min_flags = ee->min_flags;
+         eaf_flags_t min_flags = ee->min_flags;
          if (ee->direct && !em->direct)
            min_flags = deref_flags (min_flags, ignore_stores);
          struct escape_entry entry = {em->parm_index, ee->arg,
                                       min_flags,
-                                      ee->direct & em->direct};
+                                      ee->direct && em->direct};
          sum->esc.safe_push (entry);
        }
     }
index cb0374f426b08edf8e346790985ad87d05f57a08..653055fdcf67a8744811972c885e0bd2944521d2 100644 (file)
@@ -444,7 +444,7 @@ pair_fusion_bb_info::track_access (insn_info *insn, bool load_p, rtx mem)
   const bool fpsimd_op_p = m_pass->fpsimd_op_p (reg_op, mem_mode, load_p);
 
   // Note pair_operand_mode_ok_p already rejected VL modes.
-  const HOST_WIDE_INT mem_size = GET_MODE_SIZE (mem_mode).to_constant ();
+  const unsigned mem_size = GET_MODE_SIZE (mem_mode).to_constant ();
   const lfs_fields lfs = { load_p, fpsimd_op_p, mem_size };
 
   if (track_via_mem_expr (insn, mem, lfs))
index 998e06e155f756b0dc1fa7c38a1a782d4833807e..0cd9b4d0a4168fb73755ef8ee0921e1e146fd0bd 100644 (file)
@@ -1923,7 +1923,7 @@ format_phase_2 (pretty_printer *pp,
            /* When quoting, print alphanumeric, punctuation, and the space
               character unchanged, and all others in hexadecimal with the
               "\x" prefix.  Otherwise print them all unchanged.  */
-           int chr = va_arg (*text.m_args_ptr, int);
+           char chr = (char) va_arg (*text.m_args_ptr, int);
            if (ISPRINT (chr) || !quote)
              pp_character (pp, chr);
            else
index d39184fb8cd8e0f5ebcff766c9a84bd6a41c0cff..143c22c8c77db20a8c39084363a5ffc9d343ecb0 100644 (file)
@@ -41,7 +41,8 @@ access_array_builder::quick_push (access_info *access)
 inline array_slice<access_info *>
 access_array_builder::finish ()
 {
-  auto num_accesses = obstack_object_size (m_obstack) / sizeof (access_info *);
+  unsigned num_accesses
+    = obstack_object_size (m_obstack) / sizeof (access_info *);
   if (num_accesses == 0)
     return {};
 
index 525eb357858a9c93a4640fcc79c419b3653bd016..6552ddd1ee2f5a74c78a59ed935caac16bb96b82 100644 (file)
@@ -839,8 +839,8 @@ ch_base::copy_headers (function *fun)
         copied.  TODO -- handle while (a || b) - like cases, by not requiring
         the header to have just a single successor and copying up to
         postdominator.  */
-      int nheaders = 0;
-      int last_win_nheaders = 0;
+      unsigned int nheaders = 0;
+      unsigned int last_win_nheaders = 0;
       bool last_win_invariant_exit = false;
       ch_decision ret;
       auto_vec <ch_decision, 32> decision;
@@ -893,7 +893,7 @@ ch_base::copy_headers (function *fun)
        }
       /* "Duplicate" all BBs with zero cost following last basic blocks we
         decided to copy.  */
-      while (last_win_nheaders < (int)decision.length ()
+      while (last_win_nheaders < decision.length ()
             && decision[last_win_nheaders] == ch_possible_zero_cost)
        {
          if (dump_file && (dump_flags & TDF_DETAILS))
index a32ef1d5cc0c95fe81821620d6a18d128abe0a56..d6a53f801f036fd1bbe2586e102a1c3517e199bb 100644 (file)
@@ -3220,15 +3220,15 @@ process_constraint (constraint_t t)
 /* Return the position, in bits, of FIELD_DECL from the beginning of its
    structure.  */
 
-static HOST_WIDE_INT
+static unsigned HOST_WIDE_INT
 bitpos_of_field (const tree fdecl)
 {
-  if (!tree_fits_shwi_p (DECL_FIELD_OFFSET (fdecl))
-      || !tree_fits_shwi_p (DECL_FIELD_BIT_OFFSET (fdecl)))
+  if (!tree_fits_uhwi_p (DECL_FIELD_OFFSET (fdecl))
+      || !tree_fits_uhwi_p (DECL_FIELD_BIT_OFFSET (fdecl)))
     return -1;
 
-  return (tree_to_shwi (DECL_FIELD_OFFSET (fdecl)) * BITS_PER_UNIT
-         + tree_to_shwi (DECL_FIELD_BIT_OFFSET (fdecl)));
+  return (tree_to_uhwi (DECL_FIELD_OFFSET (fdecl)) * BITS_PER_UNIT
+         + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fdecl)));
 }
 
 
@@ -5925,7 +5925,7 @@ field_must_have_pointers (tree t)
 
 static bool
 push_fields_onto_fieldstack (tree type, vec<fieldoff_s> *fieldstack,
-                            HOST_WIDE_INT offset)
+                            unsigned HOST_WIDE_INT offset)
 {
   tree field;
   bool empty_p = true;
@@ -5943,7 +5943,7 @@ push_fields_onto_fieldstack (tree type, vec<fieldoff_s> *fieldstack,
     if (TREE_CODE (field) == FIELD_DECL)
       {
        bool push = false;
-       HOST_WIDE_INT foff = bitpos_of_field (field);
+       unsigned HOST_WIDE_INT foff = bitpos_of_field (field);
        tree field_type = TREE_TYPE (field);
 
        if (!var_can_have_subvars (field)
@@ -5988,7 +5988,7 @@ push_fields_onto_fieldstack (tree type, vec<fieldoff_s> *fieldstack,
                && !must_have_pointers_p
                && !pair->must_have_pointers
                && !pair->has_unknown_size
-               && pair->offset + (HOST_WIDE_INT)pair->size == offset + foff)
+               && pair->offset + pair->size == offset + foff)
              {
                pair->size += tree_to_uhwi (DECL_SIZE (field));
              }
index f5b47e430e31dd3bce6dd9e74777dce901dda63f..482b9d504965e9c0ce11150d09dbe5bd76f131a7 100644 (file)
@@ -7489,8 +7489,8 @@ vect_prologue_cost_for_slp (slp_tree node,
       nelt_limit = const_nunits;
       hash_set<vect_scalar_ops_slice_hash> vector_ops;
       for (unsigned int i = 0; i < SLP_TREE_NUMBER_OF_VEC_STMTS (node); ++i)
-       if (!vector_ops.add ({ ops, i * const_nunits, const_nunits }))
-         starts.quick_push (i * const_nunits);
+       if (!vector_ops.add ({ ops, i * nelt_limit, nelt_limit }))
+         starts.quick_push (i * nelt_limit);
     }
   else
     {
index ad08fbe55110ecea9df09ee05a96b5ed97f10212..c654e01a540f2fcf0b275a28d1c383de560be590 100644 (file)
@@ -1711,11 +1711,11 @@ vect_truncate_gather_scatter_offset (stmt_vec_info stmt_info,
     count = max_iters.to_shwi ();
 
   /* Try scales of 1 and the element size.  */
-  int scales[] = { 1, vect_get_scalar_dr_size (dr_info) };
+  unsigned int scales[] = { 1, vect_get_scalar_dr_size (dr_info) };
   wi::overflow_type overflow = wi::OVF_NONE;
   for (int i = 0; i < 2; ++i)
     {
-      int scale = scales[i];
+      unsigned int scale = scales[i];
       widest_int factor;
       if (!wi::multiple_of_p (wi::to_widest (step), scale, SIGNED, &factor))
        continue;
@@ -6539,7 +6539,8 @@ vectorizable_operation (vec_info *vinfo,
   poly_uint64 nunits_in;
   poly_uint64 nunits_out;
   tree vectype_out;
-  int ncopies, vec_num;
+  unsigned int ncopies;
+  int vec_num;
   int i;
   vec<tree> vec_oprnds0 = vNULL;
   vec<tree> vec_oprnds1 = vNULL;
index bc83827f644eb706112214eb93f07aa36fdf683f..b13c4716428e8af33973bb613277005b5f0f1b09 100644 (file)
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -2409,7 +2409,7 @@ public:
   const value_type &back () const;
   const value_type &operator[] (unsigned int i) const;
 
-  size_t size () const { return m_size; }
+  unsigned size () const { return m_size; }
   size_t size_bytes () const { return m_size * sizeof (T); }
   bool empty () const { return m_size == 0; }