This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PR c/52952] More precise locations within format strings


This patch allows format warnings to point within the format string
for simple strings. There are a few limitations:

* It does not handle 'const char *' because the location of the
initializer is not available. The result is the same before and after
this patch.

* It does not handle non-concatenated tokens, since the preprocessor
does not keep their location yet. The result after the patch is that
we point to some arbitrary place between the first " and the first
newline. This is slightly worse than the current behavior (which
points to the first "), but I could not figure out a way to detect
this case and not generate an offset. It is a matter of implementing
this idea: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52952#c13 as a
follow-up. The line pointed at is the same before and after the patch,
only the column number is affected.

* It does not handle macros, but the behavior before and after this
patch is the same (and there is work-in-progress on this:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52952#c33)

The changes to libcpp are exactly the same as in this patch:
https://gcc.gnu.org/ml/gcc-patches/2014-11/msg00000.html, which is
still pending review.

Boot&tested on x86_64-linux-gnu.

OK?

libcpp/ChangeLog:

2014-11-07  Manuel López-Ibáñez  <manu@gcc.gnu.org>

    * include/line-map.h (linemap_position_for_loc_and_offset):
    Declare.
    * line-map.c (linemap_position_for_loc_and_offset): New.

gcc/c-family/ChangeLog:

2014-11-07  Manuel López-Ibáñez  <manu@gcc.gnu.org>

    PR c/52952
    * c-format.c (location_from_offset): New.
    (check_format_info): Use it.
    (check_format_arg): Likewise.
    (check_format_info_main): Likewise.
    (format_type_warning): Likewise.

gcc/testsuite/ChangeLog:

2014-11-07  Manuel López-Ibáñez  <manu@gcc.gnu.org>

    PR c/52952
    * gcc.dg/redecl-4.c: Update column info.
    * 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: 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.

Attachment: format-loc8.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]