diff mbox

Add wide_int_storage::operator=

Message ID alpine.LSU.2.20.1703011306070.30051@zhemvz.fhfr.qr
State New
Headers show

Commit Message

Richard Biener March 1, 2017, 12:08 p.m. UTC
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.

Comments

Jakub Jelinek March 1, 2017, 12:14 p.m. UTC | #1
On Wed, Mar 01, 2017 at 01:08:58PM +0100, Richard Biener wrote:
> 
> In debugging a -Wuninitialized issue from ipa-cp.c which does
> 
>               vr.min = vr.max = wi::zero (INT_TYPE_SIZE);

Note maybe it would be faster to:
	vr.min = wi::zero (INT_TYPE_SIZE);
	vr.max = wi::zero (INT_TYPE_SIZE);

That doesn't mean your wide-int.h change isn't useful.

	Jakub
Richard Biener March 1, 2017, 12:18 p.m. UTC | #2
On Wed, 1 Mar 2017, Jakub Jelinek wrote:

> On Wed, Mar 01, 2017 at 01:08:58PM +0100, Richard Biener wrote:
> > 
> > In debugging a -Wuninitialized issue from ipa-cp.c which does
> > 
> >               vr.min = vr.max = wi::zero (INT_TYPE_SIZE);
> 
> Note maybe it would be faster to:
> 	vr.min = wi::zero (INT_TYPE_SIZE);
> 	vr.max = wi::zero (INT_TYPE_SIZE);
> 
> That doesn't mean your wide-int.h change isn't useful.

Note that rewriting like above doesn't fix the warning.  The issue
is from

generic_wide_int<storage>& generic_wide_int<T>::operator=(const T&) [with 
T = wi::hwi_with_prec; storage = wide_int_storage] (struct 
generic_wide_int * const this, const struct hwi_with_prec & x)
{
  struct wide_int_storage D.47458;
  struct generic_wide_int & D.52104;

  wide_int_storage::wide_int_storage<wi::hwi_with_prec> (&D.47458, x);
  try
    {
      this->D.16244 = D.47458;

where wide_int_storage::wide_int_storage<wi::hwi_with_prec> (&D.47458, x)
doesn't initialize all of wide_int_storage (but only up to len).

Richard.
diff mbox

Patch

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
 {