public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: David Malcolm <dmalcolm@redhat.com>, gcc-patches@gcc.gnu.org
Cc: Joseph Myers <joseph@codesourcery.com>
Subject: Re: [PATCH 4/4] c-format.c: suggest the correct format string to use (PR c/64955)
Date: Thu, 04 Aug 2016 19:55:00 -0000	[thread overview]
Message-ID: <f5319406-64a7-76aa-836d-1121dfbe204e@redhat.com> (raw)
In-Reply-To: <1470239113-42666-4-git-send-email-dmalcolm@redhat.com>

On 08/03/2016 09:45 AM, David Malcolm wrote:
> 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).
>
> Successfully bootstrapped&regrtested in conjunction with the rest of the
> patch kit on x86_64-pc-linux-gnu.
>
> (The v2 version of the patch had a successful selftest run for stage 1 on
> powerpc-ibm-aix7.1.3.0 (gcc111) in conjunction with the rest of the patch
> kit, and a successful build of stage1 for all targets via config-list.mk;
> the patch has only been rebased since)
>
> OK for trunk if it passes testing?
>
> 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.
> 	(check_format_info_main): 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.
So presumably we always use the type of the argument as the "correct" 
type and assume the format string is what needs to be fixed (with the 
exception of getting the right amount of *s handled).  That seems 
intuitively the right thing to do, but do we have a hit rate better than 
50% in practice?

This is OK.  I'm really just curious about your thoughts/experiences on 
the heuristics.

jeff


  reply	other threads:[~2016-08-04 19:55 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-08 21:22 [PATCH] RFC: On-demand locations within string-literals David Malcolm
2016-07-20 19:38 ` David Malcolm
2016-07-21 16:38   ` Jeff Law
2016-07-26 16:43     ` [PATCH 1/3] (v2) " David Malcolm
2016-07-26 16:43       ` [PATCH 3/3] c-format.c: suggest the correct format string to use (PR c/64955) David Malcolm
2016-07-26 16:43       ` [PATCH 2/3] Use class substring_loc in c-format.c (PR c/52952) David Malcolm
2016-07-26 18:06       ` [PATCH 1/3] (v2) On-demand locations within string-literals Manuel López-Ibáñez
2016-07-27 14:30         ` David Malcolm
2016-07-27 22:42           ` Manuel López-Ibáñez
2016-07-28 20:12             ` David Malcolm
2016-07-28 20:38               ` Martin Sebor
2016-07-28 21:17                 ` Martin Sebor
2016-07-29 12:37                   ` David Malcolm
2016-07-29 14:22                     ` Martin Sebor
2016-07-29 14:46                       ` David Malcolm
2016-07-29 15:26                         ` David Malcolm
2016-07-29 16:54                           ` Manuel López-Ibáñez
2016-07-29 17:27                             ` David Malcolm
2016-07-30  1:18                               ` Manuel López-Ibáñez
2016-08-03 15:56                               ` Jeff Law
2016-08-01 21:13                   ` Joseph Myers
2016-07-29 21:42       ` Joseph Myers
2016-07-30  1:16         ` David Malcolm
2016-08-03 15:17           ` [PATCH 1/4] selftest.h: Add ASSERT_TRUE_AT and ASSERT_FALSE_AT David Malcolm
2016-08-03 15:17             ` [PATCH 3/4] Use class substring_loc in c-format.c (PR c/52952) David Malcolm
2016-08-04 18:09               ` Jeff Law
2016-08-04 19:25                 ` David Malcolm
2016-08-04 20:22                   ` Jeff Law
2016-08-06  0:56                     ` [PATCH] c-format.c: cleanup of check_format_info_main David Malcolm
2016-08-08 17:20                       ` Jeff Law
2016-08-08 20:16                 ` [PATCH 3/4] Use class substring_loc in c-format.c (PR c/52952) David Malcolm
2016-08-03 15:17             ` [PATCH 2/4] (v3) On-demand locations within string-literals David Malcolm
2016-08-04 17:38               ` Jeff Law
2016-08-04 19:21                 ` David Malcolm
2016-08-04 20:18                   ` Jeff Law
2016-08-05 18:17                     ` [Committed] [PATCH 2/4] (v4) " David Malcolm
2016-08-06  5:48                       ` Markus Trippelsdorf
2016-08-06  5:59                         ` Prathamesh Kulkarni
2016-08-06 18:10                           ` [committed] Fix crash in selftest::test_lexer_string_locations_ucn4 (PR bootstrap/72823) David Malcolm
2021-09-02 13:59                       ` [Committed] [PATCH 2/4] (v4) On-demand locations within string-literals Thomas Schwinge
2021-09-02 19:09                         ` Thomas Schwinge
2021-09-03 16:33                           ` Thomas Schwinge
2021-09-10  7:48                             ` [PING] " Thomas Schwinge
2021-09-17 11:16                               ` [PING^2] " Thomas Schwinge
2021-09-30  6:47                                 ` [PING^3] Generalize 'gcc/input.h:struct location_hash' (was: [Committed] [PATCH 2/4] (v4) On-demand locations within string-literals) Thomas Schwinge
2021-10-17 22:33                                   ` Jeff Law
2021-11-09 13:48                                     ` Thomas Schwinge
2021-09-19  5:52                               ` [PING] Re: [Committed] [PATCH 2/4] (v4) On-demand locations within string-literals Jeff Law
2016-08-03 15:17             ` [PATCH 4/4] c-format.c: suggest the correct format string to use (PR c/64955) David Malcolm
2016-08-04 19:55               ` Jeff Law [this message]
2016-08-04 21:06                 ` David Malcolm
2016-08-03 16:06             ` [PATCH 1/4] selftest.h: Add ASSERT_TRUE_AT and ASSERT_FALSE_AT Jeff Law
2016-08-04 19:02               ` David Malcolm
2016-08-03 15:59         ` [PATCH 1/3] (v2) On-demand locations within string-literals Jeff Law
2016-08-04 14:27           ` David Malcolm
2016-08-04 17:37             ` Jeff Law
2016-07-23 21:36 ` [PATCH] RFC: " Martin Sebor
2016-07-24  0:37   ` David Malcolm
2016-08-23  3:25     ` Martin Sebor
2016-08-23 13:59       ` David Malcolm
2016-08-23 15:18         ` Martin Sebor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f5319406-64a7-76aa-836d-1121dfbe204e@redhat.com \
    --to=law@redhat.com \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).