]> gcc.gnu.org Git - gcc.git/commitdiff
re PR middle-end/82123 (spurious -Wformat-overflow warning for converted vars)
authorJeff Law <law@redhat.com>
Tue, 20 Feb 2018 18:59:22 +0000 (11:59 -0700)
committerJeff Law <law@gcc.gnu.org>
Tue, 20 Feb 2018 18:59:22 +0000 (11:59 -0700)
PR middle-end/82123
PR tree-optimization/81592
PR middle-end/79257
* gimple-ssa-sprintf.c (format_integer): Query EVRP range analyzer
for range data rather than using global data.

* gcc.dg/pr81592.c: New test.
* gcc.dg/pr82123.c: New test.

From-SVN: r257857

gcc/ChangeLog
gcc/gimple-ssa-sprintf.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr81592.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr82123.c [new file with mode: 0644]

index 161c9aa50519da9043bc4f037dad34f0653e0d11..77d0dc3a3de3ecfdb084175959002d590a8eb9c6 100644 (file)
@@ -3,6 +3,8 @@
        PR middle-end/82123
        PR tree-optimization/81592
        PR middle-end/79257
+       * gimple-ssa-sprintf.c (format_integer): Query EVRP range analyzer
+       for range data rather than using global data.
        * gimple-ssa-sprintf.c (get_int_range): Query EVRP range analyzer for
        range data rather than using global data.
        * gimple-ssa-sprintf.c (get_int_range): Accept vr_values parameter
index b3ffaec3ba62e272a7db85aa2a7dc321e87bb072..1189d9fea35e22eefe7072ada5a88688310e07ac 100644 (file)
@@ -1451,12 +1451,13 @@ format_integer (const directive &dir, tree arg, vr_values *vr_values)
     {
       /* Try to determine the range of values of the integer argument
         (range information is not available for pointers).  */
-      wide_int min, max;
-      enum value_range_type range_type = get_range_info (arg, &min, &max);
-      if (range_type == VR_RANGE)
+      value_range *vr = vr_values->get_value_range (arg);
+      if (vr->type == VR_RANGE
+         && TREE_CODE (vr->min) == INTEGER_CST
+         && TREE_CODE (vr->max) == INTEGER_CST)
        {
-         argmin = wide_int_to_tree (argtype, min);
-         argmax = wide_int_to_tree (argtype, max);
+         argmin = vr->min;
+         argmax = vr->max;
 
          /* Set KNOWNRANGE if the argument is in a known subrange
             of the directive's type and neither width nor precision
@@ -1469,11 +1470,12 @@ format_integer (const directive &dir, tree arg, vr_values *vr_values)
          res.argmin = argmin;
          res.argmax = argmax;
        }
-      else if (range_type == VR_ANTI_RANGE)
+      else if (vr->type == VR_ANTI_RANGE)
        {
          /* Handle anti-ranges if/when bug 71690 is resolved.  */
        }
-      else if (range_type == VR_VARYING)
+      else if (vr->type == VR_VARYING
+              || vr->type == VR_UNDEFINED)
        {
          /* The argument here may be the result of promoting the actual
             argument to int.  Try to determine the type of the actual
index 6351dd56db771bfa05d96d17ca07809fb1452342..035e48d16c5717119463e356eb5843f055207bdb 100644 (file)
@@ -9,6 +9,8 @@
         PR middle-end/82123
         PR tree-optimization/81592
         PR middle-end/79257
+       * gcc.dg/pr81592.c: New test.
+       * gcc.dg/pr82123.c: New test.
        * gcc.dg/builtin-unreachable-6.c: Turn off VRP.
 
 2018-02-20  Jakub Jelinek  <jakub@redhat.com>
diff --git a/gcc/testsuite/gcc.dg/pr81592.c b/gcc/testsuite/gcc.dg/pr81592.c
new file mode 100644 (file)
index 0000000..a37703a
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall -fno-strict-overflow  -Wstrict-overflow=2 -fsanitize=signed-integer-overflow" } */
+
+#include <stdio.h>
+
+int proc_keys_show(long expiry, long now)
+{
+       unsigned long timo;
+       char xbuf[4];
+
+       if (now < expiry) {
+               timo = expiry - now;
+               if (timo < 60)
+                       sprintf(xbuf, "%lus", timo);
+       }
+
+       return 0;
+}
+
+
diff --git a/gcc/testsuite/gcc.dg/pr82123.c b/gcc/testsuite/gcc.dg/pr82123.c
new file mode 100644 (file)
index 0000000..34109f1
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wformat-overflow=1" } */
+
+void acpi_gpiochip_request_interrupt(unsigned short s)
+{
+        char name[3];
+       unsigned int pin = s;
+
+       if (pin <= 255)
+               __builtin_sprintf(name, "%02X", pin);
+}
+
This page took 0.094038 seconds and 5 git commands to generate.