summaryrefslogtreecommitdiff
path: root/gcc/gimple-ssa-sprintf.c
diff options
context:
space:
mode:
authormsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>2017-01-17 00:14:52 +0000
committermsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>2017-01-17 00:14:52 +0000
commita61df77a67ef0daf34a3299cb1004465dc779b37 (patch)
tree03a1bb0b97bc037879fb4d8de2867702ae95f24a /gcc/gimple-ssa-sprintf.c
parent33f5262e51b4de83e8dc8a191713ccd321d9e04f (diff)
downloadgcc-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.c26
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;