From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Cc: msebor@redhat.com, Jakub Jelinek <jakub@redhat.com>
Subject: [PATCH] tree-optimization/105080 - make sure SCEV is available for ranger
Date: Mon, 28 Mar 2022 15:16:24 +0200 (CEST) [thread overview]
Message-ID: <20220328131625.05BFC13215@imap2.suse-dmz.suse.de> (raw)
When doing format diagnostics at -O0 we should make sure to make
SCEV available to avoid false positives due to ranges we otherwise
can trivially compute.
Bootstrap and regtest running on x86_64-unknown-linux-gnu.
OK if that succeeds?
Thanks,
Richard.
2022-03-28 Richard Biener <rguenther@suse.de>
PR tree-optimization/105080
* tree-ssa-strlen.cc (printf_strlen_execute): Always init
loops and SCEV.
* gcc.dg/pr105080.c: New testcase.
---
gcc/testsuite/gcc.dg/pr105080.c | 11 +++++++++++
gcc/tree-ssa-strlen.cc | 16 ++++------------
2 files changed, 15 insertions(+), 12 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr105080.c
diff --git a/gcc/testsuite/gcc.dg/pr105080.c b/gcc/testsuite/gcc.dg/pr105080.c
new file mode 100644
index 00000000000..77ee7eeb396
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr105080.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O0 -Wall" } */
+
+int main()
+{
+ char foo[3];
+ int i;
+
+ for (i = 0; i < 16; i++)
+ __builtin_snprintf(foo, sizeof(foo), "%d", i); /* { dg-bogus "truncated" } */
+}
diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc
index 112f0dce874..b2556366214 100644
--- a/gcc/tree-ssa-strlen.cc
+++ b/gcc/tree-ssa-strlen.cc
@@ -5858,13 +5858,8 @@ printf_strlen_execute (function *fun, bool warn_only)
strlen_optimize = !warn_only;
calculate_dominance_info (CDI_DOMINATORS);
-
- bool use_scev = optimize > 0 && flag_printf_return_value;
- if (use_scev)
- {
- loop_optimizer_init (LOOPS_NORMAL);
- scev_initialize ();
- }
+ loop_optimizer_init (LOOPS_NORMAL);
+ scev_initialize ();
gcc_assert (!strlen_to_stridx);
if (warn_stringop_overflow || warn_stringop_truncation)
@@ -5902,11 +5897,8 @@ printf_strlen_execute (function *fun, bool warn_only)
strlen_to_stridx = NULL;
}
- if (use_scev)
- {
- scev_finalize ();
- loop_optimizer_finalize ();
- }
+ scev_finalize ();
+ loop_optimizer_finalize ();
return walker.m_cleanup_cfg ? TODO_cleanup_cfg : 0;
}
--
2.34.1
next reply other threads:[~2022-03-28 13:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-28 13:16 Richard Biener [this message]
2022-03-28 13:21 ` Jakub Jelinek
2022-03-28 13:26 ` Richard Biener
2022-03-28 13:29 ` Richard Biener
2022-03-28 13:38 ` Jakub Jelinek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220328131625.05BFC13215@imap2.suse-dmz.suse.de \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=msebor@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).