re PR middle-end/85598 (Incorrect -Wformat-truncation in a loop only at -O2 and -O3)
authorAldy Hernandez <aldyh@redhat.com>
Fri, 22 Feb 2019 13:46:01 +0000 (13:46 +0000)
committerAldy Hernandez <aldyh@gcc.gnu.org>
Fri, 22 Feb 2019 13:46:01 +0000 (13:46 +0000)
PR middle-end/85598
* gimple-ssa-sprintf.c (pass_sprintf_length::execute): Enable loop
analysis for pass.

From-SVN: r269115

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

index c4d16b9b70a88aaa3eb44c5c5589a02246803f40..9d79670582d96c17e45847c915f51abf96dca102 100644 (file)
@@ -1,3 +1,9 @@
+2019-02-22  Aldy Hernandez  <aldyh@redhat.com>
+
+       PR middle-end/85598
+       * gimple-ssa-sprintf.c (pass_sprintf_length::execute): Enable loop
+       analysis for pass.
+
 2019-02-22  Thiago Macieira  <thiago.macieira@intel.com>
 
        PR target/89444
index 8e6016fc42f3dfcec31fc93a1dea8680373d00ba..4fe666ff0de94d898656d92f0fdfbf3445fc6c49 100644 (file)
@@ -65,6 +65,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-propagate.h"
 #include "calls.h"
 #include "cfgloop.h"
+#include "tree-scalar-evolution.h"
+#include "tree-ssa-loop.h"
 #include "intl.h"
 #include "langhooks.h"
 
@@ -4200,10 +4202,22 @@ pass_sprintf_length::execute (function *fun)
   init_target_to_host_charmap ();
 
   calculate_dominance_info (CDI_DOMINATORS);
+  bool use_scev = optimize > 0 && flag_printf_return_value;
+  if (use_scev)
+    {
+      loop_optimizer_init (LOOPS_NORMAL);
+      scev_initialize ();
+    }
 
   sprintf_dom_walker sprintf_dom_walker;
   sprintf_dom_walker.walk (ENTRY_BLOCK_PTR_FOR_FN (fun));
 
+  if (use_scev)
+    {
+      scev_finalize ();
+      loop_optimizer_finalize ();
+    }
+
   /* Clean up object size info.  */
   fini_object_sizes ();
   return 0;
diff --git a/gcc/testsuite/gcc.dg/pr85598.c b/gcc/testsuite/gcc.dg/pr85598.c
new file mode 100644 (file)
index 0000000..c84b63f
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall" } */
+
+typedef __SIZE_TYPE__ size_t;
+extern void __chk_fail (void);
+extern int snprintf (char *, size_t, const char *, ...);
+
+int main()
+{
+    char temp[100];
+    unsigned int x;
+    char *str = temp;
+    for(x=0; x<256; ++x) {
+      snprintf(str, 4, "%%%02X", x);
+    }
+}