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

gcc/testsuite/ChangeLog:

2015-05-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR c/52952
	* gcc.dg/redecl-4.c: Update column numbers.
	* gcc.dg/format/bitfld-1.c: Likewise.
	* gcc.dg/format/attr-2.c: Likewise.
	* gcc.dg/format/attr-6.c: Likewise.
	* gcc.dg/format/attr-7.c (baz): 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. Add tests for column
	locations within strings with embedded escape sequences.

gcc/c-family/ChangeLog:

2015-05-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>
	
	PR c/52952
	* c-format.c (location_column_from_byte_offset): New.
	(location_from_offset): New.
	(struct format_wanted_type): Add offset_loc field.
	(check_format_info): Move handling of location for extra arguments
	closer to the point of warning.
	(check_format_info_main): Pass the result of location_from_offset
	to warning_at.
	(format_type_warning): Pass the result of location_from_offset
	to warning_at.

From-SVN: r223470
parent a4f238b6
2015-05-21 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c/52952
* c-format.c (location_column_from_byte_offset): New.
(location_from_offset): New.
(struct format_wanted_type): Add offset_loc field.
(check_format_info): Move handling of location for extra arguments
closer to the point of warning.
(check_format_info_main): Pass the result of location_from_offset
to warning_at.
(format_type_warning): Pass the result of location_from_offset
to warning_at.
2015-05-20 Marek Polacek <polacek@redhat.com>
* c-omp.c (check_omp_for_incr_expr): Use BINARY_CLASS_P.
......
2015-05-21 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c/52952
* gcc.dg/redecl-4.c: Update column numbers.
* gcc.dg/format/bitfld-1.c: Likewise.
* gcc.dg/format/attr-2.c: Likewise.
* gcc.dg/format/attr-6.c: Likewise.
* gcc.dg/format/attr-7.c (baz): 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. Add tests for column
locations within strings with embedded escape sequences.
2015-05-20 Alex Velenko <Alex.Velenko@arm.com>
* gcc.target/arm/thumb1-far-jump-2.c (r4): Added int in definition.
......
......@@ -42,39 +42,40 @@ 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);
/* Standard specifiers not accepted in asm_fprintf. */
asm_fprintf ("%f\n", d); /* { dg-warning "16:format" "float" } */
asm_fprintf ("%e\n", d); /* { dg-warning "16:format" "float" } */
asm_fprintf ("%E\n", d); /* { dg-warning "16:format" "float" } */
asm_fprintf ("%g\n", d); /* { dg-warning "16:format" "float" } */
asm_fprintf ("%G\n", d); /* { dg-warning "16:format" "float" } */
asm_fprintf ("%p\n", p); /* { dg-warning "16:format" "pointer" } */
asm_fprintf ("%n\n", n); /* { dg-warning "16:format" "counter" } */
asm_fprintf ("%hd\n", i); /* { dg-warning "16:format" "conversion" } */
asm_fprintf ("%f\n", d); /* { dg-warning "18:format" "float" } */
asm_fprintf ("%e\n", d); /* { dg-warning "18:format" "float" } */
asm_fprintf ("%E\n", d); /* { dg-warning "18:format" "float" } */
asm_fprintf ("%g\n", d); /* { dg-warning "18:format" "float" } */
asm_fprintf ("%G\n", d); /* { dg-warning "18:format" "float" } */
asm_fprintf ("%p\n", p); /* { dg-warning "18:format" "pointer" } */
asm_fprintf ("%n\n", n); /* { dg-warning "18:format" "counter" } */
asm_fprintf ("%hd\n", i); /* { dg-warning "18:format" "conversion" } */
/* Various tests of bad argument types. */
asm_fprintf ("%d", l); /* { dg-warning "16:format" "bad argument types" } */
asm_fprintf ("%wd", l); /* { dg-warning "16:format" "bad argument types" } */
asm_fprintf ("%d", ll); /* { dg-warning "16: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 "16:format" "bad * argument types" } */
asm_fprintf ("%*.*ld\n", i1, i2, l); /* { dg-warning "16:format" "bad * argument types" } */
asm_fprintf ("%ld", i); /* { dg-warning "16:format" "bad argument types" } */
asm_fprintf ("%s", n); /* { dg-warning "16:format" "bad argument types" } */
asm_fprintf ("%d", l); /* { dg-warning "18:format" "bad argument types" } */
asm_fprintf ("%wd", l); /* { dg-warning "19:format" "bad argument types" } */
asm_fprintf ("%d", ll); /* { dg-warning "18:format" "bad argument types" } */
asm_fprintf ("%*d\n", i1, i); /* { dg-warning "18:format" "bad * argument types" } */
asm_fprintf ("%.*d\n", i2, i); /* { dg-warning "19:format" "bad * argument types" } */
asm_fprintf ("%*.*ld\n", i1, i2, l); /* { dg-warning "18:format" "bad * argument types" } */
asm_fprintf ("%ld", i); /* { dg-warning "19:format" "bad argument types" } */
asm_fprintf ("%s", n); /* { dg-warning "18:format" "bad argument types" } */
/* Wrong number of arguments. */
asm_fprintf ("%d%d", i); /* { dg-warning "16:matching" "wrong number of args" } */
asm_fprintf ("%d%d", i); /* { dg-warning "20:matching" "wrong number of args" } */
asm_fprintf ("%d", i, i); /* { dg-warning "16:arguments" "wrong number of args" } */
/* Miscellaneous bogus constructions. */
asm_fprintf (""); /* { dg-warning "16:zero-length" "warning for empty format" } */
asm_fprintf ("\0"); /* { dg-warning "16: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 "16:embedded|too many" "warning for embedded NUL" } */
asm_fprintf ("\0"); /* { dg-warning "17:embedded" "warning for embedded NUL" } */
asm_fprintf ("%d\0", i); /* { dg-warning "19:embedded" "warning for embedded NUL" } */
asm_fprintf ("%d\0%d", i, i); /* { dg-warning "19:embedded|too many" "warning for embedded NUL" } */
asm_fprintf (NULL); /* { dg-warning "null" "null format string warning" } */
asm_fprintf ("%"); /* { dg-warning "16:trailing" "trailing % warning" } */
asm_fprintf ("%++d", i); /* { dg-warning "16:repeated" "repeated flag warning" } */
asm_fprintf ("%"); /* { dg-warning "17:trailing" "trailing % warning" } */
asm_fprintf ("%++d", i); /* { dg-warning "19:repeated" "repeated flag warning" } */
asm_fprintf ((const char *)L"foo"); /* { dg-warning "30:wide" "wide string" } */
asm_fprintf ("%s", (char *)0); /* { dg-warning "null" "%s with NULL" } */
/* Make sure we still get warnings for regular printf. */
printf ("%d\n", ll); /* { dg-warning "11:format" "bad argument types" } */
printf ("%d\n", ll); /* { dg-warning "13:format" "bad argument types" } */
}
/* { dg-warning "16:too many arguments for format" "too many arguments" { target *-*-* } 0 } */
......@@ -30,13 +30,13 @@ void
foo (int i, int *ip, double d)
{
tformatprintf ("%d", i);
tformatprintf ("%"); /* { dg-warning "18:format" "attribute format printf" } */
tformatprintf ("%"); /* { dg-warning "19:format" "attribute format printf" } */
tformat__printf__ ("%d", i);
tformat__printf__ ("%"); /* { dg-warning "format" "attribute format __printf__" } */
tformatscanf ("%d", ip);
tformatscanf ("%"); /* { dg-warning "format" "attribute format scanf" } */
tformat__scanf__ ("%d", ip);
tformat__scanf__ ("%"); /* { dg-warning "format" "attribute format __scanf__" } */
tformat__scanf__ ("%"); /* { dg-warning "22:format" "attribute format __scanf__" } */
tformatstrftime ("%a");
tformatstrftime ("%"); /* { dg-warning "format" "attribute format strftime" } */
tformat__strftime__ ("%a");
......
......@@ -16,7 +16,7 @@ void
baz (int i, int *ip, double d)
{
tformatprintf0 ("%d", i);
tformatprintf0 ("%"); /* { dg-warning "19:format" "attribute format printf case 0" } */
tformatprintf0 ("%"); /* { dg-warning "20:format" "attribute format printf case 0" } */
tformatprintf1 ("%d", i);
tformatprintf1 ("%"); /* { dg-warning "format" "attribute format printf case 1" } */
tformatprintf2 ("%d", i);
......
......@@ -17,6 +17,6 @@
void
foo (const char *s, int *p)
{
scanf("%ld", p); /* { dg-warning "9:format" "implicit scanf" } */
scanf("%ld", p); /* { dg-warning "12:format" "implicit scanf" } */
/* { dg-warning "implicit" "implicit decl warning" { target *-*-* } 20 } */
}
......@@ -18,7 +18,7 @@ baz (int i)
{
(*tformatprintf0) ("%d", i);
(*tformatprintf0) ((*tformat_arg) ("%d"), i);
(*tformatprintf0) ("%"); /* { dg-warning "22:format" "prefix" } */
(*tformatprintf0) ("%"); /* { dg-warning "23:format" "prefix" } */
(*tformatprintf0) ((*tformat_arg) ("%")); /* { dg-warning "format" "prefix" } */
(*tformatprintf1) ("%d", i);
(*tformatprintf1) ((*tformat_arg) ("%d"), i);
......
......@@ -46,6 +46,6 @@ foo (void)
printf ("%ld%lu", x.u32, x.u32);
printf ("%ld%lu", x.s32, x.s32);
#endif
printf ("%llu", x.u48); /* { dg-warning "11:has type '.*unsigned int:48'" } */
printf ("%llu", x.u48); /* { dg-warning "15:has type '.*unsigned int:48'" } */
printf ("%llu", (unsigned long long)x.u48);
}
......@@ -9,19 +9,19 @@ void
foo (long l, int nfoo)
{
printf ((nfoo > 1) ? "%d foos" : "%d foo", nfoo);
printf ((l > 1) ? "%d foos" /* { dg-warning "21:int" "wrong type in conditional expr" } */
: "%d foo", l); /* { dg-warning "14: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" } */
printf ((l > 1) ? "%d foos" /* { dg-warning "23:int" "wrong type in conditional expr" } */
: "%d foo", l); /* { dg-warning "16:int" "wrong type in conditional expr" } */
printf ((l > 1) ? "%ld foos" : "%d foo", l); /* { dg-warning "36:int" "wrong type in conditional expr" } */
printf ((l > 1) ? "%d foos" : "%ld foo", l); /* { dg-warning "23:int" "wrong type in conditional expr" } */
/* Should allow one case to have extra arguments. */
printf ((nfoo > 1) ? "%d foos" : "1 foo", nfoo);
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 > 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" : "%ld foos"), nfoo); /* { dg-warning "61: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 "50:long int" "wrong type" } */
printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%ld foos"), nfoo); /* { dg-warning "64:long int" "wrong type" } */
printf ((nfoo > 1) ? "%ld foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo); /* { dg-warning "27:long int" "wrong type" } */
printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%ld foo" : "%d foos"), nfoo); /* { dg-warning "53:long int" "wrong type" } */
/* Extra arguments to NULL should be complained about. */
printf (0, "foo"); /* { dg-warning "14:too many" "NULL extra args" } */
/* { dg-warning "null" "null format arg" { target *-*-* } 26 } */
......
......@@ -15,7 +15,7 @@ f (void)
/* Should get format warnings even though the built-in declaration
isn't "visible". */
printf (
"%s", 1); /* { dg-warning "6:format" } */
"%s", 1); /* { dg-warning "8:format" } */
/* The type of strcmp here should have no prototype. */
if (0)
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