public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Silence some -Wnarrowing errors
@ 2022-12-02  7:26 Eric Gallager
  2022-12-05 16:53 ` Jeff Law
  2023-04-20 16:28 ` Jeff Law
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Gallager @ 2022-12-02  7:26 UTC (permalink / raw)
  To: gcc-patches; +Cc: marxin

[-- Attachment #1: Type: text/plain, Size: 1013 bytes --]

I tried turning -Wnarrowing back on earlier this year, but
unfortunately it didn't work due to triggering a bunch of new errors.
This patch silences at least some of them, but there will still be
more left even after applying it. (When compiling with clang,
technically the warning flag is -Wc++11-narrowing, but it's pretty
much the same thing as gcc's -Wnarrowing, albeit with fixit hints,
which I made use of to insert the casts here.)

gcc/ChangeLog:

    * ipa-modref.cc (modref_lattice::add_escape_point): Use a
static_cast to silence -Wnarrowing.
    (modref_eaf_analysis::record_escape_points): Likewise.
    (update_escape_summary_1): Likewise.
    * rtl-ssa/changes.cc (function_info::temp_access_array): Likewise.
    * rtl-ssa/member-fns.inl: Likewise.
    * tree-ssa-structalias.cc (push_fields_onto_fieldstack): Likewise.
    * tree-vect-slp.cc (vect_prologue_cost_for_slp): Likewise.
    * tree-vect-stmts.cc (vect_truncate_gather_scatter_offset): Likewise.
    (vectorizable_operation): Likewise.

[-- Attachment #2: patch-Wnarrowing.diff --]
[-- Type: application/octet-stream, Size: 4708 bytes --]

diff --git a/gcc/ipa-modref.cc b/gcc/ipa-modref.cc
index 0d9abacf0a6..4183fed73c7 100644
--- a/gcc/ipa-modref.cc
+++ b/gcc/ipa-modref.cc
@@ -2119,7 +2119,7 @@ modref_lattice::add_escape_point (gcall *call, int arg, int min_flags,
       merge (0);
       return true;
     }
-  escape_point new_ep = {call, arg, min_flags, direct};
+  escape_point new_ep = {call, arg, static_cast<eaf_flags_t>(min_flags), direct};
   escape_points.safe_push (new_ep);
   return true;
 }
@@ -2880,7 +2880,8 @@ modref_eaf_analysis::record_escape_points (tree name, int parm_index, int flags)
 	if ((ep->min_flags & flags) != flags)
 	  {
 	    cgraph_edge *e = node->get_edge (ep->call);
-	    struct escape_entry ee = {parm_index, ep->arg,
+	    struct escape_entry ee = {parm_index,
+				      static_cast<unsigned int>(ep->arg),
 				      ep->min_flags, ep->direct};
 
 	    escape_summaries->get_create (e)->esc.safe_push (ee);
@@ -4350,8 +4351,8 @@ update_escape_summary_1 (cgraph_edge *e,
 	  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};
+				       static_cast<eaf_flags_t>(min_flags),
+				       static_cast<bool>(ee->direct & em->direct)};
 	  sum->esc.safe_push (entry);
 	}
     }
diff --git a/gcc/rtl-ssa/changes.cc b/gcc/rtl-ssa/changes.cc
index 298358ed6d4..8b54714a4cc 100644
--- a/gcc/rtl-ssa/changes.cc
+++ b/gcc/rtl-ssa/changes.cc
@@ -90,7 +90,7 @@ function_info::temp_access_array (access_array accesses)
   gcc_assert (obstack_object_size (&m_temp_obstack) == 0);
   obstack_grow (&m_temp_obstack, accesses.begin (), accesses.size_bytes ());
   return { static_cast<access_info **> (obstack_finish (&m_temp_obstack)),
-	   accesses.size () };
+	   static_cast<unsigned int>(accesses.size ()) };
 }
 
 // See the comment above the declaration.
diff --git a/gcc/rtl-ssa/member-fns.inl b/gcc/rtl-ssa/member-fns.inl
index 25a8750aefa..f7b91bc3c6f 100644
--- a/gcc/rtl-ssa/member-fns.inl
+++ b/gcc/rtl-ssa/member-fns.inl
@@ -47,7 +47,7 @@ access_array_builder::finish ()
 
   auto **base = static_cast<access_info **> (obstack_finish (m_obstack));
   keep ();
-  return { base, num_accesses };
+  return { base, static_cast<unsigned int>(num_accesses) };
 }
 
 inline bool
diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc
index dcf13d939bd..e85a36eda3d 100644
--- a/gcc/tree-ssa-structalias.cc
+++ b/gcc/tree-ssa-structalias.cc
@@ -5885,7 +5885,8 @@ push_fields_onto_fieldstack (tree type, vec<fieldoff_s> *fieldstack,
 		&& offset + foff != 0)
 	      {
 		fieldoff_s e
-		  = {0, offset + foff, false, false, true, false, NULL_TREE};
+		  = {0, static_cast<unsigned long long>(offset + foff), false,
+		     false, true, false, NULL_TREE};
 		pair = fieldstack->safe_push (e);
 	      }
 
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index e54414f6bef..9cf06aa4218 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -6055,7 +6055,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 }))
+	if (!vector_ops.add ({ ops, static_cast<unsigned int>(i * const_nunits),
+	                       static_cast<unsigned int>(const_nunits) }))
 	  starts.quick_push (i * const_nunits);
     }
   else
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 5485da58b38..31453665aa9 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -1911,7 +1911,7 @@ 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) };
+  int scales[] = { 1, static_cast<int>(vect_get_scalar_dr_size (dr_info)) };
   wi::overflow_type overflow = wi::OVF_NONE;
   for (int i = 0; i < 2; ++i)
     {
@@ -6476,7 +6476,7 @@ vectorizable_operation (vec_info *vinfo,
 	      && VECTOR_BOOLEAN_TYPE_P (vectype))
 	    {
 	      if (loop_vinfo->scalar_cond_masked_set.contains ({ op0,
-								 ncopies}))
+								 static_cast<unsigned int>(ncopies)}))
 		{
 		  mask = vect_get_loop_mask (gsi, masks, vec_num * ncopies,
 					     vectype, i);
@@ -6486,7 +6486,7 @@ vectorizable_operation (vec_info *vinfo,
 		}
 
 	      if (loop_vinfo->scalar_cond_masked_set.contains ({ op1,
-								 ncopies }))
+								 static_cast<unsigned int>(ncopies) }))
 		{
 		  mask = vect_get_loop_mask (gsi, masks, vec_num * ncopies,
 					     vectype, i);

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-04-20 16:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-02  7:26 [PATCH] Silence some -Wnarrowing errors Eric Gallager
2022-12-05 16:53 ` Jeff Law
2023-04-20 16:28 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).