This is the mail archive of the
mailing list for the GCC project.
Re: PR 63427: Missing wrapping operation in wi::from_mpz
- From: Jeff Law <law at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, mikestump at comcast dot net, zadeck at naturalbridge dot com, rdsandiford at googlemail dot com
- Date: Mon, 23 Feb 2015 15:44:49 -0700
- Subject: Re: PR 63427: Missing wrapping operation in wi::from_mpz
- Authentication-results: sourceware.org; auth=none
- References: <8761ascmqh dot fsf at googlemail dot com>
On 02/23/15 15:00, Richard Sandiford wrote:
The comment for wi::from_mpz says:
/* Returns X converted to TYPE. If WRAP is true, then out-of-range
values of VAL will be wrapped; otherwise, they will be set to the
appropriate minimum or maximum TYPE bound. */
The problem in PR 63427 was that we didn't actually implement the WRAP
case; we just read the whole thing into a wide_int and hoped that it
was already in range of the target precision. In the testcase this
resulted in the "len" field being too big for the precision, which
"only" showed up as a failure when ubsan was enabled. But in more
extreme cases we could walk well beyond the end up of the buffer,
as shown by a segfault in the attached testcase.
Tested on x86_64-linux-gnu. OK to install?
* wide-int.cc (wi::from_mpz): Cope with unwrapped values that are
too big for a wide_int. Implement missing wrapping operation.
* gfortran.dg/integer_exponentiation_6.F90: New test.