[Bug tree-optimization/78608] gimple-ssa-sprintf.c:570:17: runtime error: negation of -9223372036854775808 cannot be represented in type 'long int'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78608 Martin Sebor changed: What|Removed |Added Keywords|ice-on-invalid-code |patch --- Comment #5 from Martin Sebor --- A bigger patch that addresses a number of overflow-related problems has been posted for review: https://gcc.gnu.org/ml/gcc-patches/2016-12/msg00262.html
[Bug tree-optimization/78608] gimple-ssa-sprintf.c:570:17: runtime error: negation of -9223372036854775808 cannot be represented in type 'long int'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78608 --- Comment #4 from Markus Trippelsdorf --- The patch fixes all issue that I came across. Please apply your patch. Thanks.
[Bug tree-optimization/78608] gimple-ssa-sprintf.c:570:17: runtime error: negation of -9223372036854775808 cannot be represented in type 'long int'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78608 --- Comment #3 from Martin Sebor --- I suspect the same problem should come up with a call to vsprintf. The patch below should handle this case but I haven't don't done a bootstrap-ubsan to verify there are no others like it. diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c index eceed3e..2b0781a 100644 --- a/gcc/gimple-ssa-sprintf.c +++ b/gcc/gimple-ssa-sprintf.c @@ -565,7 +565,13 @@ tree_digits (tree x, int base, bool plus, bool prefix) if (tree_fits_shwi_p (x)) { HOST_WIDE_INT i = tree_to_shwi (x); - if (i < 0) + if (HOST_WIDE_INT_MIN == i) + { + /* Avoid undefined behavior due to negating a minimum. */ + absval = HOST_WIDE_INT_MAX; + res = 1; + } + else if (i < 0) { absval = -i; res = 1;
[Bug tree-optimization/78608] gimple-ssa-sprintf.c:570:17: runtime error: negation of -9223372036854775808 cannot be represented in type 'long int'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78608 Martin Sebor changed: What|Removed |Added Keywords||ice-on-invalid-code Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org Known to fail||7.0 --- Comment #2 from Martin Sebor --- Thanks for the test case. The code is invalid but GCC should handle it gracefully.
[Bug tree-optimization/78608] gimple-ssa-sprintf.c:570:17: runtime error: negation of -9223372036854775808 cannot be represented in type 'long int'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78608 Markus Trippelsdorf changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2016-12-01 Ever confirmed|0 |1 --- Comment #1 from Markus Trippelsdorf --- % echo 'void foo() { __builtin_snprintf(0, 0, "%ld"); }' | gcc -x c -c -O2 -o /dev/null - gimple-ssa-sprintf.c:570:17: runtime error: negation of -9223372036854775808 cannot be represented in type 'long int'; cast to an unsigned type to negate this value to itself