Commit eb319c50 by Martin Sebor

PR tree-optimization/88993 - GCC 9 -Wformat-overflow=2 should reflect real libc limits

PR tree-optimization/88993 - GCC 9 -Wformat-overflow=2 should reflect real libc limits
PR tree-optimization/88835 - overly aggressive -Werror=format-overflow for printf

gcc/ChangeLog:

	PR tree-optimization/88993
	PR tree-optimization/88853
	* gimple-ssa-sprintf.c (sprintf_dom_walker::call_info::is_file_func):
	New helper.
	(sprintf_dom_walker::call_info::is_string_func): New helper.
	(format_directive): Only issue "may exceed" 4095/INT_MAX warnings
	for formatted string functions.
	(sprintf_dom_walker::handle_gimple_call): Fix a typo in a comment.

gcc/testsuite/ChangeLog:

	PR tree-optimization/88993
	PR tree-optimization/88853
	* gcc.dg/tree-ssa/builtin-fprintf-warn-2.c: New test.
	* gcc.dg/tree-ssa/builtin-printf-warn-2.c: New test.
	* gcc.dg/tree-ssa/builtin-snprintf-warn-3.c: Adjust.
	* gcc.dg/tree-ssa/builtin-sprintf-warn-18.c: Same.

From-SVN: r269125
parent cfed471a
/* PR middle-end/79448 - unhelpful -Wformat-truncation=2 warning
{ dg-do compile }
{ dg-options "-O2 -Wformat -Wformat-truncation=2 -ftrack-macro-expansion=0" }
{ dg-options "-O2 -Wformat -Wformat-truncation=2 -ftrack-macro-expansion=0" }
{ dg-require-effective-target ptr32plus } */
typedef __SIZE_TYPE__ size_t;
......@@ -166,11 +166,17 @@ void test_string_checked (const char *s, const struct Arrays *ar)
T (-1, "%s%s", ar->a4k, ar->ax);
/* Verify that an array that fits a string longer than 4095 bytes
does trigger a warning. */
T (-1, "%-s", ar->a4kp1); /* { dg-warning "directive output between 0 and 4096 bytes may exceed minimum required size of 4095" } */
/* Also verify that a %s directive with width greater than 4095
triggers a warning even if the argument is not longer than 4k. */
does not trigger a warning. (No known implementation has trouble
with this). */
T (-1, "%s", ar->a4kp1);
/* Verify that a %s directive with width greater than 4095 does
trigger a warning even if the string argument is not longer
than 4k. Glibc only has trouble with directives whose width
or precision exceeds 64K or so:
https://bugzilla.redhat.com/show_bug.cgi?id=441945 *
but hardcoding that as the limit and assuming no other
implementation has a lower one seems unwise. */
T (-1, "%*s", 4096, ar->a4k); /* { dg-warning "directive output of 4096 bytes exceeds minimum required size of 4095" } */
/* Verify that precision constrains the putput and suppresses the 4k
......@@ -190,5 +196,7 @@ void test_string_checked (const char *s, const struct Arrays *ar)
T (-1, "%s %s %s", ar->a4k, ar->a4k, ar->a4k);
T (-1, "%s %s %s", ar->ax, ar->ax, ar->ax);
T (-1, "%-s", ar->amax); /* { dg-warning "directive output between 0 and \[0-9\]+ bytes may exceed minimum required size of 4095" } */
/* Similar to the above, verify there's no warning for an array
just because its size is INT_MAX bytes. */
T (-1, "%s", ar->amax);
}
......@@ -118,9 +118,9 @@ void test_width_and_precision_out_of_range (char *d)
/* The range here happens to be a property of the compiler, not
one of the target. */
T ("%9223372036854775808i", 0); /* { dg-warning "width out of range" "first" } */
/* { dg-warning "result to exceed .INT_MAX." "second" { target *-*-* } .-1 } */
/* { dg-warning "exceeds .INT_MAX." "second" { target *-*-* } .-1 } */
T ("%.9223372036854775808i", 0); /* { dg-warning "precision out of range" "first" } */
/* { dg-warning "causes result to exceed .INT_MAX." "second" { target *-*-* } .-1 } */
/* { dg-warning "exceeds .INT_MAX." "second" { target *-*-* } .-1 } */
/* The following is diagnosed by -Wformat (disabled here). */
/* T ("%9223372036854775808$i", 0); */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment