On 08/10/2016 02:10 PM, David Malcolm wrote:

The patch generalizes class substring_loc from being just a range
(pair of indices) to being a range plus a caret (three indices),
updating c-format.c to use the appropriate caret location.
Doing so means we have to pass a location_t around (containing the
caret+range) rather than a source_range.

For multi-column charaters the patch uses the start of the source
character for the caret, so the locations for embedded NULs in
gcc.dg/format/asm_fprintf-1.c and c90-printf-1.c revert to their locations
before r239253, i.e. from:
  "  \0  "
     ~^
to
  "  \0  "
     ^~
Other locations in c90-printf-1.c revert to their locations due to the fix
for PR c/72857.

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

OK for trunk?

gcc/c-family/ChangeLog:
        PR c/72857
        * c-common.c (substring_loc::get_range): Rename to...
        (substring_loc::get_location): ...this, converting param from a
        source_range * to a location_t *.  Call
        get_source_location_for_substring rather than
        get_source_range_for_substring, and pass in m_caret_idx.
        * c-common.h (substring_loc::substring_loc): Add param "caret_idx".
        (substring_loc::get_range): Replace with...
        (substring_loc::get_location): ...this.
        (substring_loc::set_caret_index): New method.
        (substring_loc): Add field m_caret_idx.
        * c-format.c (format_warning_va): Update for above changes.
        Rename local "substring_loc" to "fmt_substring_loc" to avoid
        clashing with type name.
        (format_warning_at_char): Add caret_idx param to substring_loc ctor.
        (check_argument_type): Likewise.
        (format_type_warning): Rename param "fmt_loc" to "whole_fmt_loc"
        Use a copy when emitting warnings, setting the caret index from TYPE.

gcc/ChangeLog:
        PR c/72857
        * input.c (get_source_range_for_substring): Rename to...
        (get_source_location_for_substring): ...this, adding param
        "caret_idx", and converting output param from source_range * to
        location_t *.
        (get_source_range_for_char): New function.
        (get_num_source_ranges_for_substring): Update comment to reflect
        above renaming.
        (assert_char_at_range): Update to use get_source_range_for_char
        rather than get_source_range_for_substring.
        (test_lexer_string_locations_concatenation_2): Likewise.
        * substring-locations.h (get_source_range_for_substring): Rename
        to...
        (get_source_location_for_substring): ...this, and adding param
        "caret_idx", and converting output param from source_range * to
        location_t *.

gcc/testsuite/ChangeLog:
        PR c/72857
        * gcc.dg/format/asm_fprintf-1.c: Restore column numbers
        for embedded NUL.
        * gcc.dg/format/c90-printf-1.c: Restore column numbers.
        * gcc.dg/format/diagnostic-ranges.c (test_hex): Update expected
        caret placement.
        (test_oct): Likewise.
        (test_multiple): Likewise.
        (test_field_width_specifier): Likewise.
        (test_field_width_specifier_2): New function.
        (test_field_precision_specifier): New function.
        (test_embedded_nul): Update expected caret placement.
        (test_non_contiguous_strings): Update line number.
        * gcc.dg/plugin/diagnostic-test-string-literals-1.c
        (__emit_string_literal_range): Add "caret_idx" param.
        (test_simple_string_literal): Add value for new param, updating
        expected output..
        (test_concatenated_string_literal): Likewise.
        (test_multiline_string_literal): Likewise.
        (test_hex): Likewise.
        (test_oct): Likewise.
        (test_multiple): Likewise.
        (test_ucn4): Likewise.
        (test_ucn8): Likewise.
        (test_u8): Likewise.
        (test_u): Likewise; update expected message, from "range" to
        "location".
        (test_U): Likewise.
        (test_L): Likewise.
        (test_macro): Add value for new param.
        * gcc.dg/plugin/diagnostic-test-string-literals-2.c
        (__emit_string_literal_range): Add "caret_idx" param.
        (test_stringified_token_1): Add value for new param.  Update
        expected message, from "range" to "location".
        (test_stringized_token_2): Likewise, adding param to macro.
        (test_stringified_token_3): Likewise.
        * gcc.dg/plugin/diagnostic_plugin_test_string_literals.c
        (emit_warning): Convert param from source_range to location_t.
        (test_string_literals): Add caret_idx param, and use it when
        constructing a substring_loc.  Update error message, from
        "range" to "location".
OK.
jeff

Reply via email to