On 07/03/2018 04:50 PM, Martin Sebor wrote:
> In computing the size of expected output for non-constant floating
> arguments the sprintf pass doesn't consider the possibility that
> the argument value may be not finite (i.e., it can be infinity or
> NaN). Infinities and NaNs are formatted as "inf" or "infinity"
> and "nan". As a result, any floating directive can produce as
> few bytes on output as three for an non-finite argument, when
> the least amount directives such as %f produce for finite
> arguments is 8.
>
> The attached patch adjusts the floating point code to correctly
> reflect the lower bound.
>
> Martin
>
> gcc-86274.diff
>
>
> PR tree-optimization/86274 - SEGFAULT when logging std::to_string(NAN)
>
> gcc/ChangeLog:
>
> PR tree-optimization/86274
> * gimple-ssa-sprintf.c (fmtresult::type_max_digits): Verify
> precondition.
> (format_floating): Correct handling of infinities and NaNs.
>
> gcc/testsuite/ChangeLog:
>
> PR tree-optimization/86274
> * gcc.dg/tree-ssa/builtin-sprintf-9.c: New test.
> * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Adjust.
> * gcc.dg/tree-ssa/builtin-sprintf-warn-10.c: Same.
> * gcc.dg/tree-ssa/builtin-sprintf-warn-15.c: Same.
> * gcc.dg/tree-ssa/builtin-sprintf-warn-7.c: Same.
> * gcc.dg/tree-ssa/builtin-sprintf.c: Same.
> * gcc.dg/tree-ssa/pr83198.c: Same.
OK
jeff