aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2019-02-22 13:46:01 +0000
committerAldy Hernandez <aldyh@gcc.gnu.org>2019-02-22 13:46:01 +0000
commit965779b4ad0f0abbdc8ab0addd2fae14165a08f4 (patch)
treee9705216db4985528e7cd40aff61fcbb03f371f6 /gcc
parentc94500335251e83ccee1ef096f0a63e97834258a (diff)
downloadgcc-965779b4ad0f0abbdc8ab0addd2fae14165a08f4.zip
gcc-965779b4ad0f0abbdc8ab0addd2fae14165a08f4.tar.gz
gcc-965779b4ad0f0abbdc8ab0addd2fae14165a08f4.tar.bz2
re PR middle-end/85598 (Incorrect -Wformat-truncation in a loop only at -O2 and -O3)
PR middle-end/85598 * gimple-ssa-sprintf.c (pass_sprintf_length::execute): Enable loop analysis for pass. From-SVN: r269115
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/gimple-ssa-sprintf.c14
-rw-r--r--gcc/testsuite/gcc.dg/pr85598.c16
3 files changed, 36 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c4d16b9..9d79670 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index 8e6016f..4fe666f 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -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
index 0000000..c84b63f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr85598.c
@@ -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);
+ }
+}