This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add wide_int_storage::operator=


In debugging a -Wuninitialized issue from ipa-cp.c which does

              vr.min = vr.max = wi::zero (INT_TYPE_SIZE);

I figured we are missing this operator and are thus copying possibly
uninitialized data.

This means instead of a plain assignment of wide_int_storage we
get a loop here.  So I'm not 100% sure this "omission" wasn't on
purpose.  Note there already is a copy constructor implemented
in terms of wi::copy.

Bootstrap / regtest running on x86_64-unknown-linux-gnu.

Ok?

Thanks,
Richard.

2017-03-01  Richard Biener  <rguenther@suse.de>

	* wide-int.h (wide_int_storage::operator=): Implement in terms
	of wi::copy.

Index: gcc/wide-int.h
===================================================================
--- gcc/wide-int.h	(revision 245803)
+++ gcc/wide-int.h	(working copy)
@@ -1019,6 +1019,9 @@ public:
   HOST_WIDE_INT *write_val ();
   void set_len (unsigned int, bool = false);
 
+  template <typename T>
+  wide_int_storage &operator = (const T &);
+
   static wide_int from (const wide_int_ref &, unsigned int, signop);
   static wide_int from_array (const HOST_WIDE_INT *, unsigned int,
 			      unsigned int, bool = true);
@@ -1058,6 +1061,18 @@ inline wide_int_storage::wide_int_storag
   wi::copy (*this, xi);
 }
 
+template <typename T>
+inline wide_int_storage&
+wide_int_storage::operator = (const T &x)
+{
+  { STATIC_ASSERT (!wi::int_traits<T>::host_dependent_precision); }
+  { STATIC_ASSERT (wi::int_traits<T>::precision_type != wi::CONST_PRECISION); }
+  WIDE_INT_REF_FOR (T) xi (x);
+  precision = xi.precision;
+  wi::copy (*this, xi);
+  return *this;
+}
+
 inline unsigned int
 wide_int_storage::get_precision () const
 {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]