[Bug middle-end/87041] [8/9 Regression] GCC 8 regression: -Wformat "reading through null pointer" on unreachable code
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87041 --- Comment #10 from Martin Sebor --- Author: msebor Date: Tue Oct 30 21:58:35 2018 New Revision: 265648 URL: https://gcc.gnu.org/viewcvs?rev=265648=gcc=rev Log: PR middle-end/87041 - -Wformat reading through null pointer on unreachable code gcc/ChangeLog: PR middle-end/87041 * gimple-ssa-sprintf.c (format_directive): Use %G to include inlining context. (sprintf_dom_walker::compute_format_length): Avoid setting POSUNDER4K here. (get_destination_size): Handle null argument values. (get_user_idx_format): New function. (sprintf_dom_walker::handle_gimple_call): Handle all printf-like functions, including user-defined with attribute format printf. Use %G to include inlining context. Set POSUNDER4K here. gcc/c-family/ChangeLog: PR middle-end/87041 * c-format.c (check_format_types): Avoid diagnosing null pointer arguments to printf-family of functions. gcc/testsuite/ChangeLog: PR middle-end/87041 * gcc.c-torture/execute/fprintf-2.c: New test. * gcc.c-torture/execute/printf-2.c: Same. * gcc.c-torture/execute/user-printf.c: Same. * gcc.dg/tree-ssa/builtin-fprintf-warn-1.c: Same. * gcc.dg/tree-ssa/builtin-printf-2.c: Same. * gcc.dg/tree-ssa/builtin-printf-warn-1.c: Same. * gcc.dg/tree-ssa/user-printf-warn-1.c: Same. Added: trunk/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c trunk/gcc/testsuite/gcc.c-torture/execute/printf-2.c trunk/gcc/testsuite/gcc.c-torture/execute/user-printf.c trunk/gcc/testsuite/gcc.dg/tree-ssa/builtin-fprintf-warn-1.c trunk/gcc/testsuite/gcc.dg/tree-ssa/builtin-printf-2.c trunk/gcc/testsuite/gcc.dg/tree-ssa/builtin-printf-warn-1.c trunk/gcc/testsuite/gcc.dg/tree-ssa/user-printf-warn-1.c Modified: trunk/gcc/ChangeLog trunk/gcc/c-family/ChangeLog trunk/gcc/c-family/c-format.c trunk/gcc/gimple-ssa-sprintf.c trunk/gcc/testsuite/ChangeLog
[Bug middle-end/87041] [8/9 Regression] GCC 8 regression: -Wformat "reading through null pointer" on unreachable code
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87041 --- Comment #9 from Andrew Church --- Trunk r265614 with the patch from comment #8 no longer emits spurious warnings from -Wformat for all of my cases which previously triggered such warnings. Thanks for the patch.
[Bug middle-end/87041] [8/9 Regression] GCC 8 regression: -Wformat "reading through null pointer" on unreachable code
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87041 Martin Sebor changed: What|Removed |Added Keywords||patch --- Comment #8 from Martin Sebor --- Patch: https://gcc.gnu.org/ml/gcc-patches/2018-10/msg01860.html
[Bug middle-end/87041] [8/9 Regression] GCC 8 regression: -Wformat "reading through null pointer" on unreachable code
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87041 Martin Sebor changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org --- Comment #7 from Martin Sebor --- Testing a patch.
[Bug middle-end/87041] [8/9 Regression] GCC 8 regression: -Wformat "reading through null pointer" on unreachable code
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87041 --- Comment #6 from Martin Sebor --- -Wformat-overflow already warns for null pointers. I don't recall any bug reports about it so it shouldn't be too bad. void f (char *d, char *p) { if (p) return; __builtin_sprintf (d, "%s", p); } warning: ā%sā directive argument is null [-Wformat-overflow=] __builtin_sprintf (d, "%s", p);
[Bug middle-end/87041] [8/9 Regression] GCC 8 regression: -Wformat "reading through null pointer" on unreachable code
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87041 --- Comment #5 from Jakub Jelinek --- I don't think we want to move it there, that will mean lots of false positives due to jump threading etc. It is a good thing this is a FE warning.
[Bug middle-end/87041] [8/9 Regression] GCC 8 regression: -Wformat "reading through null pointer" on unreachable code
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87041 Martin Sebor changed: What|Removed |Added CC||msebor at gcc dot gnu.org --- Comment #4 from Martin Sebor --- Moving the null warning to the sprintf pass (and extending the latter to also handle {f,}printf as well) would solve the problem and help detect many other kinds of bugs a front-end warning can't.
[Bug middle-end/87041] [8/9 Regression] GCC 8 regression: -Wformat "reading through null pointer" on unreachable code
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87041 --- Comment #3 from Andrew Church --- I agree it's a good idea to warn if the code is reachable, but if not, it's only so much noise. I can see that in this case the second const makes no difference to code generation, but I'd prefer not to modify the macro since doing so would go against the style of related code, which does in fact use *const where appropriate to ensure pointer variables are not inadvertently changed. I'd also be a bit concerned that future changes to dataflow analysis or optimization passes could trigger the warning even without the const, at which point it would be less trivial to work around.
[Bug middle-end/87041] [8/9 Regression] GCC 8 regression: -Wformat "reading through null pointer" on unreachable code
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87041 --- Comment #2 from Jakub Jelinek --- That change just improved the constant folding. In C++ which has done that constant folding forever we don't warn, because check_format_arguments is called with the non-folded original arguments (though, before delayed folding - r217814 - C++ warned about this). Though, for this case I'd think it is a good think to warn about const char *const p = NULL; printf ("%s\n", p); My suggestion is if you don't want this warning don't use const on the variables, it doesn't improve the generated code when optimizing, so the only advantage of it is making sure you inside of the macro don't try to change the value of the variables.
[Bug middle-end/87041] [8/9 Regression] GCC 8 regression: -Wformat "reading through null pointer" on unreachable code
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87041 Richard Biener changed: What|Removed |Added Keywords||diagnostic Target Milestone|--- |8.3 Summary|GCC 8 regression: -Wformat |[8/9 Regression] GCC 8 |"reading through null |regression: -Wformat |pointer" on unreachable |"reading through null |code|pointer" on unreachable ||code