PR middle-end/100325 - missing warning with -O0 on sprintf overflow with pointer plus offset

gcc/ChangeLog:

	* passes.def (pass_warn_printf): Run after SSA.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/builtin-sprintf-warn-26.c: New test.
This commit is contained in:
Martin Sebor 2021-05-05 11:07:39 -06:00
parent 2b71ca688b
commit 2254b3233b
2 changed files with 4 additions and 4 deletions

View File

@ -45,7 +45,6 @@ along with GCC; see the file COPYING3. If not see
NEXT_PASS (pass_warn_function_return);
NEXT_PASS (pass_coroutine_early_expand_ifns);
NEXT_PASS (pass_expand_omp);
NEXT_PASS (pass_warn_printf);
NEXT_PASS (pass_walloca, /*strict_mode_p=*/true);
NEXT_PASS (pass_build_cgraph_edges);
TERMINATE_PASS_LIST (all_lowering_passes)
@ -58,6 +57,7 @@ along with GCC; see the file COPYING3. If not see
PUSH_INSERT_PASSES_WITHIN (pass_build_ssa_passes)
NEXT_PASS (pass_fixup_cfg);
NEXT_PASS (pass_build_ssa);
NEXT_PASS (pass_warn_printf);
NEXT_PASS (pass_warn_nonnull_compare);
NEXT_PASS (pass_early_warn_uninitialized);
NEXT_PASS (pass_ubsan);

View File

@ -22,17 +22,17 @@ void nowarn_4m3 ()
void warn_2m1 ()
{
char *p = a + 2;
sprintf (p - 1, "%i", 123); // { dg-warning "-Wformat-overflow" "pr100325" { xfail *-*-* } }
sprintf (p - 1, "%i", 123); // { dg-warning "-Wformat-overflow" "pr100325" }
}
void warn_3m1 ()
{
char *p = a + 3;
sprintf (p - 1, "%i", 12); // { dg-warning "-Wformat-overflow" "pr100325" { xfail *-*-* } }
sprintf (p - 1, "%i", 12); // { dg-warning "-Wformat-overflow" "pr100325" }
}
void warn_4m1 ()
{
char *p = a + 4;
sprintf (p - 1, "%i", 1); // { dg-warning "-Wformat-overflow" "pr100325" { xfail *-*-* } }
sprintf (p - 1, "%i", 1); // { dg-warning "-Wformat-overflow" "pr100325" }
}