Commit 209042e6 by Martin Sebor Committed by Martin Sebor

PR tree-optimization/78608 - gimple-ssa-sprintf.c:570:17: runtime error:…

PR tree-optimization/78608 - gimple-ssa-sprintf.c:570:17: runtime error: negation of -9223372036854775808 cannot be represented in type 'long int'

gcc/ChangeLog:
	* gimple-ssa-sprintf.c (tree_digits): Avoid negating TYPE_MIN.

From-SVN: r244511
parent 26830c2f
2017-01-16 Martin Sebor <msebor@redhat.com>
PR tree-optimization/78608
* gimple-ssa-sprintf.c (tree_digits): Avoid negating TYPE_MIN.
2017-01-16 Jeff Law <law@redhat.com> 2017-01-16 Jeff Law <law@redhat.com>
Revert: Revert:
......
...@@ -577,16 +577,22 @@ tree_digits (tree x, int base, HOST_WIDE_INT prec, bool plus, bool prefix) ...@@ -577,16 +577,22 @@ tree_digits (tree x, int base, HOST_WIDE_INT prec, bool plus, bool prefix)
if (tree_fits_shwi_p (x)) if (tree_fits_shwi_p (x))
{ {
HOST_WIDE_INT i = tree_to_shwi (x); HOST_WIDE_INT i = tree_to_shwi (x);
if (i < 0) if (HOST_WIDE_INT_MIN == i)
{ {
absval = -i; /* Avoid undefined behavior due to negating a minimum. */
res = 1; absval = HOST_WIDE_INT_MAX;
} res = 1;
else }
{ else if (i < 0)
absval = i; {
res = plus; absval = -i;
} res = 1;
}
else
{
absval = i;
res = plus;
}
} }
else else
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment