summaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-08-08 22:50:47 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-08-08 22:50:47 +0000
commit7af4d06beef1a319be9ea26ca2197016968c4d66 (patch)
treed1295b1b4e0a648f2f906e00b8e96ce05e031c74 /gcc/c
parentb9fbd3ed29e50a5b0c156d8878d56f7d08bb08dd (diff)
downloadgcc-7af4d06beef1a319be9ea26ca2197016968c4d66.tar.gz
c-format.c: suggest the correct format string to use (PR c/64955)
This adds fix-it hints to c-format.c so that it can (sometimes) suggest the format string the user should have used. The patch adds selftests for the new code in c-format.c. These selftests are thus lang-specific. This is the first time we've had lang-specific selftests, and hence the patch also adds a langhook for running them. (Note that currently the Makefile only invokes the selftests for cc1). gcc/c-family/ChangeLog: PR c/64955 * c-common.h (selftest::c_format_c_tests): New declaration. (selftest::run_c_tests): New declaration. * c-format.c: Include "selftest.h. (format_warning_va): Add param "corrected_substring" and use it to add a replacement fix-it hint. (format_warning_at_substring): Likewise. (format_warning_at_char): Update for new param of format_warning_va. (argument_parser::check_argument_type): Pass "fki" to check_format_types. (check_format_types): Add param "fki" and pass it to format_type_warning. (deref_n_times): New function. (get_modifier_for_format_len): New function. (selftest::test_get_modifier_for_format_len): New function. (get_format_for_type): New function. (format_type_warning): Add param "fki" and use it to attempt to provide hints for argument types when calling format_warning_at_substring. (selftest::get_info): New function. (selftest::assert_format_for_type_streq): New function. (ASSERT_FORMAT_FOR_TYPE_STREQ): New macro. (selftest::test_get_format_for_type_printf): New function. (selftest::test_get_format_for_type_scanf): New function. (selftest::c_format_c_tests): New function. gcc/c/ChangeLog: PR c/64955 * c-lang.c (LANG_HOOKS_RUN_LANG_SELFTESTS): If CHECKING_P, wire this up to selftest::run_c_tests. (selftest::run_c_tests): New function. gcc/ChangeLog: PR c/64955 * langhooks-def.h (LANG_HOOKS_RUN_LANG_SELFTESTS): New default do-nothing langhook. (LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_RUN_LANG_SELFTESTS. * langhooks.h (struct lang_hooks): Add run_lang_selftests. * selftest-run-tests.c: Include "tree.h" and "langhooks.h". (selftest::run_tests): Call lang_hooks.run_lang_selftests. gcc/testsuite/ChangeLog: PR c/64955 * gcc.dg/format/diagnostic-ranges.c: Add fix-it hints to expected output. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@239260 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog7
-rw-r--r--gcc/c/c-lang.c22
2 files changed, 29 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index ecae4f158bb..3161dcb6a02 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,10 @@
+2016-08-08 David Malcolm <dmalcolm@redhat.com>
+
+ PR c/64955
+ * c-lang.c (LANG_HOOKS_RUN_LANG_SELFTESTS): If CHECKING_P, wire
+ this up to selftest::run_c_tests.
+ (selftest::run_c_tests): New function.
+
2016-08-04 Thomas Schwinge <thomas@codesourcery.com>
* c-parser.c (struct oacc_routine_data): Add error_seen and
diff --git a/gcc/c/c-lang.c b/gcc/c/c-lang.c
index 89954b749cf..b26be6ad92c 100644
--- a/gcc/c/c-lang.c
+++ b/gcc/c/c-lang.c
@@ -38,7 +38,29 @@ enum c_language_kind c_language = clk_c;
#undef LANG_HOOKS_INIT_TS
#define LANG_HOOKS_INIT_TS c_common_init_ts
+#if CHECKING_P
+#undef LANG_HOOKS_RUN_LANG_SELFTESTS
+#define LANG_HOOKS_RUN_LANG_SELFTESTS selftest::run_c_tests
+#endif /* #if CHECKING_P */
+
/* Each front end provides its own lang hook initializer. */
struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
+#if CHECKING_P
+
+namespace selftest {
+
+/* Implementation of LANG_HOOKS_RUN_LANG_SELFTESTS for the C frontend. */
+
+void
+run_c_tests (void)
+{
+ c_format_c_tests ();
+}
+
+} // namespace selftest
+
+#endif /* #if CHECKING_P */
+
+
#include "gtype-c.h"