re PR c/52952 (Wformat location info is bad (wrong column number))

gcc/c-family/ChangeLog:

2014-08-19  Manuel López-Ibáñez  <manu@gcc.gnu.org>
	    Steven Bosscher  <steven@gcc.gnu.org>

	PR c/52952
	* c-format.c: Add extra_arg_loc and format_string_loc to struct
	format_check_results.
	(check_function_format): Use true and add comment for boolean
	argument.
	(finish_dollar_format_checking): Use explicit location when warning.
	(check_format_info): Likewise.
	(check_format_arg): Set extra_arg_loc and format_string_loc.
	(check_format_info_main): Use explicit location when warning.
	(check_format_types): Pass explicit location.
	(format_type_warning): Likewise.

gcc/testsuite/ChangeLog:

2014-08-19  Manuel López-Ibáñez  <manu@gcc.gnu.org>
	    Steven Bosscher  <steven@gcc.gnu.org>

	PR c/52952
	* gcc.dg/redecl-4.c: Add column markers.
	* gcc.dg/format/bitfld-1.c: Likewise.
	* gcc.dg/format/attr-2.c: Likewise.
	* gcc.dg/format/attr-6.c: Likewise.
	* gcc.dg/format/array-1.c: Likewise.
	* gcc.dg/format/attr-7.c: Likewise.
	* gcc.dg/format/asm_fprintf-1.c: Likewise.
	* gcc.dg/format/attr-4.c: Likewise.
	* gcc.dg/format/branch-1.c: Likewise.
	* gcc.dg/format/c90-printf-1.c: Likewise.


Co-Authored-By: Steven Bosscher <steven@gcc.gnu.org>

From-SVN: r214129
parent 0f82e5c9
2014-08-19 Manuel López-Ibáñez <manu@gcc.gnu.org>
Steven Bosscher <steven@gcc.gnu.org>
PR c/52952
* c-format.c: Add extra_arg_loc and format_string_loc to struct
format_check_results.
(check_function_format): Use true and add comment for boolean
argument.
(finish_dollar_format_checking): Use explicit location when warning.
(check_format_info): Likewise.
(check_format_arg): Set extra_arg_loc and format_string_loc.
(check_format_info_main): Use explicit location when warning.
(check_format_types): Pass explicit location.
(format_type_warning): Likewise.
2014-08-15 Manuel López-Ibáñez <manu@gcc.gnu.org> 2014-08-15 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR fortran/44054 PR fortran/44054
......
2014-08-19 Manuel López-Ibáñez <manu@gcc.gnu.org>
Steven Bosscher <steven@gcc.gnu.org>
PR c/52952
* gcc.dg/redecl-4.c: Add column markers.
* gcc.dg/format/bitfld-1.c: Likewise.
* gcc.dg/format/attr-2.c: Likewise.
* gcc.dg/format/attr-6.c: Likewise.
* gcc.dg/format/array-1.c: Likewise.
* gcc.dg/format/attr-7.c: Likewise.
* gcc.dg/format/asm_fprintf-1.c: Likewise.
* gcc.dg/format/attr-4.c: Likewise.
* gcc.dg/format/branch-1.c: Likewise.
* gcc.dg/format/c90-printf-1.c: Likewise.
2014-08-18 Aldy Hernandez <aldyh@redhat.com> 2014-08-18 Aldy Hernandez <aldyh@redhat.com>
* guality/nrv-1.c: Add `used' attribute to a1. * guality/nrv-1.c: Add `used' attribute to a1.
......
...@@ -23,19 +23,19 @@ foo (int i, long l) ...@@ -23,19 +23,19 @@ foo (int i, long l)
static const char q2[] = "bar%d"; static const char q2[] = "bar%d";
printf (a1); printf (a1);
printf (a2, i); printf (a2, i);
printf (a2, l); /* { dg-warning "format" "wrong type with array" } */ printf (a2, l); /* { dg-warning "11:format" "wrong type with array" } */
printf (b1); /* { dg-warning "unterminated" "unterminated array" } */ printf (b1); /* { dg-warning "11:unterminated" "unterminated array" } */
printf (b2); /* { dg-warning "unterminated" "unterminated array" } */ printf (b2); /* { dg-warning "11:unterminated" "unterminated array" } */
printf (c1); printf (c1);
printf (c2, i); printf (c2, i);
printf (c2, l); /* { dg-warning "format" "wrong type with array" } */ printf (c2, l); /* { dg-warning "11:format" "wrong type with array" } */
printf (p1); printf (p1);
printf (p2, i); printf (p2, i);
printf (p2, l); /* { dg-warning "format" "wrong type with array" } */ printf (p2, l); /* { dg-warning "11:format" "wrong type with array" } */
printf (q1); printf (q1);
printf (q2, i); printf (q2, i);
printf (q2, l); /* { dg-warning "format" "wrong type with array" } */ printf (q2, l); /* { dg-warning "11:format" "wrong type with array" } */
/* Volatile or non-constant arrays must not be checked. */ /* Volatile or non-constant arrays must not be checked. */
printf (d); /* { dg-warning "not a string literal" "non-const" } */ printf (d); /* { dg-warning "11:not a string literal" "non-const" } */
printf ((const char *)e); /* { dg-warning "not a string literal" "volatile" } */ printf ((const char *)e); /* { dg-warning "25:not a string literal" "volatile" } */
} }
...@@ -42,39 +42,39 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, ...@@ -42,39 +42,39 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p,
asm_fprintf ("%wd%wi%wo%wu%wx%wX", ll, ll, ull, ull, ull, ull); asm_fprintf ("%wd%wi%wo%wu%wx%wX", ll, ll, ull, ull, ull, ull);
/* Standard specifiers not accepted in asm_fprintf. */ /* Standard specifiers not accepted in asm_fprintf. */
asm_fprintf ("%f\n", d); /* { dg-warning "format" "float" } */ asm_fprintf ("%f\n", d); /* { dg-warning "16:format" "float" } */
asm_fprintf ("%e\n", d); /* { dg-warning "format" "float" } */ asm_fprintf ("%e\n", d); /* { dg-warning "16:format" "float" } */
asm_fprintf ("%E\n", d); /* { dg-warning "format" "float" } */ asm_fprintf ("%E\n", d); /* { dg-warning "16:format" "float" } */
asm_fprintf ("%g\n", d); /* { dg-warning "format" "float" } */ asm_fprintf ("%g\n", d); /* { dg-warning "16:format" "float" } */
asm_fprintf ("%G\n", d); /* { dg-warning "format" "float" } */ asm_fprintf ("%G\n", d); /* { dg-warning "16:format" "float" } */
asm_fprintf ("%p\n", p); /* { dg-warning "format" "pointer" } */ asm_fprintf ("%p\n", p); /* { dg-warning "16:format" "pointer" } */
asm_fprintf ("%n\n", n); /* { dg-warning "format" "counter" } */ asm_fprintf ("%n\n", n); /* { dg-warning "16:format" "counter" } */
asm_fprintf ("%hd\n", i); /* { dg-warning "format" "conversion" } */ asm_fprintf ("%hd\n", i); /* { dg-warning "16:format" "conversion" } */
/* Various tests of bad argument types. */ /* Various tests of bad argument types. */
asm_fprintf ("%d", l); /* { dg-warning "format" "bad argument types" } */ asm_fprintf ("%d", l); /* { dg-warning "16:format" "bad argument types" } */
asm_fprintf ("%wd", l); /* { dg-warning "format" "bad argument types" } */ asm_fprintf ("%wd", l); /* { dg-warning "16:format" "bad argument types" } */
asm_fprintf ("%d", ll); /* { dg-warning "format" "bad argument types" } */ asm_fprintf ("%d", ll); /* { dg-warning "16:format" "bad argument types" } */
asm_fprintf ("%*d\n", i1, i); /* { dg-warning "format" "bad * argument types" } */ asm_fprintf ("%*d\n", i1, i); /* { dg-warning "16:format" "bad * argument types" } */
asm_fprintf ("%.*d\n", i2, i); /* { dg-warning "format" "bad * argument types" } */ asm_fprintf ("%.*d\n", i2, i); /* { dg-warning "16:format" "bad * argument types" } */
asm_fprintf ("%*.*ld\n", i1, i2, l); /* { dg-warning "format" "bad * argument types" } */ asm_fprintf ("%*.*ld\n", i1, i2, l); /* { dg-warning "16:format" "bad * argument types" } */
asm_fprintf ("%ld", i); /* { dg-warning "format" "bad argument types" } */ asm_fprintf ("%ld", i); /* { dg-warning "16:format" "bad argument types" } */
asm_fprintf ("%s", n); /* { dg-warning "format" "bad argument types" } */ asm_fprintf ("%s", n); /* { dg-warning "16:format" "bad argument types" } */
/* Wrong number of arguments. */ /* Wrong number of arguments. */
asm_fprintf ("%d%d", i); /* { dg-warning "matching" "wrong number of args" } */ asm_fprintf ("%d%d", i); /* { dg-warning "16:matching" "wrong number of args" } */
asm_fprintf ("%d", i, i); /* { dg-warning "arguments" "wrong number of args" } */ asm_fprintf ("%d", i, i); /* { dg-warning "16:arguments" "wrong number of args" } */
/* Miscellaneous bogus constructions. */ /* Miscellaneous bogus constructions. */
asm_fprintf (""); /* { dg-warning "zero-length" "warning for empty format" } */ asm_fprintf (""); /* { dg-warning "16:zero-length" "warning for empty format" } */
asm_fprintf ("\0"); /* { dg-warning "embedded" "warning for embedded NUL" } */ asm_fprintf ("\0"); /* { dg-warning "16:embedded" "warning for embedded NUL" } */
asm_fprintf ("%d\0", i); /* { dg-warning "embedded" "warning for embedded NUL" } */ asm_fprintf ("%d\0", i); /* { dg-warning "16:embedded" "warning for embedded NUL" } */
asm_fprintf ("%d\0%d", i, i); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */ asm_fprintf ("%d\0%d", i, i); /* { dg-warning "16:embedded|too many" "warning for embedded NUL" } */
asm_fprintf (NULL); /* { dg-warning "null" "null format string warning" } */ asm_fprintf (NULL); /* { dg-warning "null" "null format string warning" } */
asm_fprintf ("%"); /* { dg-warning "trailing" "trailing % warning" } */ asm_fprintf ("%"); /* { dg-warning "16:trailing" "trailing % warning" } */
asm_fprintf ("%++d", i); /* { dg-warning "repeated" "repeated flag warning" } */ asm_fprintf ("%++d", i); /* { dg-warning "16:repeated" "repeated flag warning" } */
asm_fprintf ((const char *)L"foo"); /* { dg-warning "wide" "wide string" } */ asm_fprintf ((const char *)L"foo"); /* { dg-warning "30:wide" "wide string" } */
asm_fprintf ("%s", (char *)0); /* { dg-warning "null" "%s with NULL" } */ asm_fprintf ("%s", (char *)0); /* { dg-warning "null" "%s with NULL" } */
/* Make sure we still get warnings for regular printf. */ /* Make sure we still get warnings for regular printf. */
printf ("%d\n", ll); /* { dg-warning "format" "bad argument types" } */ printf ("%d\n", ll); /* { dg-warning "11:format" "bad argument types" } */
} }
...@@ -30,7 +30,7 @@ void ...@@ -30,7 +30,7 @@ void
foo (int i, int *ip, double d) foo (int i, int *ip, double d)
{ {
tformatprintf ("%d", i); tformatprintf ("%d", i);
tformatprintf ("%"); /* { dg-warning "format" "attribute format printf" } */ tformatprintf ("%"); /* { dg-warning "18:format" "attribute format printf" } */
tformat__printf__ ("%d", i); tformat__printf__ ("%d", i);
tformat__printf__ ("%"); /* { dg-warning "format" "attribute format __printf__" } */ tformat__printf__ ("%"); /* { dg-warning "format" "attribute format __printf__" } */
tformatscanf ("%d", ip); tformatscanf ("%d", ip);
......
...@@ -16,7 +16,7 @@ void ...@@ -16,7 +16,7 @@ void
baz (int i, int *ip, double d) baz (int i, int *ip, double d)
{ {
tformatprintf0 ("%d", i); tformatprintf0 ("%d", i);
tformatprintf0 ("%"); /* { dg-warning "format" "attribute format printf case 0" } */ tformatprintf0 ("%"); /* { dg-warning "19:format" "attribute format printf case 0" } */
tformatprintf1 ("%d", i); tformatprintf1 ("%d", i);
tformatprintf1 ("%"); /* { dg-warning "format" "attribute format printf case 1" } */ tformatprintf1 ("%"); /* { dg-warning "format" "attribute format printf case 1" } */
tformatprintf2 ("%d", i); tformatprintf2 ("%d", i);
......
...@@ -17,6 +17,6 @@ ...@@ -17,6 +17,6 @@
void void
foo (const char *s, int *p) foo (const char *s, int *p)
{ {
scanf("%ld", p); /* { dg-warning "format" "implicit scanf" } */ scanf("%ld", p); /* { dg-warning "9:format" "implicit scanf" } */
/* { dg-warning "implicit" "implicit decl warning" { target *-*-* } 20 } */ /* { dg-warning "implicit" "implicit decl warning" { target *-*-* } 20 } */
} }
...@@ -18,7 +18,7 @@ baz (int i) ...@@ -18,7 +18,7 @@ baz (int i)
{ {
(*tformatprintf0) ("%d", i); (*tformatprintf0) ("%d", i);
(*tformatprintf0) ((*tformat_arg) ("%d"), i); (*tformatprintf0) ((*tformat_arg) ("%d"), i);
(*tformatprintf0) ("%"); /* { dg-warning "format" "prefix" } */ (*tformatprintf0) ("%"); /* { dg-warning "22:format" "prefix" } */
(*tformatprintf0) ((*tformat_arg) ("%")); /* { dg-warning "format" "prefix" } */ (*tformatprintf0) ((*tformat_arg) ("%")); /* { dg-warning "format" "prefix" } */
(*tformatprintf1) ("%d", i); (*tformatprintf1) ("%d", i);
(*tformatprintf1) ((*tformat_arg) ("%d"), i); (*tformatprintf1) ((*tformat_arg) ("%d"), i);
......
...@@ -46,6 +46,6 @@ foo (void) ...@@ -46,6 +46,6 @@ foo (void)
printf ("%ld%lu", x.u32, x.u32); printf ("%ld%lu", x.u32, x.u32);
printf ("%ld%lu", x.s32, x.s32); printf ("%ld%lu", x.s32, x.s32);
#endif #endif
printf ("%llu", x.u48); /* { dg-warning "has type '.*unsigned int:48'" } */ printf ("%llu", x.u48); /* { dg-warning "11:has type '.*unsigned int:48'" } */
printf ("%llu", (unsigned long long)x.u48); printf ("%llu", (unsigned long long)x.u48);
} }
...@@ -9,19 +9,20 @@ void ...@@ -9,19 +9,20 @@ void
foo (long l, int nfoo) foo (long l, int nfoo)
{ {
printf ((nfoo > 1) ? "%d foos" : "%d foo", nfoo); printf ((nfoo > 1) ? "%d foos" : "%d foo", nfoo);
printf ((l > 1) ? "%d foos" : "%d foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */ printf ((l > 1) ? "%d foos" /* { dg-warning "21:int" "wrong type in conditional expr" } */
printf ((l > 1) ? "%ld foos" : "%d foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */ : "%d foo", l); /* { dg-warning "14:int" "wrong type in conditional expr" } */
printf ((l > 1) ? "%d foos" : "%ld foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */ printf ((l > 1) ? "%ld foos" : "%d foo", l); /* { dg-warning "34:int" "wrong type in conditional expr" } */
printf ((l > 1) ? "%d foos" : "%ld foo", l); /* { dg-warning "21:int" "wrong type in conditional expr" } */
/* Should allow one case to have extra arguments. */ /* Should allow one case to have extra arguments. */
printf ((nfoo > 1) ? "%d foos" : "1 foo", nfoo); printf ((nfoo > 1) ? "%d foos" : "1 foo", nfoo);
printf ((nfoo > 1) ? "many foos" : "1 foo", nfoo); /* { dg-warning "too many" "too many args in all branches" } */ printf ((nfoo > 1) ? "many foos" : "1 foo", nfoo); /* { dg-warning "38:too many" "too many args in all branches" } */
printf ((nfoo > 1) ? "%d foos" : "", nfoo); printf ((nfoo > 1) ? "%d foos" : "", nfoo);
printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "1 foo" : "no foos"), nfoo); printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "1 foo" : "no foos"), nfoo);
printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo); printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo);
printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%ld foos"), nfoo); /* { dg-warning "long int" "wrong type" } */ printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%ld foos"), nfoo); /* { dg-warning "61:long int" "wrong type" } */
printf ((nfoo > 1) ? "%ld foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo); /* { dg-warning "long int" "wrong type" } */ printf ((nfoo > 1) ? "%ld foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo); /* { dg-warning "24:long int" "wrong type" } */
printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%ld foo" : "%d foos"), nfoo); /* { dg-warning "long int" "wrong type" } */ printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%ld foo" : "%d foos"), nfoo); /* { dg-warning "50:long int" "wrong type" } */
/* Extra arguments to NULL should be complained about. */ /* Extra arguments to NULL should be complained about. */
printf (NULL, "foo"); /* { dg-warning "too many" "NULL extra args" } */ printf (0, "foo"); /* { dg-warning "14:too many" "NULL extra args" } */
/* { dg-warning "null" "null format arg" { target *-*-* } 25 } */ /* { dg-warning "null" "null format arg" { target *-*-* } 26 } */
} }
...@@ -14,7 +14,8 @@ f (void) ...@@ -14,7 +14,8 @@ f (void)
int strcmp (); int strcmp ();
/* Should get format warnings even though the built-in declaration /* Should get format warnings even though the built-in declaration
isn't "visible". */ isn't "visible". */
printf ("%s", 1); /* { dg-warning "format" } */ printf (
"%s", 1); /* { dg-warning "6:format" } */
/* The type of strcmp here should have no prototype. */ /* The type of strcmp here should have no prototype. */
if (0) if (0)
strcmp (1); strcmp (1);
......
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