This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Add wide_int_storage::operator=
- From: Richard Biener <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Cc: richard dot sandiford at arm dot com
- Date: Wed, 1 Mar 2017 13:08:58 +0100 (CET)
- Subject: [PATCH] Add wide_int_storage::operator=
- Authentication-results: sourceware.org; auth=none
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
{