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  <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.
This commit is contained in:
Richard Biener 2022-03-28 14:55:49 +02:00
parent 3734527dfa
commit 28c5df7930
2 changed files with 15 additions and 12 deletions

View File

@ -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" } */
}

View File

@ -5858,13 +5858,8 @@ printf_strlen_execute (function *fun, bool warn_only)
strlen_optimize = !warn_only; strlen_optimize = !warn_only;
calculate_dominance_info (CDI_DOMINATORS); calculate_dominance_info (CDI_DOMINATORS);
loop_optimizer_init (LOOPS_NORMAL);
bool use_scev = optimize > 0 && flag_printf_return_value; scev_initialize ();
if (use_scev)
{
loop_optimizer_init (LOOPS_NORMAL);
scev_initialize ();
}
gcc_assert (!strlen_to_stridx); gcc_assert (!strlen_to_stridx);
if (warn_stringop_overflow || warn_stringop_truncation) if (warn_stringop_overflow || warn_stringop_truncation)
@ -5902,11 +5897,8 @@ printf_strlen_execute (function *fun, bool warn_only)
strlen_to_stridx = NULL; 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; return walker.m_cleanup_cfg ? TODO_cleanup_cfg : 0;
} }