PR tree-optimization/80497 - ICE at -O1 and above on valid code on x86_64-linux-gnu...
authorMartin Sebor <msebor@redhat.com>
Tue, 25 Apr 2017 17:40:58 +0000 (17:40 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Tue, 25 Apr 2017 17:40:58 +0000 (11:40 -0600)
gcc/ChangeLog:

PR tree-optimization/80497
* gimple-ssa-sprintf.c (get_int_range): Avoid assuming all integer
constants are representable in HOST_WIDE_INT.
(parse_directive): Ditto.

gcc/testsuite/ChangeLog:

PR tree-optimization/80497
* gcc.dg/tree-ssa/builtin-sprintf-warn-17.c: New test.

From-SVN: r247262

gcc/ChangeLog
gcc/gimple-ssa-sprintf.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-17.c [new file with mode: 0644]

index 1c9ebbec4f15aab45bb9e2d999a67db3468bb2ea..7c549a483cbe7ec5562be87b7502637509aba710 100644 (file)
@@ -1,3 +1,10 @@
+2017-04-25  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/80497
+       * gimple-ssa-sprintf.c (get_int_range): Avoid assuming all integer
+       constants are representable in HOST_WIDE_INT.
+       (parse_directive): Ditto.
+
 2017-04-25  Martin Sebor  <msebor@redhat.com>
 
        PR bootstrap/80486
index 2e62086e2d13e2c6e565953dec028f47df74ee20..d3771ddcc67b5eb77dfa61c169b32b1b88a332e7 100644 (file)
@@ -948,7 +948,8 @@ get_int_range (tree arg, HOST_WIDE_INT *pmin, HOST_WIDE_INT *pmax,
       *pmin = tree_to_shwi (TYPE_MIN_VALUE (type));
       *pmax = tree_to_shwi (TYPE_MAX_VALUE (type));
     }
-  else if (TREE_CODE (arg) == INTEGER_CST)
+  else if (TREE_CODE (arg) == INTEGER_CST
+          && TYPE_PRECISION (TREE_TYPE (arg)) <= TYPE_PRECISION (type))
     {
       /* For a constant argument return its value adjusted as specified
         by NEGATIVE and NEGBOUND and return true to indicate that the
@@ -2916,7 +2917,9 @@ parse_directive (pass_sprintf_length::call_info &info,
       if (width != -1)
        dollar = width + info.argidx;
       else if (star_width
-              && TREE_CODE (star_width) == INTEGER_CST)
+              && TREE_CODE (star_width) == INTEGER_CST
+              && (TYPE_PRECISION (TREE_TYPE (star_width))
+                  <= TYPE_PRECISION (integer_type_node)))
        dollar = width + tree_to_shwi (star_width);
 
       /* Bail when the numbered argument is out of range (it will
index cd4d1007f7f9ce8c6460774e6800bf633c6880e3..70b5682e1a3ad42b96b960e7c96bc5ac2724fecf 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-25  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/80497
+       * gcc.dg/tree-ssa/builtin-sprintf-warn-17.c: New test.
+
 2017-04-25  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>
            Jakub Jelinek  <jakub@redhat.com>
 
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-17.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-17.c
new file mode 100644 (file)
index 0000000..27aa839
--- /dev/null
@@ -0,0 +1,42 @@
+/* PR tree-optimization/80497 - ICE at -O1 and above on valid code on
+   x86_64-linux-gnu in "tree_to_uhwi"
+   { dg-do compile }
+   { dg-options "-O2 -Wall -Wformat-overflow" }
+   { dg-require-effective-target int128 } */
+
+extern char buf[];
+
+const __int128_t sint128_max
+  = (__int128_t)1 << (sizeof sint128_max * __CHAR_BIT__ - 2);
+
+void fn0 (void)
+{
+  __int128_t si128 = 0;
+
+  __builtin_sprintf (buf, "%*i", si128, 0);
+
+  __builtin_sprintf (buf, "%.*i", si128, 0);
+
+  __builtin_sprintf (buf, "%i", si128);
+
+  __builtin_sprintf (buf, "%2$*1$i", si128, 0);
+
+  __builtin_sprintf (buf, "%2$.*1$i", si128, 0);
+}
+
+void fn1 (void)
+{
+  __int128_t si128 = sint128_max;
+
+  __builtin_sprintf (buf, "%*i", si128, 0);
+
+  __builtin_sprintf (buf, "%.*i", si128, 0);
+
+  __builtin_sprintf (buf, "%i", si128);
+
+  __builtin_sprintf (buf, "%2$*1$i", si128, 0);
+
+  __builtin_sprintf (buf, "%2$.*1$i", si128, 0);
+}
+
+/* { dg-prune-output "expects argument of type .int." } */