Commit d1463eb9 by David Malcolm Committed by David Malcolm

Fix suggestions for non-trivial Wformat type cases (PR c/72858)

gcc/c-family/ChangeLog:
	PR c/72858
	* c-format.c (argument_parser::check_argument_type): Add params
	"type_start" and "conversion_char".  Use the former to generate
	offset_to_type_start and pass it and conversion_char to
	check_format_types.
	(check_format_info_main): Capture the start of the type
	information as "type_start", and pass it an format_char
	to arg_parser.check_argument_type.
	(check_format_types): Provide an example in the leading comment.
	Add params "offset_to_type_start" and "conversion_char"; pass
	them to format_type_warning calls.
	(test_get_modifier_for_format_len): Likewise.
	(matching_type_p): New function.
	(get_format_for_type): Add param "conversion_char" and move
	implementation into...
	(get_format_for_type_1): ...new function, called twice.
	Use new function matching_type_p rather than checking for
	TYPE_CANONICAL equality.
	(get_corrected_substring): New function.
	(format_type_warning): Provide an example in the leading comment.
	Add params "offset_to_type_start" and "conversion_char".  Replace
	call to get_format_for_type with call to get_corrected_substring
	and move rejection of hints for widths/precisions there.
	(assert_format_for_type_streq): Add param "conversion_char".
	(ASSERT_FORMAT_FOR_TYPE_STREQ): Add param CONVERSION_CHAR.
	(test_get_format_for_type_printf): Add conversion chars to the
	tests, adding coverage for various combinations of integer
	vs double conversions, and for preserving octal and hexadecimal
	conversions.
	(test_get_format_for_type_scanf): Add conversion chars to the
	tests.

gcc/testsuite/ChangeLog:
	PR c/72858
	* gcc.dg/format/diagnostic-ranges.c: Update expected suggestions
	to preserve conversion chars, and to preserve prefix information.
	* gcc.dg/format/pr72858.c: New test case.

From-SVN: r240095
parent 5e8037ba
2016-09-12 David Malcolm <dmalcolm@redhat.com>
PR c/72858
* c-format.c (argument_parser::check_argument_type): Add params
"type_start" and "conversion_char". Use the former to generate
offset_to_type_start and pass it and conversion_char to
check_format_types.
(check_format_info_main): Capture the start of the type
information as "type_start", and pass it an format_char
to arg_parser.check_argument_type.
(check_format_types): Provide an example in the leading comment.
Add params "offset_to_type_start" and "conversion_char"; pass
them to format_type_warning calls.
(test_get_modifier_for_format_len): Likewise.
(matching_type_p): New function.
(get_format_for_type): Add param "conversion_char" and move
implementation into...
(get_format_for_type_1): ...new function, called twice.
Use new function matching_type_p rather than checking for
TYPE_CANONICAL equality.
(get_corrected_substring): New function.
(format_type_warning): Provide an example in the leading comment.
Add params "offset_to_type_start" and "conversion_char". Replace
call to get_format_for_type with call to get_corrected_substring
and move rejection of hints for widths/precisions there.
(assert_format_for_type_streq): Add param "conversion_char".
(ASSERT_FORMAT_FOR_TYPE_STREQ): Add param CONVERSION_CHAR.
(test_get_format_for_type_printf): Add conversion chars to the
tests, adding coverage for various combinations of integer
vs double conversions, and for preserving octal and hexadecimal
conversions.
(test_get_format_for_type_scanf): Add conversion chars to the
tests.
2016-09-10 Tom de Vries <tom@codesourcery.com> 2016-09-10 Tom de Vries <tom@codesourcery.com>
PR C/71602 PR C/71602
......
2016-09-12 David Malcolm <dmalcolm@redhat.com>
PR c/72858
* gcc.dg/format/diagnostic-ranges.c: Update expected suggestions
to preserve conversion chars, and to preserve prefix information.
* gcc.dg/format/pr72858.c: New test case.
2016-09-11 Steven G. Kargl <kargl@gcc.gnu.org> 2016-09-11 Steven G. Kargl <kargl@gcc.gnu.org>
* gfortran.dg/pr77507.f90: Move to ... * gfortran.dg/pr77507.f90: Move to ...
......
...@@ -30,7 +30,7 @@ void test_mismatching_types (const char *msg) ...@@ -30,7 +30,7 @@ void test_mismatching_types (const char *msg)
/* { dg-begin-multiline-output "" } /* { dg-begin-multiline-output "" }
printf("hello %i", (long)0); printf("hello %i", (long)0);
~^ ~^
%ld %li
{ dg-end-multiline-output "" } */ { dg-end-multiline-output "" } */
} }
...@@ -88,7 +88,7 @@ void test_hex (const char *msg) ...@@ -88,7 +88,7 @@ void test_hex (const char *msg)
/* { dg-begin-multiline-output "" } /* { dg-begin-multiline-output "" }
printf("hello \x25\x69", msg); printf("hello \x25\x69", msg);
~~~~^~~~ ~~~~^~~~
%s \x25s
{ dg-end-multiline-output "" } */ { dg-end-multiline-output "" } */
} }
...@@ -102,7 +102,7 @@ void test_oct (const char *msg) ...@@ -102,7 +102,7 @@ void test_oct (const char *msg)
/* { dg-begin-multiline-output "" } /* { dg-begin-multiline-output "" }
printf("hello \045\151", msg); printf("hello \045\151", msg);
~~~~^~~~ ~~~~^~~~
%s \045s
{ dg-end-multiline-output "" } */ { dg-end-multiline-output "" } */
} }
...@@ -121,7 +121,7 @@ void test_multiple (const char *msg) ...@@ -121,7 +121,7 @@ void test_multiple (const char *msg)
/* { dg-begin-multiline-output "" } /* { dg-begin-multiline-output "" }
printf("prefix" "\x25" "\151" "suffix", printf("prefix" "\x25" "\151" "suffix",
~~~~~~~~^~~~ ~~~~~~~~^~~~
%s \x25" "s
{ dg-end-multiline-output "" } */ { dg-end-multiline-output "" } */
} }
...@@ -267,7 +267,7 @@ void test_non_contiguous_strings (void) ...@@ -267,7 +267,7 @@ void test_non_contiguous_strings (void)
/* { dg-begin-multiline-output "" } /* { dg-begin-multiline-output "" }
__builtin_printf(" %" "d ", 0.5); __builtin_printf(" %" "d ", 0.5);
~~~~^ ~~~~^
%f %" "f
{ dg-end-multiline-output "" } */ { dg-end-multiline-output "" } */
} }
......
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