diff options
author | msebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-01-17 00:14:52 +0000 |
---|---|---|
committer | msebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-01-17 00:14:52 +0000 |
commit | a61df77a67ef0daf34a3299cb1004465dc779b37 (patch) | |
tree | 03a1bb0b97bc037879fb4d8de2867702ae95f24a /gcc/gimple-ssa-sprintf.c | |
parent | 33f5262e51b4de83e8dc8a191713ccd321d9e04f (diff) | |
download | gcc-a61df77a67ef0daf34a3299cb1004465dc779b37.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@244511 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gimple-ssa-sprintf.c')
-rw-r--r-- | gcc/gimple-ssa-sprintf.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c index 262857c64de..76e851231d6 100644 --- a/gcc/gimple-ssa-sprintf.c +++ b/gcc/gimple-ssa-sprintf.c @@ -577,16 +577,22 @@ tree_digits (tree x, int base, HOST_WIDE_INT prec, bool plus, bool prefix) if (tree_fits_shwi_p (x)) { HOST_WIDE_INT i = tree_to_shwi (x); - if (i < 0) - { - absval = -i; - res = 1; - } - else - { - absval = i; - res = plus; - } + 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; + } + else + { + absval = i; + res = plus; + } } else return -1; |