On 12/13/2016 09:07 PM, Martin Sebor wrote:
In a discussion of my patch for bug 78696 I mentioned I had found
a bug/limitation in MPFR that causes GCC to allocate excessive
amounts of memory on some corner cases (very large precision).
https://gcc.gnu.org/ml/gcc-patches/2016-12/msg01098.html
I've since raised GCC bug 78786 for the GCC problem and discussed
the MPFR issues with the library's maintainer. The attached patch
tweaks GCC to avoid triggering the MPFR problem.
There is some overlap with the attached patch and the one posted
for bug 78608 (fix integer overflow bugs in gimple-ssa-sprintf.c)
that will need to be resolved. The latter patch also fixes some
more bugs in some esoteric corner cases having to do with flags
that this patch doesn't attempt to handle.
Martin
gcc-78786.diff
PR middle-end/78786 - GCC hangs/out of memory calling sprintf with large
precision
gcc/ChangeLog:
PR middle-end/78786
* gimple-ssa-sprintf.c (target_dir_max): New macro.
(get_mpfr_format_length): New function.
(format_integer): Use HOST_WIDE_INT instead of int.
(format_floating_max): Same.
(format_floating): Call get_mpfr_format_length.
(format_directive): Use target_dir_max.
gcc/testsuite/ChangeLog:
PR middle-end/78786
* gcc.dg/tree-ssa/builtin-sprintf-warn-7.c: New test.
Index: gcc/gimple-ssa-sprintf.c
+ /* Adjust the retrun value by the difference. */
s/retrun/return/
As you note there's some overlap between this patch and the 78608 which
I need to take another look at.
If this patch is safe as-is and has been through the usual bootstrap and
regression testing on its own, then it can go in now with the nit above
fixed.
Jeff