From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 6B5D6388460D; Tue, 29 Mar 2022 06:15:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B5D6388460D MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7870] tree-optimization/105080 - make sure SCEV is available for ranger X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 3734527dfa0d10a50aee2f088d37320000fd65bf X-Git-Newrev: 28c5df79300ab354cbc381aab200f7c2bd0331ad Message-Id: <20220329061501.6B5D6388460D@sourceware.org> Date: Tue, 29 Mar 2022 06:15:01 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Mar 2022 06:15:01 -0000 https://gcc.gnu.org/g:28c5df79300ab354cbc381aab200f7c2bd0331ad commit r12-7870-g28c5df79300ab354cbc381aab200f7c2bd0331ad Author: Richard Biener Date: Mon Mar 28 14:55:49 2022 +0200 tree-optimization/105080 - make sure SCEV is available for ranger 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. 2022-03-28 Richard Biener PR tree-optimization/105080 * tree-ssa-strlen.cc (printf_strlen_execute): Always init loops and SCEV. * gcc.dg/pr105080.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/pr105080.c | 11 +++++++++++ gcc/tree-ssa-strlen.cc | 16 ++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) 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; }