gcc: Fix CVE-2021-42574
PATCH 1/1 gcc: Fix CVE-2021-42574
Upstream-Status: Backport [https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=004bb936d6d5f177af26ad4905595e843d5665a5]
Upstream-Status: Backport [https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=bd5e882cf6e0def3dd1bc106075d59a303fe0d1e]
Upstream-Status: Backport [https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=51c500269bf53749b107807d84271385fad35628]
Upstream-Status: Backport [https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=1a7f2c0774129750fdf73e9f1b78f0ce983c9ab3]
Upstream-Status: Backport [https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=bef32d4a28595e933f24fef378cf052a30b674a7]
--- meta/recipes-devtools/gcc/gcc-10.2.inc | 5 + .../gcc/gcc/0001-CVE-2021-42574.patch | 2906 +++++++++++++++++ .../gcc/gcc/0002-CVE-2021-42574.patch | 2270 +++++++++++++ .../gcc/gcc/0003-CVE-2021-42574.patch | 1724 ++++++++++ .../gcc/gcc/0004-CVE-2021-42574.patch | 138 + .../gcc/gcc/0005-CVE-2021-42574.patch | 575 ++++ 6 files changed, 7618 insertions(+) create mode 100644 meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch create mode 100644 meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch create mode 100644 meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch create mode 100644 meta/recipes-devtools/gcc/gcc/0004-CVE-2021-42574.patch create mode 100644 meta/recipes-devtools/gcc/gcc/0005-CVE-2021-42574.patch
meta/recipes-devtools/gcc/gcc-10.2.inc +5 -0
@@ -74,6 +74,11 @@ SRC_URI = "\ file://0002-CVE-2021-35465.patch \ file://0003-CVE-2021-35465.patch \ file://0004-CVE-2021-35465.patch \ + file://0001-CVE-2021-42574.patch \ + file://0002-CVE-2021-42574.patch \ + file://0003-CVE-2021-42574.patch \ + file://0004-CVE-2021-42574.patch \ + file://0005-CVE-2021-42574.patch \ " SRC_URI[sha256sum] = "b8dd4368bb9c7f0b98188317ee0254dd8cc99d1e3a18d0ff146c855fe16c1d8c"
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2906 -0
2,906 lines not on this page · raw message
meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +2270 -0
83 lines not on this page · raw message
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +1724 -0
1,724 lines not on this page · raw message
meta/recipes-devtools/gcc/gcc/0004-CVE-2021-42574.patch new file +138 -0
138 lines not on this page · raw message
meta/recipes-devtools/gcc/gcc/0005-CVE-2021-42574.patch new file +575 -0
575 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.31.1
Part of the diff is not shown here. View the raw message.
I can't apply this.
git am says:
error: cannot convert from Y to UTF-8
fatal: could not parse patch
Thanks,
Anuj
Quoted 9,088 lines · pgowda
Upstream-Status: Backport
[https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=004bb936d6d5f177af26ad4905595e843d5665a5]
Upstream-Status: Backport
[https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=bd5e882cf6e0def3dd1bc106075d59a303fe0d1e]
Upstream-Status: Backport
[https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=51c500269bf53749b107807d84271385fad35628]
Upstream-Status: Backport
[https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=1a7f2c0774129750fdf73e9f1b78f0ce983c9ab3]
Upstream-Status: Backport
[https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=bef32d4a28595e933f24fef378cf052a30b674a7]Signed-off-by pgowda <[email protected]>---
meta/recipes-devtools/gcc/gcc-10.2.inc | 5 + .../gcc/gcc/0001-CVE-2021-42574.patch | 2906
+++++++++++++++++.../gcc/gcc/0002-CVE-2021-42574.patch | 2270 +++++++++++++ .../gcc/gcc/0003-CVE-2021-42574.patch | 1724 ++++++++++ .../gcc/gcc/0004-CVE-2021-42574.patch | 138 + .../gcc/gcc/0005-CVE-2021-42574.patch | 575 ++++ 6 files changed, 7618 insertions(+)create mode 100644 meta/recipes-devtools/gcc/gcc/0001-CVE-2021- 42574.patch
create mode 100644 meta/recipes-devtools/gcc/gcc/0002-CVE-2021- 42574.patch
create mode 100644 meta/recipes-devtools/gcc/gcc/0003-CVE-2021- 42574.patch
create mode 100644 meta/recipes-devtools/gcc/gcc/0004-CVE-2021- 42574.patch
create mode 100644 meta/recipes-devtools/gcc/gcc/0005-CVE-2021- 42574.patchmeta/recipes- renamed from meta/recipes-devtools/gcc/gcc-10.2.inc +0
-0devtools/gcc/gcc-10.2.inc
index5626bf20f0..fd7f16d7bf100644meta/recipes-devtools/gcc/gcc-10.2.inc +5
-0@@ -74,6 +74,11 @@ SRC_URI = "\ file://0002-CVE-2021-35465.patch \ file://0003-CVE-2021-35465.patch \ file://0004-CVE-2021-35465.patch \ + file://0001-CVE-2021-42574.patch \ + file://0002-CVE-2021-42574.patch \ + file://0003-CVE-2021-42574.patch \ + file://0004-CVE-2021-42574.patch \ + file://0005-CVE-2021-42574.patch \"
SRC_URI[sha256sum] = "b8dd4368bb9c7f0b98188317ee0254dd8cc99d1e3a18d0ff146c855fe16c1d8c"meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +1
-0@@ -0,0 +1,2906 @@ +From 004bb936d6d5f177af26ad4905595e843d5665a5 Mon Sep 17 00:00:002001
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+From: Lewis Hyatt <[email protected]> +Date: Tue, 14 Jul 2020 12:05:56 -0400 +Subject: [PATCH] diagnostics: Support conversion of tabs to spaces[PR49973]
+ [PR86904]meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2
-0+ +Supports conversion of tabs to spaces when outputting diagnostics.Also
+adds -fdiagnostics-column-unit and -fdiagnostics-column-origin options to
+control how the column number is output, thereby resolving the two PRs.meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +5
-0+ +gcc/c-family/ChangeLog: + + PR other/86904 + * c-indentation.c (should_warn_for_misleading_indentation):Get
+ global tabstop from the new source.
+ *c-opts.c(c_common_handle_option): Remove handling of - ftabstop, which
+ is now a common option.
+ * c.opt: Likewise.meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +10
-0+ +gcc/ChangeLog: + + PR preprocessor/49973 + PR other/86904 + * common.opt: Handle -ftabstop here instead of in c-family + options. Add -fdiagnostics-column-unit= and + -fdiagnostics-column-origin= options. + * opts.c (common_handle_option): Handle the new options. + * diagnostic-format-json.cc (json_from_expanded_location):Add
+ diagnostic_context argument. Use it to convert column numbers as per
+ the new options.
+ (json_from_location_range): Likewise.
+ (json_from_fixit_hint): Likewise.
+ (json_end_diagnostic): Pass the new context argument to helper
+ functions above. Add "column-origin" field to the output. + (test_unknown_location): Add the new context argument to calls to
+ helper functions.
+ (test_bad_endpoints): Likewise.
+ *diagnostic-show-locus.c
+ (exploc_with_display_col::exploc_with_display_col): Support + tabstop parameter.
+ (layout_point::layout_point): Make use of class
+ exploc_with_display_col.
+ (layout_range::layout_range): Likewise.
+ (structline_bounds): Clarify that the units are now always + display columns. Rename members accordingly. Add constructor.
+ (layout::print_source_line): Add support for tab expansion. + (make_range): Adapt to classlayout_rangechanges. + (layout::maybe_add_location_range): Likewise.
+ (layout::layout): Adapt to classexploc_with_display_colchanges.
+ (layout::calculate_x_offset_display): Support tabstop parameter.
+ (layout::print_annotation_line): Adapt to structline_boundschanges.
+ (layout::print_line): Likewise.
+ (line_label::line_label): Adddiagnostic_contextargument. + (get_affected_range): Likewise.
+ (get_printed_columns): Likewise.
+ (layout::print_any_labels): Adapt to structline_labelchanges.
+ (class correction): Addm_tabstopmember.
+ (correction::correction): Add tabstop argument.
+ (correction::compute_display_cols): Usem_tabstop. + (classline_corrections): Addm_contextmember.
+ (line_corrections::line_corrections): Adddiagnostic_contextargument.
+ (line_corrections::add_hint): Usem_contextto handle tabstops.
+ (layout::print_trailing_fixits): Adapt to classline_corrections
+ changes.
+ (test_layout_x_offset_display_utf8): Support tabstop parameter.
+ (test_layout_x_offset_display_tab): New selftest. + (test_one_liner_colorized_utf8): Likewise.
+ (test_tab_expansion): Likewise.
+ (test_diagnostic_show_locus_one_liner_utf8): Call the new tests.
+ (diagnostic_show_locus_c_tests): Likewise.
+ (test_overlapped_fixit_printing): Adapt to helper class and + function changes.
+ (test_overlapped_fixit_printing_utf8): Likewise.
+ (test_overlapped_fixit_printing_2): Likewise.
+ *diagnostic.h(enumdiagnostics_column_unit): New enum. + (structdiagnostic_context): Add members for the new options. + (diagnostic_converted_column): Declare.
+ (json_from_expanded_location): Add new context argument. + *diagnostic.c(diagnostic_initialize): Initialize new members.
+ (diagnostic_converted_column): New function.
+ (maybe_line_and_column): Be willing to output a column of 0. + (diagnostic_get_location_text): Convert column number as per the new
+ options.
+ (diagnostic_report_current_module): Likewise.
+ (assert_location_text): Add origin andcolumn_unitarguments for
+ testing the new functionality.
+ (test_diagnostic_get_location_text): Test the new functionality.
+ * doc/invoke.texi: Document the new options and behavior. + *input.h(location_compute_display_column): Add tabstop argument.
+ *input.c(location_compute_display_column): Likewise. + (test_cpp_utf8): Add selftests for tab expansion. + * tree-diagnostic-path.cc (default_tree_make_json_for_path):
Pass the
+ new context argument tojson_from_expanded_location().meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +9
-1+ +libcpp/ChangeLog: + + PR preprocessor/49973 + PR other/86904 + * include/cpplib.h (struct cpp_options): Removed support for -ftabstop, + which is now handled by diagnostic_context. + (class cpp_display_width_computation): New class. + (cpp_byte_column_to_display_column): Add optional tabstopargument.
+ (cpp_display_width): Likewise.
+ (cpp_display_column_to_byte_column): Likewise.
+ *charset.c
+ (cpp_display_width_computation::cpp_display_width_computation ): New
+ function.
+ (cpp_display_width_computation::advance_display_cols):
Likewise.
+ (compute_next_display_width): Removed and implemented this + functionality in a new function...
+ (cpp_display_width_computation::process_next_codepoint):
...here.
+ (cpp_byte_column_to_display_column): Added tabstop argument. + Reimplemented in terms of classcpp_display_width_computation.
+ (cpp_display_column_to_byte_column): Likewise.
+ *init.c(cpp_create_reader): Remove handling of -ftabstop, which is now
+ handled bydiagnostic_context.meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +6
-0+ +gcc/testsuite/ChangeLog: + + PR preprocessor/49973 + PR other/86904 + * c-c++-common/Wmisleading-indentation-3.c: Adjust expectedoutput
+ for new defaults.
+ *c-c++-common/Wmisleading-indentation.c: Likewise. + *c-c++-common/diagnostic-format-json-1.c: Likewise. + *c-c++-common/diagnostic-format-json-2.c: Likewise. + *c-c++-common/diagnostic-format-json-3.c: Likewise. + *c-c++-common/diagnostic-format-json-4.c: Likewise. + *c-c++-common/diagnostic-format-json-5.c: Likewise. + *c-c++-common/missing-close-symbol.c: Likewise. + * g++.dg/diagnostic/bad-binary-ops.C: Likewise.
+ * g++.dg/parse/error4.C: Likewise.
+ * g++.old-deja/g++.brendan/crash11.C: Likewise.
+ * g++.old-deja/g++.pt/overload2.C: Likewise.
+ * g++.old-deja/g++.robertl/eb109.C: Likewise.
+ *gcc.dg/analyzer/malloc-paths-9.c: Likewise.
+ *gcc.dg/bad-binary-ops.c: Likewise.
+ *gcc.dg/format/branch-1.c: Likewise.
+ *gcc.dg/format/pr79210.c: Likewise.
+ *gcc.dg/plugin/diagnostic-test-expressions-1.c: Likewise. + *gcc.dg/plugin/diagnostic-test-string-literals-1.c:
Likewise.
+ *gcc.dg/redecl-4.c: Likewise.
+ * gfortran.dg/diagnostic-format-json-1.F90: Likewise. + * gfortran.dg/diagnostic-format-json-2.F90: Likewise. + * gfortran.dg/diagnostic-format-json-3.F90: Likewise. + * go.dg/arrayclear.go: Add a comment explaining why adding a + comment was necessary to work around a dejagnu bug. + *c-c++-common/diagnostic-units-1.c: New test.
+ *c-c++-common/diagnostic-units-2.c: New test.
+ *c-c++-common/diagnostic-units-3.c: New test.
+ *c-c++-common/diagnostic-units-4.c: New test.
+ *c-c++-common/diagnostic-units-5.c: New test.
+ *c-c++-common/diagnostic-units-6.c: New test.
+ *c-c++-common/diagnostic-units-7.c: New test.
+ *c-c++-common/diagnostic-units-8.c: New test.meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+ +CVE: CVE-2021-42574 +Upstream-Status: Backport[https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=004bb936d6d5f177af26ad
4905595e843d5665a5]meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +61
-1+Signed-off-by: Pgowda <[email protected]> +--- + gcc/c-family/c-indentation.c | 5 +- + gcc/c-family/c-opts.c | 6 - + gcc/c-family/c.opt | 4 - + gcc/common.opt | 21 + + gcc/diagnostic-format-json.cc | 55 +- + gcc/diagnostic-show-locus.c | 504 +++++++++++++-- --- + gcc/diagnostic.c | 113 +++- + gcc/diagnostic.h | 28 +- + gcc/doc/invoke.texi | 68 ++- + gcc/input.c | 72 ++- + gcc/input.h | 4 +- + gcc/opts.c | 14 + + .../c-c++-common/Wmisleading-indentation-3.c | 12 +- + .../c-c++-common/Wmisleading-indentation.c | 6 +- + .../c-c++-common/diagnostic-format-json-1.c | 5 + + .../c-c++-common/diagnostic-format-json-2.c | 5 + + .../c-c++-common/diagnostic-format-json-3.c | 5 + + .../c-c++-common/diagnostic-format-json-4.c | 9 + + .../c-c++-common/diagnostic-format-json-5.c | 9 + + .../c-c++-common/diagnostic-units-1.c | 28 + + .../c-c++-common/diagnostic-units-2.c | 28 + + .../c-c++-common/diagnostic-units-3.c | 28 + + .../c-c++-common/diagnostic-units-4.c | 28 + + .../c-c++-common/diagnostic-units-5.c | 28 + + .../c-c++-common/diagnostic-units-6.c | 28 + + .../c-c++-common/diagnostic-units-7.c | 28 + + .../c-c++-common/diagnostic-units-8.c | 28 + + .../c-c++-common/missing-close-symbol.c | 6 +- + .../g++.dg/diagnostic/bad-binary-ops.C | 8 +- + gcc/testsuite/g++.dg/parse/error4.C | 2 +- + .../g++.old-deja/g++.brendan/crash11.C | 4 +- + gcc/testsuite/g++.old-deja/g++.pt/overload2.C | 2 +- + .../g++.old-deja/g++.robertl/eb109.C | 4 +- + .../gcc.dg/analyzer/malloc-paths-9.c | 2 +- + gcc/testsuite/gcc.dg/bad-binary-ops.c | 8 +- + gcc/testsuite/gcc.dg/format/branch-1.c | 2 +- + gcc/testsuite/gcc.dg/format/pr79210.c | 2 +- + .../plugin/diagnostic-test-expressions-1.c | 16 +- + .../diagnostic-test-string-literals-1.c | 4 +- + gcc/testsuite/gcc.dg/redecl-4.c | 2 +- + .../gfortran.dg/diagnostic-format-json-1.F90 | 5 + + .../gfortran.dg/diagnostic-format-json-2.F90 | 5 + + .../gfortran.dg/diagnostic-format-json-3.F90 | 5 + + gcc/testsuite/go.dg/arrayclear.go | 3 + + gcc/tree-diagnostic-path.cc | 5 +- + libcpp/charset.c | 98 ++-- + libcpp/include/cpplib.h | 40 +- + libcpp/init.c | 1 - + 48 files changed, 1106 insertions(+), 287 deletions(-) + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-1.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-2.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-3.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-4.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-5.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-6.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-7.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-8.c + +diff --git a/gcc/c-family/c-indentation.c b/gcc/c-family/c-
indentation.c
+--- a/gcc/c-family/c-indentation.c 2020-07-22 23:35:17.296384022 -0700
++++ b/gcc/c-family/c-indentation.c 2021-12-25 01:20:53.475636694 -0800
+@@ -24,8 +24,7 @@ along with GCC; see the file COPYING3.
+ #include "c-common.h"
+ #include "c-indentation.h"
+ #include "selftest.h"+- +-extern cpp_options *cpp_opts;++#include "
diagnostic.h"
+
+ /* Round upVIS_COLUMNto nearest tab stop. */
+
+@@ -294,7 +293,7 @@should_warn_for_misleading_indentation( +expanded_locationnext_stmt_exploc=expand_location(next_stmt_loc);
+expanded_locationguard_exploc=expand_location(guard_loc); +
+- const unsigned inttab_width=cpp_opts->tabstop;
++ const unsigned inttab_width=global_dc->tabstop;
+
+ /* They must be in the same file. */
+ if (next_stmt_exploc.file != body_exploc.file)
+diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt +--- a/gcc/c-family/c.opt 2021-12-24 20:23:42.816809230 -0800 ++++ b/gcc/c-family/c.opt 2021-12-25 01:20:53.475636694 -0800 +@@ -1876,10 +1876,6 @@Enum(strong_eval_order)String(some) Val
+ EnumValue
+Enum(strong_eval_order)String(all) Value(2)
++-ftabstop= +-C ObjC C++ ObjC++ Joined RejectNegative UInteger +--ftabstop=<number> Distance between tab stops for columnreporting.
+-
+ ftemplate-backtrace-limit=
+ C++ ObjC++ Joined RejectNegative UIntegerVar(template_backtrace_limit)Init(10)
+ Set the maximum number of template instantiation notes for a single warning or error.meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +26
-0+diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c +--- a/gcc/c-family/c-opts.c 2021-12-24 20:23:44.824774786 -0800 ++++ b/gcc/c-family/c-opts.c 2021-12-25 01:20:53.475636694 -0800 +@@ -504,12 +504,6 @@ c_common_handle_option (size_t scode, co + cpp_opts->track_macro_expansion = 2; + break; + +- case OPT_ftabstop_: +- /* It is documented that we silently ignore silly values. */ +- if (value >= 1 && value <= 100) +- cpp_opts->tabstop = value; +- break; +- + case OPT_fexec_charset_: + cpp_opts->narrow_charset = arg; + break; +diff --git a/gcc/common.opt b/gcc/common.opt +--- a/gcc/common.opt 2021-12-24 20:23:42.480814993 -0800 ++++ b/gcc/common.opt 2021-12-25 01:20:53.475636694 -0800 +@@ -1325,6 +1325,14 @@ Enum(diagnostic_url_rule) String(always) + EnumValue + Enum(diagnostic_url_rule) String(auto) Value(DIAGNOSTICS_URL_AUTO) + ++fdiagnostics-column-unit= ++Common Joined RejectNegative Enum(diagnostics_column_unit) ++-fdiagnostics-column-unit=[display|byte] Select whether columnnumbers are output as display columns (default) or raw bytes. ++
++fdiagnostics-column-origin=
++Common Joined RejectNegative UInteger ++-fdiagnostics-column-origin=<number> Set the number of the first column. The default is 1-based as per GNU style, but some utilities may expect 0-based, for example.
++
+ fdiagnostics-format=
+ Common Joined RejectNegativeEnum(diagnostics_output_format)
+ -fdiagnostics-format=[text|json] Select output format. +@@ -1334,6 +1342,15 @@ SourceInclude
+diagnostic.h
+
+ Enum
++Name(diagnostics_column_unit) Type(int)
++
++EnumValue
++Enum(diagnostics_column_unit) String(display)Value(DIAGNOSTICS_COLUMN_UNIT_DISPLAY)
++
++EnumValue
++Enum(diagnostics_column_unit) String(byte)Value(DIAGNOSTICS_COLUMN_UNIT_BYTE)
++
++Enum
+Name(diagnostics_output_format)Type(int)
+
+ EnumValue
+@@ -1362,6 +1379,10 @@ fdiagnostics-path-format=
+ Common Joined RejectNegativeVar(flag_diagnostics_path_format)Enum(diagnostic_path_format)Init(DPF_INLINE_EVENTS)
+ Specify how to print any control-flow path associated with a diagnostic.
+
++ftabstop=
++Common Joined RejectNegative UInteger ++-ftabstop=<number> Distance between tab stops for column reporting.
++
+ Enum
+Name(diagnostic_path_format)Type(int)
+
+diff --gita/gcc/diagnostic.cb/gcc/diagnostic.c
+--- a/gcc/diagnostic.c 2020-07-22 23:35:17.556386887 -0700 ++++ b/gcc/diagnostic.c 2021-12-25 01:23:41.300841207 -0800 +@@ -38,6 +38,7 @@ along with GCC; see the file COPYING3.
+ #include "selftest.h"
+ #include "selftest-diagnostic.h"
+ #include "opts.h"
++#include "cpplib.h"
+
+ #ifdefHAVE_TERMIOS_H
+ # include <termios.h>
+@@ -219,6 +220,9 @@diagnostic_initialize(diagnostic_contex+context->min_margin_width= 0;
+context->show_ruler_p= false;
+context->parseable_fixits_p= false;
++context->column_unit=DIAGNOSTICS_COLUMN_UNIT_DISPLAY; ++context->column_origin= 1;
++context->tabstop= 8;
+context->edit_context_ptr= NULL;
+context->diagnostic_group_nesting_depth= 0;
+context->diagnostic_group_emission_count= 0;
+@@ -353,8 +357,51 @@diagnostic_get_color_for_kind(diagnosti + return diagnostic_kind_color[kind];
+ }
+
++/* Given anexpanded_location, convert the column (which is in 1- based bytes)
++ to the requested units, without converting the origin. ++ Return -1 if the column is invalid (<= 0). */
++
++static int
++convert_column_unit (enumdiagnostics_column_unitcolumn_unit, ++ int tabstop,
++expanded_locations)
++{
++ if (s.column <= 0)
++ return -1;
++
++ switch (column_unit)
++ {
++ default:
++gcc_unreachable();
++
++ caseDIAGNOSTICS_COLUMN_UNIT_DISPLAY:
++ {
++ cpp_char_column_policy policy (tabstop,cpp_wcwidth); ++ returnlocation_compute_display_column(s, policy); ++ }
++
++ caseDIAGNOSTICS_COLUMN_UNIT_BYTE:
++ return s.column;
++ }
++}
++
++/* Given anexpanded_location, convert the column (which is in 1- based bytes)
++ to the requested units and origin. Return -1 if the column is ++ invalid (<= 0). */
++int
++diagnostic_converted_column (diagnostic_context*context,expanded_locations)
++{
++ intone_based_col
++ =convert_column_unit(context->column_unit,context->tabstop, s);
++ if (one_based_col<= 0)
++ return -1;
++ returnone_based_col+ (context->column_origin- 1); ++}
++
+ /* Return a formatted line and column ':%line:%column'. Elided if +- zero. The result is a statically allocated buffer. */ ++ line == 0 or col < 0. (A column of 0 may be valid due to the ++ -fdiagnostics-column-origin option.)
++ The result is a statically allocated buffer. */
+
+ static const char *
+maybe_line_and_column(int line, int col)
+@@ -363,8 +410,9 @@maybe_line_and_column(int line, int col +
+ if (line)
+ {+- size_t l = snprintf (result, sizeof (result), +- col ? ":%d:%d" : ":%d", line, col);++
size_tl
++ = snprintf (result, sizeof (result),
++ col >= 0 ? ":%d:%d" : ":%d", line, col); +gcc_checking_assert(l < sizeof (result));
+ }
+ else
+@@ -383,8 +431,14 @@diagnostic_get_location_text(diagnostic + const char*locus_cs=colorize_start(pp_show_color(pp), "locus");
+ const char*locus_ce=colorize_stop(pp_show_color(pp)); + const char *file = s.file ? s.file : progname;+- int line = strcmp (file, N_("<built-in>")) ? s.line : 0; +- int col = context->show_column ? s.column : 0;++ int line = 0;
++ int col = -1;
++ if (strcmp (file,N_("<built-in>")))
++ {
++ line = s.line;
++ if (context->show_column)
++ col =diagnostic_converted_column(context, s); ++ }
+
+ const char*line_col=maybe_line_and_column(line, col); + returnbuild_message_string("%s%s%s:%s",locus_cs, file, +@@ -650,14 +704,20 @@diagnostic_report_current_module(diagno + if (!MAIN_FILE_P(map))
+ {
+ bool first = true;
++expanded_locations = {};
+ do
+ {
+ where =linemap_included_from(map);
+ map =linemap_included_from_linemap(line_table, map);+- const char *line_col +- = maybe_line_and_column (SOURCE_LINE (map, where), +- first && context-Quoted 1 line
show_column+- ?
SOURCE_COLUMN(map, where) : 0);
++ s.file =LINEMAP_FILE(map);
++ s.line =SOURCE_LINE(map, where);
++ int col = -1;
++ if (first &&context->show_column)
++ {
++ s.column =SOURCE_COLUMN(map, where); ++ col =diagnostic_converted_column(context, s); ++ }
++ const char*line_col=maybe_line_and_column(s.line, col);
+ static const char *const msgs[] =
+ {
+N_("In file included from"),
+@@ -666,7 +726,7 @@diagnostic_report_current_module(diagno + unsigned index = !first;
+pp_verbatim(context->printer, "%s%s %r%s%s%R", + first ? "" : ",\n",_(msgs[index]), +- "locus",LINEMAP_FILE(map),line_col); ++ "locus", s.file,line_col);
+ first = false;
+ }
+ while (!MAIN_FILE_P(map));
+@@ -2042,10 +2102,15 @@test_print_parseable_fixits_replace()
+ static void
+assert_location_text(const char*expected_loc_text,
+ const char *filename, int line, int column, +- boolshow_column)
++ boolshow_column,
++ int origin = 1,
++ enumdiagnostics_column_unitcolumn_unit++ =DIAGNOSTICS_COLUMN_UNIT_BYTE)
+ {
+test_diagnostic_contextdc;
+ dc.show_column =show_column;
++ dc.column_unit =column_unit;
++ dc.column_origin = origin;
+
+expanded_locationxloc;
+ xloc.file = filename;
+@@ -2069,7 +2134,10 @@test_diagnostic_get_location_text() +assert_location_text("PROGNAME:", NULL, 0, 0, true); +assert_location_text("<built-in>:", "<built-in>", 42, 10, true); +assert_location_text("foo.c:42:10:", "foo.c", 42, 10, true); +-assert_location_text("foo.c:42:", "foo.c", 42, 0, true); ++assert_location_text("foo.c:42:9:", "foo.c", 42, 10, true, 0); ++assert_location_text("foo.c:42:1010:", "foo.c", 42, 10, true, 1001);
++ for (int origin = 0; origin != 2; ++origin)
++assert_location_text("foo.c:42:", "foo.c", 42, 0, true, origin);
+assert_location_text("foo.c:", "foo.c", 0, 10, true); +assert_location_text("foo.c:42:", "foo.c", 42, 10, false); +assert_location_text("foo.c:", "foo.c", 0, 10, false); +@@ -2077,6 +2145,41 @@test_diagnostic_get_location_text() +maybe_line_and_column(INT_MAX,INT_MAX);
+maybe_line_and_column(INT_MIN,INT_MIN);
+
++ {
++ /* In order to test display columns vs byte columns, we need to create a
++ file forlocation_get_source_line()to read. */ ++
++ const char *const content = "smile \xf0\x9f\x98\x82\n"; ++ const intline_bytes= strlen (content) - 1;
++ const intdef_tabstop= 8;
++ const intdisplay_width=cpp_display_width(content,line_bytes,
++def_tabstop); ++ASSERT_EQ(line_bytes- 2,display_width);
++temp_source_filetmp (SELFTEST_LOCATION, ".c", content); ++ const char *const fname = tmp.get_filename ();
++ const intbuf_len= strlen (fname) + 16;
++ char *const expected = XNEWVEC (char,buf_len);
++
++ snprintf (expected,buf_len, "%s:1:%d:", fname,line_bytes); ++assert_location_text(expected, fname, 1,line_bytes, true, ++ 1,DIAGNOSTICS_COLUMN_UNIT_BYTE); ++
++ snprintf (expected,buf_len, "%s:1:%d:", fname,line_bytes- 1);
++assert_location_text(expected, fname, 1,line_bytes, true, ++ 0,DIAGNOSTICS_COLUMN_UNIT_BYTE); ++
++ snprintf (expected,buf_len, "%s:1:%d:", fname,display_width); ++assert_location_text(expected, fname, 1,line_bytes, true, ++ 1,DIAGNOSTICS_COLUMN_UNIT_DISPLAY); ++
++ snprintf (expected,buf_len, "%s:1:%d:", fname,display_width- 1);
++assert_location_text(expected, fname, 1,line_bytes, true, ++ 0,DIAGNOSTICS_COLUMN_UNIT_DISPLAY); ++
++ XDELETEVEC (expected);
++ }
++
++
+ progname =old_progname;
+ }
+
+diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format- json.cc
+--- a/gcc/diagnostic-format-json.cc 2020-07-22 23:35:17.556386887 -0700
++++ b/gcc/diagnostic-format-json.cc 2021-12-25 01:20:53.475636694 -0800
+@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.
+ #include "system.h"
+ #include "coretypes.h"
+ #include "diagnostic.h"
++#include "selftest-diagnostic.h"
+ #include "diagnostic-metadata.h"
+ #include "json.h"
+ #include "selftest.h"
+@@ -43,21 +44,43 @@ staticjson::array*cur_children_array;
+ /* Generate a JSON object for LOC. */
+
+json::value*
+-json_from_expanded_location (location_tloc) ++json_from_expanded_location (diagnostic_context*context,location_tloc)
+ {
+expanded_locationexploc =expand_location(loc);
+json::object*result = newjson::object();
+ if (exploc.file)
+result->set("file", newjson::string(exploc.file)); +result->set("line", newjson::integer_number(exploc.line)); +-result->set("column", newjson::integer_number(exploc.column)); ++
++ const enumdiagnostics_column_unitorig_unit= context-Quoted 1 line
column_unit;++ struct
++ {
++ const char *name;
++ enumdiagnostics_column_unitunit;
++ } column_fields[] = {
++ {"display-column",DIAGNOSTICS_COLUMN_UNIT_DISPLAY}, ++ {"byte-column",DIAGNOSTICS_COLUMN_UNIT_BYTE}
++ };
++ intthe_column=INT_MIN;
++ for (int i = 0; i != sizeofcolumn_fields/ sizeof (*column_fields); ++i)
++ {
++context->column_unit= column_fields[i].unit;
++ const int col =diagnostic_converted_column(context, exploc);
++result->set(column_fields[i].name, newjson::integer_number(col));
++ if (column_fields[i].unit ==orig_unit)
++ the_column = col;
++ }
++gcc_assert(the_column!=INT_MIN);
++result->set("column", newjson::integer_number(the_column)); ++context->column_unit=orig_unit;
+ return result;
+ }
+
+ /* Generate a JSON object for LOC_RANGE. */
+
+ staticjson::object*
+-json_from_location_range (constlocation_range*loc_range, unsignedrange_idx)
++json_from_location_range (diagnostic_context*context, ++ constlocation_range*loc_range, unsignedrange_idx)
+ {
+location_tcaret_loc=get_pure_location(loc_range->m_loc); +
+@@ -68,13 +91,13 @@json_from_location_range(const location +location_tfinish_loc=get_finish(loc_range->m_loc); +
+json::object*result = newjson::object();
+-result->set("caret",json_from_expanded_location(caret_loc)); ++result->set("caret",json_from_expanded_location(context,caret_loc));
+ if (start_loc!=caret_loc
+ &&start_loc!=UNKNOWN_LOCATION)
+-result->set("start",json_from_expanded_location(start_loc)); ++result->set("start",json_from_expanded_location(context,start_loc));
+ if (finish_loc!=caret_loc
+ &&finish_loc!=UNKNOWN_LOCATION)
+-result->set("finish",json_from_expanded_location(finish_loc));
++result->set("finish",json_from_expanded_location(context,finish_loc));
+
+ if (loc_range->m_label)
+ {
+@@ -91,14 +114,14 @@json_from_location_range(const location
+ /* Generate a JSON object for HINT. */
+
+ staticjson::object*
+-json_from_fixit_hint (constfixit_hint*hint) ++json_from_fixit_hint (diagnostic_context*context, constfixit_hint*hint)
+ {
+json::object*fixit_obj= newjson::object();
+
+location_tstart_loc=hint->get_start_loc();
+-fixit_obj->set("start",json_from_expanded_location(start_loc));
++fixit_obj->set("start",json_from_expanded_location(context,start_loc));
+location_tnext_loc=hint->get_next_loc();
+-fixit_obj->set("next",json_from_expanded_location(next_loc)); ++fixit_obj->set("next",json_from_expanded_location(context,next_loc));
+fixit_obj->set("string", newjson::string(hint->get_string()));
+
+ returnfixit_obj;
+@@ -190,11 +213,13 @@json_end_diagnostic(diagnostic_context+ else
+ {
+ /* Otherwise, makediag_objbe the top-level object within the group;
+- add a "children" array. */
++ add a "children" array and record the column origin. */ +toplevel_array->append(diag_obj);
+cur_group=diag_obj;
+cur_children_array= newjson::array();
+diag_obj->set("children",cur_children_array);
++diag_obj->set("column-origin",
++ newjson::integer_number(context-Quoted 1 line
column_origin));+ }
+
+ constrich_location*richloc =diagnostic->richloc; +@@ -205,7 +230,7 @@json_end_diagnostic(diagnostic_context+ for (unsigned int i = 0; i <richloc->get_num_locations(); i++) + {
+ constlocation_range*loc_range=richloc->get_range(i); +-json::object*loc_obj=json_from_location_range(loc_range, i);
++json::object*loc_obj=json_from_location_range(context,loc_range, i);
+ if (loc_obj)
+ loc_array->append (loc_obj);
+ }
+@@ -217,7 +242,7 @@json_end_diagnostic(diagnostic_context+ for (unsigned int i = 0; i <richloc->get_num_fixit_hints(); i++)
+ {
+ constfixit_hint*hint =richloc->get_fixit_hint(i); +-json::object*fixit_obj=json_from_fixit_hint(hint); ++json::object*fixit_obj=json_from_fixit_hint(context, hint);
+fixit_array->append(fixit_obj);
+ }
+ }
+@@ -320,7 +345,8 @@ namespace selftest {
+ static void
+test_unknown_location()
+ {
+- deletejson_from_expanded_location(UNKNOWN_LOCATION); ++test_diagnostic_contextdc;
++ deletejson_from_expanded_location(&dc,UNKNOWN_LOCATION);
+ }
+
+ /* Verify that we gracefully handle attempts to serialize bad +@@ -338,7 +364,8 @@test_bad_endpoints()
+ loc_range.m_range_display_kind =SHOW_RANGE_WITH_CARET; + loc_range.m_label = NULL;
+
+-json::object*obj =json_from_location_range(&loc_range, 0); ++test_diagnostic_contextdc;
++json::object*obj =json_from_location_range(&dc,&loc_range, 0);
+ /* We should have a "caret" value, but no "start" or "finish" values. */
+ASSERT_TRUE(obj != NULL);
+ASSERT_TRUE(obj->get("caret") != NULL);
+diff --gita/gcc/diagnostic.hb/gcc/diagnostic.h
+--- a/gcc/diagnostic.h 2020-07-22 23:35:17.556386887 -0700 ++++ b/gcc/diagnostic.h 2021-12-25 01:20:53.479636627 -0800 +@@ -24,6 +24,20 @@ along with GCC; see the file COPYING3.
+ #include "pretty-print.h"
+ #include "diagnostic-core.h"
+
++/* An enum for controlling what units to use for the column number ++ when diagnostics are output, used by the -fdiagnostics-column- unit option.
++ Tabs will be expanded or not according to the value of - ftabstop. The origin
++ (default 1) is controlled by -fdiagnostics-column-origin. */ ++
++enumdiagnostics_column_unit
++{
++ /* The default from GCC 11 onwards: display columns. */ ++DIAGNOSTICS_COLUMN_UNIT_DISPLAY,
++
++ /* The behavior in GCC 10 and earlier: simple bytes. */ ++DIAGNOSTICS_COLUMN_UNIT_BYTE
++};
++
+ /* Enum for overriding the standard output format. */
+
+ enumdiagnostics_output_format
+@@ -280,6 +294,15 @@ structdiagnostic_context
+ rest of the diagnostic. */
+ boolparseable_fixits_p;
+
++ /* What units to use when outputting the column number. */ ++ enumdiagnostics_column_unitcolumn_unit;
++
++ /* The origin for the column number (1-based or 0-based typically). */
++ intcolumn_origin;
++
++ /* The size of the tabstop for tab expansion. */
++ int tabstop;
++
+ /* If non-NULL, anedit_contextto which fix-it hints should be + applied, for generating patches. */
+edit_context*edit_context_ptr;
+@@ -458,6 +481,8 @@diagnostic_same_line(constdiagnostic_c
+ }
+
+ extern const char*diagnostic_get_color_for_kind(diagnostic_tkind);
++extern intdiagnostic_converted_column(diagnostic_context*context,
++ expanded_location s); +
+ /* Pure text formatting support functions. */
+ extern char*file_name_as_prefix(diagnostic_context*, const char *);
+@@ -470,6 +495,7 @@ extern voiddiagnostic_output_format_ini
+ /* Compute the number of digits in the decimal representation of an integer. */
+ extern intnum_digits(int);
+
+-externjson::value*json_from_expanded_location(location_tloc); ++externjson::value*json_from_expanded_location(diagnostic_context*context,
++location_tloc); +
+ #endif /* !GCC_DIAGNOSTIC_H*/
+diff --gita/gcc/diagnostic-show-locus.cb/gcc/diagnostic-show-locus.c
+--- a/gcc/diagnostic-show-locus.c 2020-07-22 23:35:17.556386887 -0700
++++ b/gcc/diagnostic-show-locus.c 2021-12-25 01:20:53.479636627 -0800
+@@ -175,9 +175,10 @@ enumcolumn_unit{
+ classexploc_with_display_col: publicexpanded_location
+ {
+ public:
+-exploc_with_display_col(constexpanded_location&exploc) ++exploc_with_display_col(constexpanded_location&exploc, int tabstop)
+ :expanded_location(exploc),
+-m_display_col(location_compute_display_column(exploc)) {} ++m_display_col(location_compute_display_column(exploc, tabstop))
++ {}
+
+ intm_display_col;
+ };
+@@ -189,11 +190,11 @@ classexploc_with_display_col: public e
+ classlayout_point
+ {
+ public:
+-layout_point(constexpanded_location&exploc)
++layout_point(constexploc_with_display_col&exploc)
+ :m_line(exploc.line)
+ {
+ m_columns[CU_BYTES] = exploc.column;
+- m_columns[CU_DISPLAY_COLS] =location_compute_display_column(exploc);
++ m_columns[CU_DISPLAY_COLS] = exploc.m_display_col;
+ }
+
+linenum_typem_line;
+@@ -205,10 +206,10 @@ classlayout_point
+ classlayout_range
+ {
+ public:+- layout_range (const expanded_location *start_exploc, +- const expanded_location *finish_exploc,++
layout_range(constexploc_with_display_col&start_exploc, ++ constexploc_with_display_col&finish_exploc, + enumrange_display_kindrange_display_kind, +- constexpanded_location*caret_exploc,
++ constexploc_with_display_col&caret_exploc, + unsignedoriginal_idx,
+ constrange_label*label);
+
+@@ -226,22 +227,18 @@ classlayout_range
+
+ /* A struct for use bylayout::print_source_linefor telling +layout::print_annotation_linethe extents of the source line that
+- it printed, so that underlines can be clipped appropriately. */ ++ it printed, so that underlines can be clipped appropriately. Units
++ are 1-based display columns. */
+
+ structline_bounds
+ {+- int m_first_non_ws; +- int m_last_non_ws;++ int
m_first_non_ws_disp_col;
++ intm_last_non_ws_disp_col;
+
+- voidconvert_to_display_cols(char_spanline)
++line_bounds()
+ {
+-m_first_non_ws=cpp_byte_column_to_display_column(line.get_buffer (),
+- line.length (),
+-
m_first_non_ws) ;+- +- m_last_non_ws = cpp_byte_column_to_display_column(line.get_buffer (),
+- line.length (),
+-m_last_non_ws);
++m_first_non_ws_disp_col=INT_MAX;
++m_last_non_ws_disp_col= 0;
+ }
+ };
+
+@@ -351,8 +348,8 @@ class layout
+ private:
+ boolwill_show_line_p(linenum_typerow) const;
+ voidprint_leading_fixits(linenum_typerow);
+- voidprint_source_line(linenum_typerow, const char *line, intline_bytes,
+-line_bounds*lbounds_out);
++line_boundsprint_source_line(linenum_typerow, const char *line,
++ intline_bytes);
+ boolshould_print_annotation_line_p(linenum_typerow) const; + voidstart_annotation_line(charmargin_char= ' ') const; + voidprint_annotation_line(linenum_typerow, constline_boundslbounds);
+@@ -513,16 +510,16 @@colorizer::get_color_by_name(const char + Initialize variouslayout_pointfields fromexpanded_location+ equivalents; we've already filtered on file. */
++-layout_range::layout_range (const expanded_location *start_exploc, +- const expanded_location *finish_exploc,++layout_range::layout_range (const
exploc_with_display_col&start_exploc,
++ constexploc_with_display_col&finish_exploc,
+ enumrange_display_kindrange_display_kind,
+- constexpanded_location*caret_exploc, ++ constexploc_with_display_col&caret_exploc,
+ unsignedoriginal_idx,
+ constrange_label*label)+-: m_start (*start_exploc), +- m_finish (*finish_exploc),++:
m_start(start_exploc),
++m_finish(finish_exploc),
+m_range_display_kind(range_display_kind),
+-m_caret(*caret_exploc),
++m_caret(caret_exploc),
+m_original_idx(original_idx),
+m_label(label)
+ {
+@@ -646,6 +643,9 @@layout_range::intersects_line_p(linenum +
+ #ifCHECKING_P
+
++/* Default for when we don't care what the tab expansion is set to. */
++static const intdef_tabstop= 8;
++
+ /* Create some expanded locations for testing layout_range. The filename
+ member of the explocs is set to the empty string. This member will only be
+ inspected by the calls tolocation_compute_display_column()made from the
+@@ -662,8 +662,11 @@make_range(intstart_line, intstart_co+ = {"",start_line,start_col, NULL, false};
+ constexpanded_locationfinish_exploc
+ = {"",end_line,end_col, NULL, false};
+- returnlayout_range(&start_exploc,&finish_exploc,SHOW_RANGE_WITHOUT_CARET,
+-&start_exploc, 0, NULL);
++ returnlayout_range(exploc_with_display_col(start_exploc,def_tabstop),
++exploc_with_display_col(finish_exploc,def_tabstop),
++SHOW_RANGE_WITHOUT_CARET,
++exploc_with_display_col(start_exploc,def_tabstop),
++ 0, NULL);
+ }
+
+ /* Selftests forlayout_range::contains_pointand
+@@ -964,7 +967,7 @@layout::layout(diagnostic_context* con
+ :m_context(context),
+m_pp(context->printer),
+m_primary_loc(richloc->get_range(0)->m_loc),
+-m_exploc(richloc->get_expanded_location(0)),
++m_exploc(richloc->get_expanded_location(0),context->tabstop), +m_colorizer(context,diagnostic_kind),
+m_colorize_source_p(context->colorize_source_p),
+m_show_labels_p(context->show_labels_p),
+@@ -1060,7 +1063,10 @@layout::maybe_add_location_range(const +
+ /* Everything is now known to be in the correct source file, + but it may require further sanitization. */
+-layout_rangeri (&start, &finish, loc_range-Quoted 1 line
m_range_display_kind, &caret,++
layout_rangeri (exploc_with_display_col(start, m_context-Quoted 1 line
tabstop),
++
exploc_with_display_col(finish, m_context-Quoted 1 line
tabstop),
++
loc_range->m_range_display_kind, ++exploc_with_display_col(caret, m_context-Quoted 1 line
tabstop),
+
original_idx,loc_range->m_label);
+
+ /* If we have a range that finishes before it starts (perhaps +@@ -1394,7 +1400,7 @@layout::calculate_x_offset_display() + =get_line_bytes_without_trailing_whitespace(line.get_buffer (),
+ line.length ()); + inteol_display_column
+- =cpp_display_width(line.get_buffer (),line_bytes); ++ =cpp_display_width(line.get_buffer (),line_bytes, m_context-Quoted 1 line
tabstop);
+ if (
caret_display_column>eol_display_column
+ || !caret_display_column)
+ {
+@@ -1445,16 +1451,13 @@layout::calculate_x_offset_display()
+ }
+
+ /* Print line ROW of source code, potentially colorized at any ranges, and+- populate *LBOUNDS_OUT. +- LINE is the source line (not necessarily 0-terminated) and LINE_BYTES +- is its length in bytes. +- This function deals only with byte offsets, not display columns,so
+-m_x_offset_displaymust be converted from display to byte units. In
+- particular,LINE_BYTESandLBOUNDS_OUTare in bytes. */ ++ return the line bounds. LINE is the source line (not necessarily
++ 0-terminated) andLINE_BYTESis its length in bytes. In order to handle both
++ colorization and tab expansion, this function tracks the line position in
++ both byte and display column units. */
++-void +-layout::print_source_line (linenum_type row, const char *line, int
line_bytes,
+-line_bounds*lbounds_out) ++line_bounds
++layout::print_source_line (linenum_typerow, const char *line, intline_bytes)
+ {
+ m_colorizer.set_normal_text ();
+
+@@ -1469,30 +1472,29 @@layout::print_source_line(linenum_type+ else
+pp_space(m_pp);
+
+- /* We will stop printing the source line at any trailing whitespace, and start
+- printing it as per m_x_offset_display. */
++ /* We will stop printing the source line at any trailing whitespace. */
+line_bytes=get_line_bytes_without_trailing_whitespace(line, +line_bytes);+- int x_offset_bytes = 0; +- if (m_x_offset_display) +- { +- x_offset_bytes = cpp_display_column_to_byte_column (line,
line_bytes,
+-m_x_offset_display);
+- /* In case the leading portion of the line that will be skipped over ends
+- with a character with wcwidth > 1, then it is possible we skipped too+- much, so account for that by padding with spaces. */ +- const int overage +- = cpp_byte_column_to_display_column (line, line_bytes, x_offset_bytes) +- - m_x_offset_display; +- for (int column = 0; column < overage; ++column) +- pp_space (m_pp); +- line += x_offset_bytes; +- } + +- /* Print the line. */ +- int first_non_ws = INT_MAX; +- int last_non_ws = 0; +- for (int col_byte = 1 + x_offset_bytes; col_byte <= line_bytes;col_byte++)
++ /* This object helps to keep track of which display column we are at, which is
++ necessary for computing the line bounds in display units, for doing
++ tab expansion, and for implementing m_x_offset_display. */ ++cpp_display_width_computationdw (line,line_bytes, m_context-Quoted 1 line
tabstop);
++
++ /* Skip the firstm_x_offset_displaydisplay columns. In case the leading
++ portion that will be skipped ends with a character with wcwidth > 1, then
++ it is possible we skipped too much, so account for that by padding with
++ spaces. Note that this does the right thing too in case a tab was the last
++ character to be skipped over; the tab is effectively replaced by the
++ correct number of trailing spaces needed to offset by the desired number of
++ display columns. */
++ for (intskipped_display_cols= dw.advance_display_cols (m_x_offset_display);
++skipped_display_cols>m_x_offset_display; --skipped_display_cols)
++pp_space(m_pp);
++
++ /* Print the line and compute the line_bounds. */
++line_boundslbounds;
++ while (!dw.done ())
+ {
+ /* Assuming colorization is enabled for the caret and underline
+ characters, we may also colorize the associated characters +@@ -1510,7 +1512,8 @@layout::print_source_line(linenum_type+ {
+ boolin_range_p;
+point_statestate;
+-in_range_p=get_state_at_point(row,col_byte, ++ const intstart_byte_col= dw.bytes_processed () + 1; ++in_range_p=get_state_at_point(row,start_byte_col, + 0,INT_MAX,
+CU_BYTES,
+ &state);
+@@ -1519,22 +1522,44 @@layout::print_source_line(linenum_type+ else
+ m_colorizer.set_normal_text ();
+ }+- char c = *line; +- if (c == '\0' || c == '\t' || c == '\r') +- c = ' '; +- if (c != ' ')++
++ /* Get the display width of the next character to be output, expanding
++ tabs and replacing some control bytes with spaces as necessary. */
++ const char *c = dw.next_byte ();
++ const intstart_disp_col= dw.display_cols_processed () + 1; ++ const intthis_display_width= dw.process_next_codepoint (); ++ if (*c == '\t')
++ {
++ /* The returned display width is the number of spaces into which the
++ tab should be expanded. */
++ for (int i = 0; i !=this_display_width; ++i) ++pp_space(m_pp);
++ continue;
++ }
++ if (*c == '\0' || *c == '\r')
+ {+- last_non_ws = col_byte; +- if (first_non_ws == INT_MAX) +- first_non_ws = col_byte;++ /*
cpp_wcwidth()promises to return 1 for all control bytes, and we
++ want to output these as a single space too, so this case is
++ actually the same as the '\t' case. */
++gcc_assert(this_display_width== 1);
++pp_space(m_pp);
++ continue;
+ }+- pp_character (m_pp, c); +- line++;++
++ /* We have a (possibly multibyte) character to output; update the line
++ bounds if it is not whitespace. */
++ if (*c != ' ')
++ {
++ lbounds.m_last_non_ws_disp_col = dw.display_cols_processed ();
++ if (lbounds.m_first_non_ws_disp_col ==INT_MAX) ++ lbounds.m_first_non_ws_disp_col =start_disp_col; ++ }
++
++ /* Output the character. */
++ while (c != dw.next_byte ())pp_character(m_pp, *c++); + }
+print_newline();+- +- lbounds_out->m_first_non_ws = first_non_ws; +- lbounds_out->m_last_non_ws = last_non_ws;++ return lbounds;
+ }
+
+ /* Determine if we should print an annotation line for ROW. +@@ -1576,14 +1601,13 @@layout::start_annotation_line(char marg
+ }
+
+ /* Print a line consisting of the caret/underlines for the given +- source line. This function works with display columns, rather than byte
+- counts; in particular, LBOUNDS should be in display column units. */
++ source line. */
+
+ void
+layout::print_annotation_line(linenum_typerow, constline_boundslbounds)
+ {
+ intx_bound=get_x_bound_for_row(row, m_exploc.m_display_col, +- lbounds.m_last_non_ws); ++ lbounds.m_last_non_ws_disp_col); +
+start_annotation_line();
+pp_space(m_pp);
+@@ -1593,8 +1617,8 @@layout::print_annotation_line(linenum_t+ boolin_range_p;
+point_statestate;
+in_range_p=get_state_at_point(row, column,+- lbounds.m_first_non_ws, +- lbounds.m_last_non_ws,++
lbounds.m_first_non_ws_disp_col,
++
lbounds.m_last_non_ws_disp_col,
+CU_DISPLAY_COLS,
+ &state);
+ if (in_range_p)
+@@ -1631,12 +1655,14 @@layout::print_annotation_line(linenum_t
+ classline_label
+ {
+ public:
+-line_label(intstate_idx, int column,label_texttext) ++line_label(diagnostic_context*context, intstate_idx, int column,
++label_texttext)
+ :m_state_idx(state_idx),m_column(column),
+m_text(text),m_label_line(0),m_has_vbar(true)
+ {
+ const int bytes = strlen (text.m_buffer);
+-m_display_width=cpp_display_width(text.m_buffer, bytes); ++m_display_width
++ =cpp_display_width(text.m_buffer, bytes,context->tabstop); + }
+
+ /* Sorting is primarily by column, then by state index. */ +@@ -1696,7 +1722,7 @@layout::print_any_labels(linenum_typer + if (text.m_buffer == NULL)
+ continue;
+
+- labels.safe_push (line_label(i,disp_col, text)); ++ labels.safe_push (line_label(m_context, i,disp_col, text)); + }
+ }
+
+@@ -1976,7 +2002,8 @@ public:
+
+ /* Get the range of bytes or display columns that HINT would affect. */
+ staticcolumn_range
+-get_affected_range (constfixit_hint*hint, enumcolumn_unitcol_unit)
++get_affected_range (diagnostic_context*context,
++ constfixit_hint*hint, enumcolumn_unitcol_unit)
+ {
+expanded_locationexploc_start=expand_location(hint-Quoted 1 line
get_start_loc());+
expanded_locationexploc_finish=expand_location(hint-Quoted 1 line
get_next_loc());+@@ -1986,11 +2013,13 @@
get_affected_range(constfixit_hint*hi + intfinish_column;
+ if (col_unit==CU_DISPLAY_COLS)
+ {
+-start_column=location_compute_display_column(exploc_start);
++start_column
++ =location_compute_display_column(exploc_start, context-Quoted 1 line
tabstop);
+ if (
hint->insertion_p())
+ finish_column =start_column- 1;
+ else
+- finish_column =location_compute_display_column(exploc_finish);
++ finish_column
++ =location_compute_display_column(exploc_finish, context-Quoted 1 line
tabstop);
+ }
+ else
+ {
+@@ -2003,12 +2032,12 @@get_affected_range(constfixit_hint*hi
+ /* Get the range of display columns that would be printed for HINT. */
+
+ staticcolumn_range
+-get_printed_columns (constfixit_hint*hint) ++get_printed_columns (diagnostic_context*context, constfixit_hint*hint)
+ {
+expanded_locationexploc =expand_location(hint->get_start_loc());+- int start_column = location_compute_display_column (exploc); +- int hint_width = cpp_display_width (hint->get_string (), +- hint->get_length ());++ int
start_column=location_compute_display_column(exploc,context->tabstop);
++ inthint_width=cpp_display_width(hint->get_string(), hint-Quoted 1 line
get_length(),++
context->tabstop);
+ intfinal_hint_column=start_column+hint_width- 1; + if (hint->insertion_p())
+ {
+@@ -2018,7 +2047,8 @@get_printed_columns(constfixit_hint*h + {
+ exploc =expand_location(hint->get_next_loc()); + --exploc.column;
+- intfinish_column=location_compute_display_column(exploc); ++ intfinish_column
++ =location_compute_display_column(exploc,context->tabstop); + returncolumn_range(start_column,
+ MAX (finish_column,final_hint_column)); + }
+@@ -2035,12 +2065,14 @@ public:
+ correction (column_rangeaffected_bytes,
+column_rangeaffected_columns,
+column_rangeprinted_columns,
+- const char*new_text,size_tnew_text_len) ++ const char*new_text,size_tnew_text_len, ++ int tabstop)
+ :m_affected_bytes(affected_bytes),
+m_affected_columns(affected_columns),
+m_printed_columns(printed_columns),
+m_text(xstrdup (new_text)),
+m_byte_length(new_text_len),
++m_tabstop(tabstop),
+m_alloc_sz(new_text_len+ 1)
+ {
+compute_display_cols();
+@@ -2058,7 +2090,7 @@ public:
+
+ voidcompute_display_cols()
+ {
+-m_display_cols=cpp_display_width(m_text,m_byte_length); ++m_display_cols=cpp_display_width(m_text,m_byte_length,m_tabstop);
+ }
+
+ void overwrite (intdst_offset, constchar_span&src_span) +@@ -2086,6 +2118,7 @@ public:
+ char*m_text;
+size_tm_byte_length; /* Not including null-terminator. */ + intm_display_cols;
++ intm_tabstop;
+size_tm_alloc_sz;
+ };
+
+@@ -2121,13 +2154,15 @@correction::ensure_terminated()
+ classline_corrections
+ {
+ public:+- line_corrections (const char *filename, linenum_type row) +- : m_filename (filename), m_row (row)++
line_corrections(diagnostic_context*context, const char *filename,
++linenum_typerow)
++ :m_context(context),m_filename(filename),m_row(row) + {}
+ ~line_corrections ();
+
+ voidadd_hint(constfixit_hint*hint);
+
++diagnostic_context*m_context;
+ const char*m_filename;
+linenum_typem_row;
+auto_vec<correction *>m_corrections;
+@@ -2173,9 +2208,10 @@source_line::source_line(const char *fi
+ void
+line_corrections::add_hint(constfixit_hint*hint)
+ {
+-column_rangeaffected_bytes=get_affected_range(hint,CU_BYTES);
+-column_rangeaffected_columns=get_affected_range(hint,CU_DISPLAY_COLS);
+-column_rangeprinted_columns=get_printed_columns(hint); ++column_rangeaffected_bytes=get_affected_range(m_context, hint,CU_BYTES);
++column_rangeaffected_columns=get_affected_range(m_context, hint,
++CU_DISPLAY_COLS);
++column_rangeprinted_columns=get_printed_columns(m_context, hint);
+
+ /* Potentially consolidate. */
+ if (!m_corrections.is_empty ())
+@@ -2243,7 +2279,8 @@line_corrections::add_hint(constfixit_+affected_columns, +printed_columns, +hint->get_string(), +-hint->get_length())); ++hint->get_length(), ++m_context->tabstop));
+ }
+
+ /* If there are any fixit hints on source line ROW, print them. +@@ -2257,7 +2294,7 @@layout::print_trailing_fixits(linenum_t
+ {
+ /* Build a list of correction instances for the line, + potentially consolidating hints (for the sake of readability). */
+-line_correctionscorrections (m_exploc.file, row);
++line_correctionscorrections (m_context, m_exploc.file, row); + for (unsigned int i = 0; i < m_fixit_hints.length (); i++) + {
+ constfixit_hint*hint = m_fixit_hints[i];
+@@ -2499,15 +2536,11 @@layout::print_line(linenum_typerow) + if (!line)
+ return;
+
+-line_boundslbounds;
+print_leading_fixits(row);
+-print_source_line(row, line.get_buffer (), line.length (), &lbounds);
++ constline_boundslbounds
++ =print_source_line(row, line.get_buffer (), line.length ()); + if (should_print_annotation_line_p(row))+- { +- if (lbounds.m_first_non_ws != INT_MAX) +- lbounds.convert_to_display_cols (line); +- print_annotation_line (row, lbounds); +- }++
print_annotation_line(row, lbounds);
+ if (m_show_labels_p)
+print_any_labels(row);
+print_trailing_fixits(row);
+@@ -2670,9 +2703,11 @@test_layout_x_offset_display_utf8(const +
+char_spanlspan =location_get_source_line(tmp.get_filename (), 1);
+ASSERT_EQ(line_display_cols,
+-cpp_display_width(lspan.get_buffer (), lspan.length ()));
++cpp_display_width(lspan.get_buffer (), lspan.length (), ++ def_tabstop));
+ASSERT_EQ(line_display_cols,
+-location_compute_display_column(expand_location(line_end)));
++location_compute_display_column(expand_location(line_end),
++def_tabstop)); +ASSERT_EQ(0, memcmp (lspan.get_buffer () + (emoji_col- 1), + "\xf0\x9f\x98\x82\xf0\x9f\x98\x82", 8)); +
+@@ -2774,6 +2809,111 @@test_layout_x_offset_display_utf8(const +
+ }
+
++static void
++test_layout_x_offset_display_tab (constline_table_case&case_) ++{
++ const char *content
++ = "This line is very long, so that we can use it to test the logic for "
++ "clipping long lines. Also this: `\t' is a tab that occupies 1 byte and "
++ "a variable number of display columns, starting at column #103.\n";
++
++ /* Number of bytes in the line, subtracting one to remove the newline. */
++ const intline_bytes= strlen (content) - 1;
++
++ /* The column where the tab begins. Byte or display is the same as there are
++ no multibyte characters earlier on the line. */
++ const inttab_col= 103;
++
++ /* Effective extra size of the tab beyond what a single space would have taken
++ up, indexed by tabstop. */
++ static const intnum_tabstops= 11;
++ int extra_width[num_tabstops];
++ for (int tabstop = 1; tabstop !=num_tabstops; ++tabstop) ++ {
++ const intthis_tab_size= tabstop - (tab_col- 1) % tabstop; ++ extra_width[tabstop] =this_tab_size- 1;
++ }
++ /* Example of this calculation: if tabstop is 10, the tab starting at column
++ #103 has to expand into 8 spaces, covering columns 103-110, so that the
++ next character is at column #111. So it takes up 7 more columns than
++ a space would have taken up. */
++ASSERT_EQ(7, extra_width[10]);
++
++temp_source_filetmp (SELFTEST_LOCATION, ".c", content); ++line_table_testltt (case_);
++
++linemap_add(line_table,LC_ENTER, false, tmp.get_filename (), 1);
++
++location_tline_end=linemap_position_for_column(line_table,line_bytes);
++
++ /* Don't attempt to run the tests if column data might be unavailable. */
++ if (line_end>LINE_MAP_MAX_LOCATION_WITH_COLS)
++ return;
++
++ /* Check thatcpp_display_widthhandles the tabs as expected. */ ++char_spanlspan =location_get_source_line(tmp.get_filename (), 1);
++ASSERT_EQ('\t', *(lspan.get_buffer () + (tab_col- 1))); ++ for (int tabstop = 1; tabstop !=num_tabstops; ++tabstop) ++ {
++ASSERT_EQ(line_bytes+ extra_width[tabstop],
++cpp_display_width(lspan.get_buffer (), lspan.length (),
++ tabstop));
++ASSERT_EQ(line_bytes+ extra_width[tabstop],
++location_compute_display_column(expand_location(line_end),
++ tabstop)); ++ }
++
++ /* Check that the tab is expanded to the expected number of spaces. */
++rich_locationrichloc (line_table,
++linemap_position_for_column(line_table, ++tab_col+ 1)); ++ for (int tabstop = 1; tabstop !=num_tabstops; ++tabstop) ++ {
++test_diagnostic_contextdc;
++ dc.tabstop = tabstop;
++ layouttest_layout(&dc, &richloc,DK_ERROR);
++ test_layout.print_line (1);
++ const char *out =pp_formatted_text(dc.printer); ++ASSERT_EQ(NULL, strchr (out, '\t'));
++ const char*left_quote= strchr (out, '`');
++ const char*right_quote= strchr (out, '\'');
++ASSERT_NE(NULL,left_quote);
++ASSERT_NE(NULL,right_quote);
++ASSERT_EQ(right_quote-left_quote, extra_width[tabstop] + 2);
++ }
++
++ /* Check that the line is offset properly and that the tab is broken up
++ into the expected number of spaces when it is the last character skipped
++ over. */
++ for (int tabstop = 1; tabstop !=num_tabstops; ++tabstop) ++ {
++test_diagnostic_contextdc;
++ dc.tabstop = tabstop;
++ static const intsmall_width= 24;
++ dc.caret_max_width =small_width- 4;
++ dc.min_margin_width =test_left_margin-test_linenum_sep+ 1;
++ dc.show_line_numbers_p = true;
++ layouttest_layout(&dc, &richloc,DK_ERROR);
++ test_layout.print_line (1);
++
++ /* We have arranged things so that two columns will be printed before
++ the caret. If the tab results in more than one space, this should
++ produce two spaces in the output; otherwise, it will be a single space
++ preceded by the opening quote before the tab character. */ ++ const char *output1
++ = " 1 | ' is a tab that occupies 1 byte and a variable number of "
++ "display columns, starting at column #103.\n"
++ " | ^\n\n";
++ const char *output2
++ = " 1 | ` ' is a tab that occupies 1 byte and a variable number of "
++ "display columns, starting at column #103.\n"
++ " | ^\n\n";
++ const char*expected_output= (extra_width[tabstop] ? output1 : output2);
++ASSERT_STREQ(expected_output,pp_formatted_text(dc.printer));
++ }
++}
++
++
+ /* Verify thatdiagnostic_show_locusworks sanely on UNKNOWN_LOCATION. */
+
+ static void
+@@ -3854,6 +3994,27 @@test_one_liner_labels_utf8()
+ }
+ }
+
++/* Make sure that colorization codes don't interrupt a multibyte ++ sequence, which would corrupt it. */
++static void
++test_one_liner_colorized_utf8 ()
++{
++test_diagnostic_contextdc;
++ dc.colorize_source_p = true;
++diagnostic_color_init(&dc,DIAGNOSTICS_COLOR_YES);
++ constlocation_tpi =linemap_position_for_column(line_table, 12);
++rich_locationrichloc (line_table, pi);
++diagnostic_show_locus(&dc, &richloc,DK_ERROR);
++
++ /* In order to avoid having the test depend on exactly how the colorization
++ was effected, just confirm there are two pi characters in the output. */
++ const char *result =pp_formatted_text(dc.printer); ++ const char*null_term= result + strlen (result);
++ const char*first_pi= strstr (result, "\xcf\x80");
++ASSERT_TRUE(first_pi&&first_pi<=null_term- 2); ++ASSERT_STR_CONTAINS(first_pi+ 2, "\xcf\x80");
++}
++
+ /* Run the various one-liner tests. */
+
+ static void
+@@ -3884,8 +4045,10 @@test_diagnostic_show_locus_one_liner_utf+ASSERT_EQ(31,LOCATION_COLUMN(line_end));
+
+char_spanlspan =location_get_source_line(tmp.get_filename (), 1);
+-ASSERT_EQ(25,cpp_display_width(lspan.get_buffer (), lspan.length ()));
+-ASSERT_EQ(25,location_compute_display_column(expand_location(line_end)));
++ASSERT_EQ(25,cpp_display_width(lspan.get_buffer (), lspan.length (),
++def_tabstop));
++ASSERT_EQ(25,location_compute_display_column(expand_location(line_end),
++def_tabstop)); +
+test_one_liner_simple_caret_utf8();
+test_one_liner_caret_and_range_utf8();
+@@ -3900,6 +4063,7 @@test_diagnostic_show_locus_one_liner_utf+test_one_liner_many_fixits_1_utf8();
+test_one_liner_many_fixits_2_utf8();
+test_one_liner_labels_utf8();
++test_one_liner_colorized_utf8();
+ }
+
+ /* Verify thatgcc_rich_location::add_location_if_nearbyworks. */ +@@ -4272,25 +4436,28 @@test_overlapped_fixit_printing(const li + /* Unit-test theline_correctionsmachinery. */
+ASSERT_EQ(3, richloc.get_num_fixit_hints ());
+ constfixit_hint*hint_0= richloc.get_fixit_hint (0); +-ASSERT_EQ(column_range(12, 12),get_affected_range(hint_0,CU_BYTES));
+ASSERT_EQ(column_range(12, 12),
+-get_affected_range(hint_0,CU_DISPLAY_COLS));
+-ASSERT_EQ(column_range(12, 22),get_printed_columns(hint_0));
++get_affected_range(&dc,hint_0,CU_BYTES)); ++ASSERT_EQ(column_range(12, 12),
++get_affected_range(&dc,hint_0,CU_DISPLAY_COLS)); ++ASSERT_EQ(column_range(12, 22),get_printed_columns(&dc,hint_0));
+ constfixit_hint*hint_1= richloc.get_fixit_hint (1); +-ASSERT_EQ(column_range(18, 18),get_affected_range(hint_1,CU_BYTES));
+ASSERT_EQ(column_range(18, 18),
+-get_affected_range(hint_1,CU_DISPLAY_COLS));
+-ASSERT_EQ(column_range(18, 20),get_printed_columns(hint_1));
++get_affected_range(&dc,hint_1,CU_BYTES)); ++ASSERT_EQ(column_range(18, 18),
++get_affected_range(&dc,hint_1,CU_DISPLAY_COLS)); ++ASSERT_EQ(column_range(18, 20),get_printed_columns(&dc,hint_1));
+ constfixit_hint*hint_2= richloc.get_fixit_hint (2); +-ASSERT_EQ(column_range(29, 28),get_affected_range(hint_2,CU_BYTES));
+ASSERT_EQ(column_range(29, 28),
+-get_affected_range(hint_2,CU_DISPLAY_COLS));
+-ASSERT_EQ(column_range(29, 29),get_printed_columns(hint_2));
++get_affected_range(&dc,hint_2,CU_BYTES)); ++ASSERT_EQ(column_range(29, 28),
++get_affected_range(&dc,hint_2,CU_DISPLAY_COLS)); ++ASSERT_EQ(column_range(29, 29),get_printed_columns(&dc,hint_2));
+
+ /* Add each hint in turn to aline_correctionsinstance, + and verify that they are consolidated into one correction instance
+ as expected. */
+-line_correctionslc (tmp.get_filename (), 1);
++line_correctionslc (&dc, tmp.get_filename (), 1);
+
+ /* The first replace hint by itself. */
+ lc.add_hint (hint_0);
+@@ -4484,25 +4651,28 @@test_overlapped_fixit_printing_utf8(con + /* Unit-test theline_correctionsmachinery. */
+ASSERT_EQ(3, richloc.get_num_fixit_hints ());
+ constfixit_hint*hint_0= richloc.get_fixit_hint (0); +-ASSERT_EQ(column_range(14, 14),get_affected_range(hint_0,CU_BYTES));
++ASSERT_EQ(column_range(14, 14),
++get_affected_range(&dc,hint_0,CU_BYTES)); +ASSERT_EQ(column_range(12, 12),
+-get_affected_range(hint_0,CU_DISPLAY_COLS));
+-ASSERT_EQ(column_range(12, 22),get_printed_columns(hint_0));
++get_affected_range(&dc,hint_0,CU_DISPLAY_COLS)); ++ASSERT_EQ(column_range(12, 22),get_printed_columns(&dc,hint_0));
+ constfixit_hint*hint_1= richloc.get_fixit_hint (1); +-ASSERT_EQ(column_range(22, 22),get_affected_range(hint_1,CU_BYTES));
++ASSERT_EQ(column_range(22, 22),
++get_affected_range(&dc,hint_1,CU_BYTES)); +ASSERT_EQ(column_range(18, 18),
+-get_affected_range(hint_1,CU_DISPLAY_COLS));
+-ASSERT_EQ(column_range(18, 20),get_printed_columns(hint_1));
++get_affected_range(&dc,hint_1,CU_DISPLAY_COLS)); ++ASSERT_EQ(column_range(18, 20),get_printed_columns(&dc,hint_1));
+ constfixit_hint*hint_2= richloc.get_fixit_hint (2); +-ASSERT_EQ(column_range(35, 34),get_affected_range(hint_2,CU_BYTES));
++ASSERT_EQ(column_range(35, 34),
++get_affected_range(&dc,hint_2,CU_BYTES)); +ASSERT_EQ(column_range(30, 29),
+-get_affected_range(hint_2,CU_DISPLAY_COLS));
+-ASSERT_EQ(column_range(30, 30),get_printed_columns(hint_2));
++get_affected_range(&dc,hint_2,CU_DISPLAY_COLS)); ++ASSERT_EQ(column_range(30, 30),get_printed_columns(&dc,hint_2));
+
+ /* Add each hint in turn to aline_correctionsinstance, + and verify that they are consolidated into one correction instance
+ as expected. */
+-line_correctionslc (tmp.get_filename (), 1);
++line_correctionslc (&dc, tmp.get_filename (), 1);
+
+ /* The first replace hint by itself. */
+ lc.add_hint (hint_0);
+@@ -4689,6 +4859,8 @@test_overlapped_fixit_printing_2(const +
+ /* Two insertions, in the wrong order. */
+ {
++test_diagnostic_contextdc;
++
+rich_locationrichloc (line_table,col_20);
+ richloc.add_fixit_insert_before (col_23, "{");
+ richloc.add_fixit_insert_before (col_21, "}");
+@@ -4696,14 +4868,15 @@test_overlapped_fixit_printing_2(const + /* These fixits should be accepted; they can't be consolidated. */
+ASSERT_EQ(2, richloc.get_num_fixit_hints ());
+ constfixit_hint*hint_0= richloc.get_fixit_hint (0); +-ASSERT_EQ(column_range(23, 22),get_affected_range(hint_0,CU_BYTES));
+-ASSERT_EQ(column_range(23, 23),get_printed_columns(hint_0));
++ASSERT_EQ(column_range(23, 22),
++get_affected_range(&dc,hint_0,CU_BYTES)); ++ASSERT_EQ(column_range(23, 23),get_printed_columns(&dc,hint_0));
+ constfixit_hint*hint_1= richloc.get_fixit_hint (1); +-ASSERT_EQ(column_range(21, 20),get_affected_range(hint_1,CU_BYTES));
+-ASSERT_EQ(column_range(21, 21),get_printed_columns(hint_1));
++ASSERT_EQ(column_range(21, 20),
++get_affected_range(&dc,hint_1,CU_BYTES)); ++ASSERT_EQ(column_range(21, 21),get_printed_columns(&dc,hint_1));
+
+ /* Verify that they're printed correctly. */
+-test_diagnostic_contextdc;
+diagnostic_show_locus(&dc, &richloc,DK_ERROR);
+ASSERT_STREQ(" int a5[][0][0] = { 1, 2 };\n"
+ " ^\n"
+@@ -4955,6 +5128,65 @@test_fixit_deletion_affecting_newline(c + pp_formatted_text (dc.printer));
+ }
+
++static void
++test_tab_expansion (constline_table_case&case_)
++{
++ /* Create a tempfile and write some text to it. This example uses a tabstop
++ of 8, as the column numbers attempt to indicate:
++
++ .....................000.01111111111.22222333333 display ++ .....................123.90123456789.56789012345 columns */ ++ const char *content = " \t This: `\t' is a tab.\n"; ++ /* ....................000 00000011111 11111222222 byte ++ ....................123 45678901234 56789012345 columns */ ++
++ const int tabstop = 8;
++ const intfirst_non_ws_byte_col= 7;
++ const intright_quote_byte_col= 15;
++ const intlast_byte_col= 25;
++ASSERT_EQ(35,cpp_display_width(content,last_byte_col, tabstop));
++
++temp_source_filetmp (SELFTEST_LOCATION, ".c", content); ++line_table_testltt (case_);
++linemap_add(line_table,LC_ENTER, false, tmp.get_filename (), 1);
++
++ /* Don't attempt to run the tests if column data might be unavailable. */
++location_tline_end=linemap_position_for_column(line_table,last_byte_col);
++ if (line_end>LINE_MAP_MAX_LOCATION_WITH_COLS)
++ return;
++
++ /* Check that the leading whitespace with mixed tabs and spaces is expanded
++ into 11 spaces. Recall thatprint_line()also puts one space before
++ everything too. */
++ {
++test_diagnostic_contextdc;
++ dc.tabstop = tabstop;
++rich_locationrichloc (line_table,
++linemap_position_for_column(line_table, ++ first_non_ws_byte_col));
++ layouttest_layout(&dc, &richloc,DK_ERROR);
++ test_layout.print_line (1);
++ASSERT_STREQ(" This: ` ' is a tab.\n" ++ " ^\n",
++pp_formatted_text(dc.printer));
++ }
++
++ /* Confirm the display width was tracked correctly across the internal tab
++ as well. */
++ {
++test_diagnostic_contextdc;
++ dc.tabstop = tabstop;
++rich_locationrichloc (line_table,
++linemap_position_for_column(line_table, ++ right_quote_byte_col));
++ layouttest_layout(&dc, &richloc,DK_ERROR);
++ test_layout.print_line (1);
++ASSERT_STREQ(" This: ` ' is a tab.\n" ++ " ^\n",
++pp_formatted_text(dc.printer));
++ }
++}
++
+ /* Verify that line numbers are correctly printed for the case of + a multiline range in which the width of the line numbers changes + (e.g. from "9" to "10"). */
+@@ -5012,6 +5244,7 @@diagnostic_show_locus_c_tests()
+test_layout_range_for_multiple_lines();
+
+for_each_line_table_case(test_layout_x_offset_display_utf8); ++for_each_line_table_case(test_layout_x_offset_display_tab); +
+test_get_line_bytes_without_trailing_whitespace();
+
+@@ -5029,6 +5262,7 @@diagnostic_show_locus_c_tests()
+for_each_line_table_case(test_fixit_insert_containing_newline_2);
+for_each_line_table_case(test_fixit_replace_containing_newline); +for_each_line_table_case(test_fixit_deletion_affecting_newline); ++for_each_line_table_case(test_tab_expansion);
+
+test_line_numbers_multiline_range();
+ }meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +6
-1+diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi +--- a/gcc/doc/invoke.texi 2021-12-24 20:23:46.876739587 -0800 ++++ b/gcc/doc/invoke.texi 2021-12-25 01:20:53.487636494 -0800 +@@ -293,7 +293,9 @@ Objective-C and Objective-C++ Dialects}. + -fdiagnostics-show-template-tree -fno-elide-type @gol + -fdiagnostics-path-format=@r{[}none@r{|}separate-events@r{|}inline-events@r{]} @gol
+ -fdiagnostics-show-path-depths @gol
+--fno-show-column}
++-fno-show-column @gol ++-fdiagnostics-column-unit=@r{[}display@r{|}byte@r{]} @gol ++-fdiagnostics-column-origin=@var{origin}}
+
+ @item Warning Options
+ @xref{Warning Options,,Options to Request or Suppress Warnings}. +@@ -4424,6 +4426,31 @@ Do not print column numbers in diagnosti
+ diagnostics are being scanned by a program that does not understand the
+ column numbers, such as @command{dejagnu}.
+
++@item -fdiagnostics-column-unit=@var{UNIT}
++@opindex fdiagnostics-column-unit
++Select the units for the column number. This affects traditional diagnostics
++(in the absence of @option{-fno-show-column}), as well as JSON format
++diagnostics if requested.
++
++The default @var{UNIT}, @samp{display}, considers the number of display
++columns occupied by each character. This may be larger than the number
++of bytes required to encode the character, in the case of tab ++characters, or it may be smaller, in the case of multibyte characters.
++For example, the character ``GREEK SMALL LETTER PI (U+03C0)'' occupies one
++display column, and its UTF-8 encoding requires two bytes; the character
++``SLIGHTLY SMILING FACE (U+1F642)'' occupies two display columns, and
++its UTF-8 encoding requires four bytes.
++
++Setting @var{UNIT} to @samp{byte} changes the column number to the raw byte
++count in all cases, as was traditionally output by GCC prior to version 11.1.0.
++
++@item -fdiagnostics-column-origin=@var{ORIGIN} ++@opindex fdiagnostics-column-origin
++Select the origin for column numbers, i.e. the column number assigned to the
++first column. The default value of 1 corresponds to traditional GCC
++behavior and to the GNU style guide. Some utilities may perform better with an
++origin of 0; any non-negative value may be specified.
++
+ @item -fdiagnostics-format=@var{FORMAT}
+ @opindex fdiagnostics-format
+ Select a different format for printing diagnostics.
+@@ -4459,11 +4486,15 @@ might be printed in JSON form (after for + "locations": [
+ @{
+ "caret": @{
++ "display-column": 3,
++ "byte-column": 3,
+ "column": 3,
+ "file": "misleading-indentation.c", + "line": 15
+ @},
+ "finish": @{
++ "display-column": 4,
++ "byte-column": 4,
+ "column": 4,
+ "file": "misleading-indentation.c", + "line": 15
+@@ -4479,6 +4510,8 @@ might be printed in JSON form (after for + "locations": [
+ @{
+ "caret": @{
++ "display-column": 5,
++ "byte-column": 5,
+ "column": 5,
+ "file": "misleading-indentation.c", + "line": 17
+@@ -4488,6 +4521,7 @@ might be printed in JSON form (after for + "message": "...this statement, but the latter is @dots{}"
+ @}
+ ]
++ "column-origin": 1,
+ @},
+ @dots{}
+ ]
+@@ -4500,10 +4534,34 @@ A diagnostic has a @code{kind}. If this
+ an @code{option} key describing the command-line option controlling the
+ warning.
+
+-A diagnostic can contain zero or more locations. Each location has up+-to three positions within it: a @code{caret} position and optional +-@code{start} and @code{finish} positions. A location can also have +-an optional @code{label} string. For example, this error:++A diagnostic can contain zero or more locations. Each location has an
++optional @code{label} string and up to three positions within it: a ++@code{caret} position and optional @code{start} and @code{finish} positions.
++A position is described by a @code{file} name, a @code{line} number, and
++three numbers indicating a column position:
++@itemize @bullet
++
++@item
++@code{display-column} counts display columns, accounting for tabs and
++multibyte characters.
++
++@item
++@code{byte-column} counts raw bytes.
++
++@item
++@code{column} is equal to one of
++the previous two, as dictated by the @option{-fdiagnostics-column- unit}
++option.
++
++@end itemize
++All three columns are relative to the origin specified by ++@option{-fdiagnostics-column-origin}, which is typically equal to 1 but may
++be set, for instance, to 0 for compatibility with other utilities that
++number columns from 0. The column origin is recorded in the JSON output in
++the @code{column-origin} tag. In the remaining examples below, the extra
++column number outputs have been omitted for brevity.
++
++For example, this error:
+
+ @smallexample
+ bad-binary-ops.c:64:23: error: invalid operands to binary + (have 'S' @{aka
+diff --gita/gcc/input.cb/gcc/input.c
+--- a/gcc/input.c 2020-07-22 23:35:17.664388078 -0700 ++++ b/gcc/input.c 2021-12-25 01:20:53.487636494 -0800 +@@ -913,7 +913,7 @@make_location(location_tcaret,source_+ source line in order to calculate the display width. If that cannot be done
+ for any reason, then returns the byte column as a fallback. */
+ int
+-location_compute_display_column (expanded_locationexploc) ++location_compute_display_column (expanded_locationexploc, int tabstop)
+ {
+ if (!(exploc.file && *exploc.file && exploc.line && exploc.column))
+ return exploc.column;
+@@ -921,7 +921,7 @@location_compute_display_column(expande + /* If line is NULL, this function returns exploc.column which is the
+ desired fallback. */
+ returncpp_byte_column_to_display_column(line.get_buffer (), line.length (),
+- exploc.column); ++ exploc.column, tabstop);
+ }
+
+ /* Dump statistics to stderr about the memory usage of theline_table
+@@ -3608,33 +3608,46 @@test_line_offset_overflow()
+
+ voidtest_cpp_utf8()
+ {
++ const intdef_tabstop= 8;
+ /* Verify that wcwidth of invalid UTF-8 or control bytes is 1. */
+ {
+- intw_bad=cpp_display_width("\xf0!\x9f!\x98!\x82!", 8); ++ intw_bad=cpp_display_width("\xf0!\x9f!\x98!\x82!", 8,def_tabstop);
+ASSERT_EQ(8,w_bad);+- int w_ctrl = cpp_display_width ("\r\t\n\v\0\1", 6); +- ASSERT_EQ (6, w_ctrl);++ int
w_ctrl=cpp_display_width("\r\n\v\0\1", 5,def_tabstop); ++ASSERT_EQ(5,w_ctrl);
+ }
+
+ /* Verify that wcwidth of valid UTF-8 is as expected. */ + {
+- const intw_pi=cpp_display_width("\xcf\x80", 2); ++ const intw_pi=cpp_display_width("\xcf\x80", 2,def_tabstop);
+ASSERT_EQ(1,w_pi);
+- const intw_emoji=cpp_display_width("\xf0\x9f\x98\x82", 4); ++ const intw_emoji=cpp_display_width("\xf0\x9f\x98\x82", 4,def_tabstop);
+ASSERT_EQ(2,w_emoji);
+- const intw_umlaut_precomposed=cpp_display_width("\xc3\xbf", 2);
++ const intw_umlaut_precomposed=cpp_display_width("\xc3\xbf", 2,
++ def_tabstop); +ASSERT_EQ(1,w_umlaut_precomposed);
+- const intw_umlaut_combining=cpp_display_width("y\xcc\x88", 3);
++ const intw_umlaut_combining=cpp_display_width("y\xcc\x88", 3,
++def_tabstop); +ASSERT_EQ(1,w_umlaut_combining);
+- const intw_han=cpp_display_width("\xe4\xb8\xba", 3); ++ const intw_han=cpp_display_width("\xe4\xb8\xba", 3,def_tabstop);
+ASSERT_EQ(2,w_han);
+- const intw_ascii=cpp_display_width("GCC", 3);
++ const intw_ascii=cpp_display_width("GCC", 3,def_tabstop); +ASSERT_EQ(3,w_ascii);
+ const intw_mixed=cpp_display_width("\xcf\x80 = 3.14 \xf0\x9f\x98\x82"
+- "\x9f! \xe4\xb8\xba y\xcc\x88", 24);
++ "\x9f! \xe4\xb8\xba y\xcc\x88",
++ 24,def_tabstop); +ASSERT_EQ(18,w_mixed);
+ }
+
++ /* Verify that display width properly expands tabs. */ ++ {
++ const char *tstr = "\tabc\td";
++ASSERT_EQ(6,cpp_display_width(tstr, 6, 1));
++ASSERT_EQ(10,cpp_display_width(tstr, 6, 3));
++ASSERT_EQ(17,cpp_display_width(tstr, 6, 8));
++ASSERT_EQ(1,cpp_display_column_to_byte_column(tstr, 6, 7, 8));
++ }
++
+ /* Verify thatcpp_byte_column_to_display_columncan go past the end,
+ and similar edge cases. */
+ {
+@@ -3645,10 +3658,13 @@ voidtest_cpp_utf8()
+ /* 111122223456
+ Byte columns. */
++- ASSERT_EQ (5, cpp_display_width (str, 6)); +- ASSERT_EQ (105, cpp_byte_column_to_display_column (str, 6,106));
+-ASSERT_EQ(10000,cpp_byte_column_to_display_column(NULL, 0, 10000));
+-ASSERT_EQ(0,cpp_byte_column_to_display_column(NULL, 10000, 0));
++ASSERT_EQ(5,cpp_display_width(str, 6,def_tabstop)); ++ASSERT_EQ(105,
++cpp_byte_column_to_display_column(str, 6, 106,def_tabstop));
++ASSERT_EQ(10000,
++cpp_byte_column_to_display_column(NULL, 0, 10000,def_tabstop));
++ASSERT_EQ(0,
++cpp_byte_column_to_display_column(NULL, 10000, 0,def_tabstop));
+ }
+
+ /* Verify thatcpp_display_column_to_byte_columncan go past the end,
+@@ -3662,21 +3678,25 @@ voidtest_cpp_utf8()
+ /* 000000000000000000000000000000000111111
+ 111122223333444456666777788889999012345
+ Byte columns. */+- ASSERT_EQ (4, cpp_display_column_to_byte_column (str, 15, 2)); +- ASSERT_EQ (15, cpp_display_column_to_byte_column (str, 15,11));
+-ASSERT_EQ(115,cpp_display_column_to_byte_column(str, 15, 111));
+-ASSERT_EQ(10000,cpp_display_column_to_byte_column(NULL, 0, 10000));
+-ASSERT_EQ(0,cpp_display_column_to_byte_column(NULL, 10000, 0));
++ASSERT_EQ(4,cpp_display_column_to_byte_column(str, 15, 2,def_tabstop));
++ASSERT_EQ(15,
++cpp_display_column_to_byte_column(str, 15, 11,def_tabstop));
++ASSERT_EQ(115,
++cpp_display_column_to_byte_column(str, 15, 111,def_tabstop));
++ASSERT_EQ(10000,
++cpp_display_column_to_byte_column(NULL, 0, 10000,def_tabstop));
++ASSERT_EQ(0,
++cpp_display_column_to_byte_column(NULL, 10000, 0,def_tabstop));
+
+ /* Verify that we do not interrupt a UTF-8 sequence. */ +-ASSERT_EQ(4,cpp_display_column_to_byte_column(str, 15, 1)); ++ASSERT_EQ(4,cpp_display_column_to_byte_column(str, 15, 1,def_tabstop));
+
+ for (intbyte_col= 1;byte_col<= 15; ++byte_col)
+ {
+- const intdisp_col=cpp_byte_column_to_display_column(str, 15,
+-
byte_co l);
+- const intbyte_col2=cpp_display_column_to_byte_column(str, 15,
+-disp_col);
++ const intdisp_col
++ =cpp_byte_column_to_display_column(str, 15,byte_col,def_tabstop);
++ const intbyte_col2
++ =cpp_display_column_to_byte_column(str, 15,disp_col,def_tabstop);
+
+ /* If we ask for the display column in the middle of a UTF-8 + sequence, it will return the length of the partial sequence,
+diff --gita/gcc/input.hb/gcc/input.h
+--- a/gcc/input.h 2020-07-22 23:35:17.664388078 -0700 ++++ b/gcc/input.h 2021-12-25 01:20:53.487636494 -0800 +@@ -38,7 +38,9 @@STATIC_ASSERT(BUILTINS_LOCATION< RESER +
+ extern boolis_location_from_builtin_token(location_t);
+ externexpanded_locationexpand_location(location_t); +-extern intlocation_compute_display_column(expanded_location); ++
++extern intlocation_compute_display_column(expanded_locationexploc,
++ int tabstop); +
+ /* A class capturing the bounds of a buffer, to allow for run-time + bounds-checking in a checked build. */
+diff --gita/gcc/opts.cb/gcc/opts.c
+--- a/gcc/opts.c 2020-07-22 23:35:17.708388562 -0700 ++++ b/gcc/opts.c 2021-12-25 01:20:53.487636494 -0800 +@@ -2439,6 +2439,14 @@common_handle_option(structgcc_options+dc->parseable_fixits_p= value;
+ break;
+
++ caseOPT_fdiagnostics_column_unit_:
++dc->column_unit= (enum diagnostics_column_unit)value; ++ break;
++
++ caseOPT_fdiagnostics_column_origin_:
++dc->column_origin= value;
++ break;
++
+ caseOPT_fdiagnostics_show_cwe:
+dc->show_cwe= value;
+ break;
+@@ -2825,6 +2833,12 @@common_handle_option(structgcc_options+check_alignment_argument(loc, arg, "functions"); + break;
+
++ caseOPT_ftabstop_:
++ /* It is documented that we silently ignore silly values. */ ++ if (value >= 1 && value <= 100)
++ dc->tabstop = value;
++ break;
++
+ default:
+ /* If the flag was handled in a standard way, assume the lack of
+ processing here is intentional. */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-format-json-1.cb/gcc/testsuite/c-c++-common/diagnostic-format-json-1.c+--- a/gcc/testsuite/c-c++-common/diagnostic-format-json-1.c 2020- 07-22 23:35:17.908390765 -0700
++++ b/gcc/testsuite/c-c++-common/diagnostic-format-json-1.c 2021- 12-25 01:20:53.487636494 -0800
+@@ -8,17 +8,22 @@
+ We can't rely on any ordering of the keys. */
+
+ /* { dg-regexp "\"kind\": \"error\"" } */
++/* { dg-regexp "\"column-origin\": 1" } */
+ /* { dg-regexp "\"message\": \"#error message\"" } */
+
+ /* { dg-regexp "\"caret\": \{" } */
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 1.c\"" } */
+ /* { dg-regexp "\"line\": 4" } */
+ /* { dg-regexp "\"column\": 2" } */
++/* { dg-regexp "\"display-column\": 2" } */
++/* { dg-regexp "\"byte-column\": 2" } */
+
+ /* { dg-regexp "\"finish\": \{" } */
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 1.c\"" } */
+ /* { dg-regexp "\"line\": 4" } */
+ /* { dg-regexp "\"column\": 6" } */
++/* { dg-regexp "\"display-column\": 6" } */
++/* { dg-regexp "\"byte-column\": 6" } */
+
+ /* { dg-regexp "\"locations\": \[\[\{\}, \]*\]" } */
+ /* { dg-regexp "\"children\": \[\[\]\[\]\]" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-format-json-2.cb/gcc/testsuite/c-c++-common/diagnostic-format-json-2.c+--- a/gcc/testsuite/c-c++-common/diagnostic-format-json-2.c 2020- 07-22 23:35:17.908390765 -0700
++++ b/gcc/testsuite/c-c++-common/diagnostic-format-json-2.c 2021- 12-25 01:20:53.487636494 -0800
+@@ -8,6 +8,7 @@
+ We can't rely on any ordering of the keys. */
+
+ /* { dg-regexp "\"kind\": \"warning\"" } */
++/* { dg-regexp "\"column-origin\": 1" } */
+ /* { dg-regexp "\"message\": \"#warning message\"" } */
+ /* { dg-regexp "\"option\": \"-Wcpp\"" } */
+ /* { dg-regexp "\"option_url\": \"https:\[^\n\r\"\]*#index-Wcpp\"" } */
+@@ -16,11 +17,15 @@
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 2.c\"" } */
+ /* { dg-regexp "\"line\": 4" } */
+ /* { dg-regexp "\"column\": 2" } */
++/* { dg-regexp "\"display-column\": 2" } */
++/* { dg-regexp "\"byte-column\": 2" } */
+
+ /* { dg-regexp "\"finish\": \{" } */
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 2.c\"" } */
+ /* { dg-regexp "\"line\": 4" } */
+ /* { dg-regexp "\"column\": 8" } */
++/* { dg-regexp "\"display-column\": 8" } */
++/* { dg-regexp "\"byte-column\": 8" } */
+
+ /* { dg-regexp "\"locations\": \[\[\{\}, \]*\]" } */
+ /* { dg-regexp "\"children\": \[\[\]\[\]\]" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-format-json-3.cb/gcc/testsuite/c-c++-common/diagnostic-format-json-3.c+--- a/gcc/testsuite/c-c++-common/diagnostic-format-json-3.c 2020- 07-22 23:35:17.908390765 -0700
++++ b/gcc/testsuite/c-c++-common/diagnostic-format-json-3.c 2021- 12-25 01:20:53.487636494 -0800
+@@ -8,6 +8,7 @@
+ We can't rely on any ordering of the keys. */
+
+ /* { dg-regexp "\"kind\": \"error\"" } */
++/* { dg-regexp "\"column-origin\": 1" } */
+ /* { dg-regexp "\"message\": \"#warning message\"" } */
+ /* { dg-regexp "\"option\": \"-Werror=cpp\"" } */
+ /* { dg-regexp "\"option_url\": \"https:\[^\n\r\"\]*#index-Wcpp\"" } */
+@@ -16,11 +17,15 @@
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 3.c\"" } */
+ /* { dg-regexp "\"line\": 4" } */
+ /* { dg-regexp "\"column\": 2" } */
++/* { dg-regexp "\"display-column\": 2" } */
++/* { dg-regexp "\"byte-column\": 2" } */
+
+ /* { dg-regexp "\"finish\": \{" } */
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 3.c\"" } */
+ /* { dg-regexp "\"line\": 4" } */
+ /* { dg-regexp "\"column\": 8" } */
++/* { dg-regexp "\"display-column\": 8" } */
++/* { dg-regexp "\"byte-column\": 8" } */
+
+ /* { dg-regexp "\"locations\": \[\[\{\}, \]*\]" } */
+ /* { dg-regexp "\"children\": \[\[\]\[\]\]" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-format-json-4.cb/gcc/testsuite/c-c++-common/diagnostic-format-json-4.c+--- a/gcc/testsuite/c-c++-common/diagnostic-format-json-4.c 2020- 07-22 23:35:17.908390765 -0700
++++ b/gcc/testsuite/c-c++-common/diagnostic-format-json-4.c 2021- 12-25 01:20:53.487636494 -0800
+@@ -24,15 +24,20 @@ int test (void)
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 4.c\"" } */
+ /* { dg-regexp "\"line\": 8" } */
+ /* { dg-regexp "\"column\": 5" } */
++/* { dg-regexp "\"display-column\": 5" } */
++/* { dg-regexp "\"byte-column\": 5" } */
+
+ /* { dg-regexp "\"finish\": \{" } */
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 4.c\"" } */
+ /* { dg-regexp "\"line\": 8" } */
+ /* { dg-regexp "\"column\": 10" } */
++/* { dg-regexp "\"display-column\": 10" } */
++/* { dg-regexp "\"byte-column\": 10" } */
+
+ /* The outer diagnostic. */
+
+ /* { dg-regexp "\"kind\": \"warning\"" } */
++/* { dg-regexp "\"column-origin\": 1" } */
+ /* { dg-regexp "\"message\": \"this 'if' clause does not guard...\"" } */
+ /* { dg-regexp "\"option\": \"-Wmisleading-indentation\"" } */
+ /* { dg-regexp "\"option_url\": \"https:\[^\n\r\"\]*#index- Wmisleading-indentation\"" } */
+@@ -41,11 +46,15 @@ int test (void)
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 4.c\"" } */
+ /* { dg-regexp "\"line\": 6" } */
+ /* { dg-regexp "\"column\": 3" } */
++/* { dg-regexp "\"display-column\": 3" } */
++/* { dg-regexp "\"byte-column\": 3" } */
+
+ /* { dg-regexp "\"finish\": \{" } */
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 4.c\"" } */
+ /* { dg-regexp "\"line\": 6" } */
+ /* { dg-regexp "\"column\": 4" } */
++/* { dg-regexp "\"display-column\": 4" } */
++/* { dg-regexp "\"byte-column\": 4" } */
+
+ /* More from the nested diagnostic (we can't guarantee what order the
+ "file" keys are consumed). */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-format-json-5.cb/gcc/testsuite/c-c++-common/diagnostic-format-json-5.c+--- a/gcc/testsuite/c-c++-common/diagnostic-format-json-5.c 2020- 07-22 23:35:17.908390765 -0700
++++ b/gcc/testsuite/c-c++-common/diagnostic-format-json-5.c 2021- 12-25 01:20:53.487636494 -0800
+@@ -13,6 +13,7 @@ int test (struct s *ptr)
+ We can't rely on any ordering of the keys. */
+
+ /* { dg-regexp "\"kind\": \"error\"" } */
++/* { dg-regexp "\"column-origin\": 1" } */
+ /* { dg-regexp "\"message\": \".*\"" } */
+
+ /* Verify fix-it hints. */
+@@ -23,11 +24,15 @@ int test (struct s *ptr)
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 5.c\"" } */
+ /* { dg-regexp "\"line\": 8" } */
+ /* { dg-regexp "\"column\": 15" } */
++/* { dg-regexp "\"display-column\": 15" } */
++/* { dg-regexp "\"byte-column\": 15" } */
+
+ /* { dg-regexp "\"next\": \{" } */
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 5.c\"" } */
+ /* { dg-regexp "\"line\": 8" } */
+ /* { dg-regexp "\"column\": 21" } */
++/* { dg-regexp "\"display-column\": 21" } */
++/* { dg-regexp "\"byte-column\": 21" } */
+
+ /* { dg-regexp "\"fixits\": \[\[\{\}, \]*\]" } */
+
+@@ -35,11 +40,15 @@ int test (struct s *ptr)
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 5.c\"" } */
+ /* { dg-regexp "\"line\": 8" } */
+ /* { dg-regexp "\"column\": 15" } */
++/* { dg-regexp "\"display-column\": 15" } */
++/* { dg-regexp "\"byte-column\": 15" } */
+
+ /* { dg-regexp "\"finish\": \{" } */
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 5.c\"" } */
+ /* { dg-regexp "\"line\": 8" } */
+ /* { dg-regexp "\"column\": 20" } */
++/* { dg-regexp "\"display-column\": 20" } */
++/* { dg-regexp "\"byte-column\": 20" } */
+
+ /* { dg-regexp "\"locations\": \[\[\{\}, \]*\]" } */
+ /* { dg-regexp "\"children\": \[\[\]\[\]\]" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-units-1.cb/gcc/testsuite/c-c++-common/diagnostic-units-1.c
+--- a/gcc/testsuite/c-c++-common/diagnostic-units-1.c 1969-12-31 16:00:00.000000000 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-units-1.c 2021-12-25 01:20:53.487636494 -0800
+@@ -0,0 +1,28 @@
++/* { dg-do compile } */
++/* { dg-additional-options "-fdiagnostics-column-unit=byte -fshow- column -fdiagnostics-show-caret -Wmultichar" } */
++
++/* column units: bytes (via arg)
++ column origin: 1 (via default)
++ tabstop: 8 (via default) */
++
++/* This line starts with a tab. */
++ int c1 = 'c1'; /* { dg-warning "11: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c1 = 'c1';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces. */
++ int c2 = 'c2'; /* { dg-warning "18: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c2 = 'c2';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces and has an internal tab after
++ a space. */
++ int c3 = 'c3'; /* { dg-warning "19: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c3 = 'c3';
++ ^~~~
++ { dg-end-multiline-output "" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-units-2.cb/gcc/testsuite/c-c++-common/diagnostic-units-2.c
+--- a/gcc/testsuite/c-c++-common/diagnostic-units-2.c 1969-12-31 16:00:00.000000000 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-units-2.c 2021-12-25 01:20:53.487636494 -0800
+@@ -0,0 +1,28 @@
++/* { dg-do compile } */
++/* { dg-additional-options "-fdiagnostics-column-unit=display - fshow-column -fdiagnostics-show-caret -Wmultichar" } */
++
++/* column units: display (via arg)
++ column origin: 1 (via default)
++ tabstop: 8 (via default) */
++
++/* This line starts with a tab. */
++ int c1 = 'c1'; /* { dg-warning "18: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c1 = 'c1';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces. */
++ int c2 = 'c2'; /* { dg-warning "18: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c2 = 'c2';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces and has an internal tab after
++ a space. */
++ int c3 = 'c3'; /* { dg-warning "25: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c3 = 'c3';
++ ^~~~
++ { dg-end-multiline-output "" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-units-3.cb/gcc/testsuite/c-c++-common/diagnostic-units-3.c
+--- a/gcc/testsuite/c-c++-common/diagnostic-units-3.c 1969-12-31 16:00:00.000000000 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-units-3.c 2021-12-25 01:20:53.487636494 -0800
+@@ -0,0 +1,28 @@
++/* { dg-do compile } */
++/* { dg-additional-options "-fdiagnostics-column-unit=byte -fshow- column -fdiagnostics-show-caret -ftabstop=200 -Wmultichar" } */ ++
++/* column units: bytes (via arg)
++ column origin: 1 (via fallback from overly large argument) ++ tabstop: 8 (via default) */
++
++/* This line starts with a tab. */
++ int c1 = 'c1'; /* { dg-warning "11: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c1 = 'c1';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces. */
++ int c2 = 'c2'; /* { dg-warning "18: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c2 = 'c2';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces and has an internal tab after
++ a space. */
++ int c3 = 'c3'; /* { dg-warning "19: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c3 = 'c3';
++ ^~~~
++ { dg-end-multiline-output "" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-units-4.cb/gcc/testsuite/c-c++-common/diagnostic-units-4.c
+--- a/gcc/testsuite/c-c++-common/diagnostic-units-4.c 1969-12-31 16:00:00.000000000 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-units-4.c 2021-12-25 01:20:53.487636494 -0800
+@@ -0,0 +1,28 @@
++/* { dg-do compile } */
++/* { dg-additional-options "-fdiagnostics-column-unit=byte -fshow- column -fdiagnostics-show-caret -fdiagnostics-column-origin=0 - Wmultichar" } */
++
++/* column units: bytes (via arg)
++ column origin: 0 (via arg)
++ tabstop: 8 (via default) */
++
++/* This line starts with a tab. */
++ int c1 = 'c1'; /* { dg-warning "10: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c1 = 'c1';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces. */
++ int c2 = 'c2'; /* { dg-warning "17: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c2 = 'c2';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces and has an internal tab after
++ a space. */
++ int c3 = 'c3'; /* { dg-warning "18: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c3 = 'c3';
++ ^~~~
++ { dg-end-multiline-output "" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-units-5.cb/gcc/testsuite/c-c++-common/diagnostic-units-5.c
+--- a/gcc/testsuite/c-c++-common/diagnostic-units-5.c 1969-12-31 16:00:00.000000000 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-units-5.c 2021-12-25 01:20:53.491636427 -0800
+@@ -0,0 +1,28 @@
++/* { dg-do compile } */
++/* { dg-additional-options "-fdiagnostics-column-unit=display - fshow-column -fdiagnostics-show-caret -fdiagnostics-column-origin=0 - Wmultichar" } */
++
++/* column units: display (via arg)
++ column origin: 0 (via arg)
++ tabstop: 8 (via default) */
++
++/* This line starts with a tab. */
++ int c1 = 'c1'; /* { dg-warning "17: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c1 = 'c1';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces. */
++ int c2 = 'c2'; /* { dg-warning "17: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c2 = 'c2';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces and has an internal tab after
++ a space. */
++ int c3 = 'c3'; /* { dg-warning "24: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c3 = 'c3';
++ ^~~~
++ { dg-end-multiline-output "" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-units-6.cb/gcc/testsuite/c-c++-common/diagnostic-units-6.c
+--- a/gcc/testsuite/c-c++-common/diagnostic-units-6.c 1969-12-31 16:00:00.000000000 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-units-6.c 2021-12-25 01:20:53.491636427 -0800
+@@ -0,0 +1,28 @@
++/* { dg-do compile } */
++/* { dg-additional-options "-fdiagnostics-column-unit=byte -fshow- column -fdiagnostics-show-caret -fdiagnostics-column-origin=100 - Wmultichar" } */
++
++/* column units: bytes (via arg)
++ column origin: 100 (via arg)
++ tabstop: 8 (via default) */
++
++/* This line starts with a tab. */
++ int c1 = 'c1'; /* { dg-warning "110: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c1 = 'c1';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces. */
++ int c2 = 'c2'; /* { dg-warning "117: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c2 = 'c2';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces and has an internal tab after
++ a space. */
++ int c3 = 'c3'; /* { dg-warning "118: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c3 = 'c3';
++ ^~~~
++ { dg-end-multiline-output "" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-units-7.cb/gcc/testsuite/c-c++-common/diagnostic-units-7.c
+--- a/gcc/testsuite/c-c++-common/diagnostic-units-7.c 1969-12-31 16:00:00.000000000 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-units-7.c 2021-12-25 01:20:53.491636427 -0800
+@@ -0,0 +1,28 @@
++/* { dg-do compile } */
++/* { dg-additional-options "-fdiagnostics-column-unit=byte -fshow- column -fdiagnostics-show-caret -ftabstop=9 -Wmultichar" } */ ++
++/* column units: bytes (via arg)
++ column origin: 1 (via default)
++ tabstop: 9 (via arg) */
++
++/* This line starts with a tab. */
++ int c1 = 'c1'; /* { dg-warning "11: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c1 = 'c1';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces. */
++ int c2 = 'c2'; /* { dg-warning "19: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c2 = 'c2';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces and has an internal tab after
++ a space. */
++ int c3 = 'c3'; /* { dg-warning "20: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c3 = 'c3';
++ ^~~~
++ { dg-end-multiline-output "" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-units-8.cb/gcc/testsuite/c-c++-common/diagnostic-units-8.c
+--- a/gcc/testsuite/c-c++-common/diagnostic-units-8.c 1969-12-31 16:00:00.000000000 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-units-8.c 2021-12-25 01:20:53.491636427 -0800
+@@ -0,0 +1,28 @@
++/* { dg-do compile } */
++/* { dg-additional-options "-fshow-column -fdiagnostics-show-caret -ftabstop=9 -Wmultichar" } */
++
++/* column units: display (via default)
++ column origin: 1 (via default)
++ tabstop: 9 (via arg) */
++
++/* This line starts with a tab. */
++ int c1 = 'c1'; /* { dg-warning "19: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c1 = 'c1';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces. */
++ int c2 = 'c2'; /* { dg-warning "19: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c2 = 'c2';
++ ^~~~
++ { dg-end-multiline-output "" } */
++
++/* This line starts with <tabstop> spaces and has an internal tab after
++ a space. */
++ int c3 = 'c3'; /* { dg-warning "28: multi-character character constant" } */
++/* { dg-begin-multiline-output "" }
++ int c3 = 'c3';
++ ^~~~
++ { dg-end-multiline-output "" } */
+diff --gita/gcc/testsuite/c-c++-common/missing-close-symbol.cb/gcc/testsuite/c-c++-common/missing-close-symbol.c
+--- a/gcc/testsuite/c-c++-common/missing-close-symbol.c 2020- 07-22 23:35:17.912390810 -0700
++++ b/gcc/testsuite/c-c++-common/missing-close-symbol.c 2021- 12-25 01:20:53.491636427 -0800
+@@ -24,9 +24,9 @@ voidtest_static_assert_different_line( + _Static_assert(sizeof(int) >= sizeof(char), /* { dg-message "to match this '\\('" } */
+ "msg"; /* { dg-error "expected '\\)' before ';' token" } */
+ /* { dg-begin-multiline-output "" }+- "msg"; +- ^ +- )++ "msg";
++ ^
++ )
+ { dg-end-multiline-output "" } */
+ /* { dg-begin-multiline-output "" }
+ _Static_assert(sizeof(int) >= sizeof(char),
+diff --gita/gcc/testsuite/c-c++-common/Wmisleading-indentation-3.cb/gcc/testsuite/c-c++-common/Wmisleading-indentation-3.c+--- a/gcc/testsuite/c-c++-common/Wmisleading-indentation-3.c 2020- 07-22 23:35:17.904390722 -0700
++++ b/gcc/testsuite/c-c++-common/Wmisleading-indentation-3.c 2021- 12-25 01:20:53.487636494 -0800
+@@ -36,20 +36,20 @@ intfn_6(int a, int b, int c)
+ /* ... */
+ if ((err = foo (a)) != 0)
+ goto fail;
+- if ((err = foo (b)) != 0) /* { dg-message "2: this 'if' clause does not guard..." } */
++ if ((err = foo (b)) != 0) /* { dg-message "9: this 'if' clause does not guard..." } */
+ goto fail;
+- goto fail; /* { dg-message "3: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'" } */
++ goto fail; /* { dg-message "17: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'" } */
+ if ((err = foo (c)) != 0)
+ goto fail;
+ /* ... */
+
+ /* { dg-begin-multiline-output "" }+- if ((err = foo (b)) != 0) +- ^~++ if ((err = foo (b)) != 0)
++ ^~
+ { dg-end-multiline-output "" } */
+ /* { dg-begin-multiline-output "" }+- goto fail; +- ^~~~++ goto fail;
++ ^~~~
+ { dg-end-multiline-output "" } */
+
+ fail:
+diff --gita/gcc/testsuite/c-c++-common/Wmisleading-indentation.cb/gcc/testsuite/c-c++-common/Wmisleading-indentation.c+--- a/gcc/testsuite/c-c++-common/Wmisleading-indentation.c 2020- 07-22 23:35:17.904390722 -0700
++++ b/gcc/testsuite/c-c++-common/Wmisleading-indentation.c 2021- 12-25 01:20:53.487636494 -0800
+@@ -65,9 +65,9 @@ intfn_6(int a, int b, int c)
+ /* ... */
+ if ((err = foo (a)) != 0)
+ goto fail;
+- if ((err = foo (b)) != 0) /* { dg-message "2: this 'if' clause does not guard..." } */
++ if ((err = foo (b)) != 0) /* { dg-message "9: this 'if' clause does not guard..." } */
+ goto fail;
+- goto fail; /* { dg-message "3: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'" } */
++ goto fail; /* { dg-message "17: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'" } */
+ if ((err = foo (c)) != 0)
+ goto fail;
+ /* ... */
+@@ -178,7 +178,7 @@ voidfn_16_tabs(void)
+ while (flagA)
+ if (flagB) /* { dg-message "7: this 'if' clause does not guard..." } */
+ foo (0);
+- foo (1);/* { dg-message "2: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'" } */ ++ foo (1);/* { dg-message "9: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'" } */
+ }
+
+ voidfn_17_spaces(void)
+diff --gita/gcc/testsuite/gcc.dg/analyzer/malloc-paths-9.cb/gcc/testsuite/gcc.dg/analyzer/malloc-paths-9.c
+--- a/gcc/testsuite/gcc.dg/analyzer/malloc-paths-9.c 2020-07-22 23:35:18.124393144 -0700
++++ b/gcc/testsuite/gcc.dg/analyzer/malloc-paths-9.c 2021-12-25 01:20:53.491636427 -0800
+@@ -288,7 +288,7 @@ inttest_3(int x, int y)+ | | ~~~~~~~~~~ + | | | + | | (4) ...to here +- | NN | to dereference it above ++ | NN | to dereference it above + | NN | return *ptr; + | | ~~~~ + | | |+diff --git
a/gcc/testsuite/gcc.dg/bad-binary-ops.cb/gcc/testsuite/gcc.dg/bad-binary-ops.c
+--- a/gcc/testsuite/gcc.dg/bad-binary-ops.c 2020-07-22 23:35:18.128393190 -0700
++++ b/gcc/testsuite/gcc.dg/bad-binary-ops.c 2021-12-25 01:20:53.491636427 -0800
+@@ -35,10 +35,10 @@ inttest_2(void)
+ ~~~~~~~~~~~~~~~~
+ |
+ struct s+- + some_other_function ()); +- ^ ~~~~~~~~~~~~~~~~~~~~~~ +- | +- struct t++ +
some_other_function());
++ ^ ~~~~~~~~~~~~~~~~~~~~~~
++ |
++ struct t
+ { dg-end-multiline-output "" } */
+ }
+
+diff --gita/gcc/testsuite/gcc.dg/format/branch-1.cb/gcc/testsuite/gcc.dg/format/branch-1.c
+--- a/gcc/testsuite/gcc.dg/format/branch-1.c 2020-07-22 23:35:18.152393454 -0700
++++ b/gcc/testsuite/gcc.dg/format/branch-1.c 2021-12-25 01:20:53.491636427 -0800
+@@ -10,7 +10,7 @@ foo (long l, int nfoo)
+ {
+ printf ((nfoo > 1) ? "%d foos" : "%d foo", nfoo);
+ printf ((l > 1) ? "%d foos" /* { dg-warning "23:int" "wrong type in conditional expr" } */
+- : "%d foo", l); /* { dg-warning "16:int" "wrong type in conditional expr" } */
++ : "%d foo", l); /* { dg-warning "23:int" "wrong type in conditional expr" } */
+ printf ((l > 1) ? "%ld foos" : "%d foo", l); /* { dg-warning "36:int" "wrong type in conditional expr" } */
+ printf ((l > 1) ? "%d foos" : "%ld foo", l); /* { dg-warning "23:int" "wrong type in conditional expr" } */
+ /* Should allow one case to have extra arguments. */ +diff --gita/gcc/testsuite/gcc.dg/format/pr79210.cb/gcc/testsuite/gcc.dg/format/pr79210.c
+--- a/gcc/testsuite/gcc.dg/format/pr79210.c 2020-07-22 23:35:18.152393454 -0700
++++ b/gcc/testsuite/gcc.dg/format/pr79210.c 2021-12-25 01:20:53.491636427 -0800
+@@ -20,4 +20,4 @@ LPFC_VPORT_ATTR_R(peer_port_login,
+ "Allow peer ports on the same physical port to login to each "
+ "other.");
+
+-/* { dg-warning "6: format .%d. expects argument of type .int., but argument 4 has type .unsigned int. " "" { target *-*-* } .-12 } */ ++/* { dg-warning "20: format .%d. expects argument of type .int., but argument 4 has type .unsigned int. " "" { target *-*-* } .-12 } */
+diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.cb/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c
+--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions- 1.c 2020-07-22 23:35:18.172393674 -0700
++++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions- 1.c 2021-12-25 01:20:53.491636427 -0800
+@@ -540,15 +540,15 @@ voidtest_builtin_types_compatible_p(un +__emit_expression_range(0,
+ f (i) +__builtin_types_compatible_p(long, int)); /* { dg-warning "range" } */
+ /* { dg-begin-multiline-output "" }+- f (i) + __builtin_types_compatible_p (long, int)); +- ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~++ f (i) +
__builtin_types_compatible_p(long, int));
++
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ { dg-end-multiline-output "" } */
+
+__emit_expression_range(0,
+__builtin_types_compatible_p(long, int) + f (i)); /* { dg-warning "range" } */
+ /* { dg-begin-multiline-output "" }+- __builtin_types_compatible_p (long, int) + f (i)); +- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~++
__builtin_types_compatible_p(long, int) + f (i));
++
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
+ { dg-end-multiline-output "" } */
+ }
+
+@@ -671,8 +671,8 @@ voidtest_multiple_ordinary_maps(void)
+ /* { dg-begin-multiline-output "" }
+__emit_expression_range(0, foo (0,
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- "01234567890123456789012345678901234567890123456789012345678901234567 89012345678901234567890123456789012345678901234567890123456789")); +-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
++ "01234567890123456789012345678901234567890123456789012345678901234567 89012345678901234567890123456789012345678901234567890123456789")); ++
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ { dg-end-multiline-output "" } */
+
+ /* Another expression that transitions between ordinary maps; this
+@@ -685,8 +685,8 @@ voidtest_multiple_ordinary_maps(void)
+ /* { dg-begin-multiline-output "" }
+__emit_expression_range(0, foo (0, "01234567890123456789012345678901234567890123456789012345678901234567 890123456789012345678901234567890123456789012345678901234567890123456 789012345678901234567890123456789012345678901234567890123456789012345 678901234567890123456789012345678901234567890123456789012345678901234 567890123456789012345678901234567890123456789012345678901234567890123 456789012345678901234567890123456789012345678901234567890123456789012 345678901234567890123456789012345678901234567890123456789012345678901 234567890123456789012345678901234567890123456789012345678901234567890 123456789012345678901234567890123456789012345678901234567890123456789 012345678901234567890123456789012345678901234567890123456789012345678 901234567890123456789012345678901234567890123456789012345678901234567 890123456789012345678901234567890123456789012345678901234567890123456 789012345678901234567890123456789012345678901234567890123456789012345 678901234567890123456789012345678901234567890123456789012345678901234 567890123456789012345678901234567890123456789012345678901234567890123 456789012345678901234567890123456789012345678901234567890123456789012 345678901234567890123456789012345678901234567890123456789012345678901 234567890123456789012345678901234567890123456789012345678901234567890 123456789012345678901234567890123456789012345678901234567890123456789 012345678901234567890123456789012345678901234567890123456789012345678 901234567890123456789012345678901234567890123456789012345678901234567 890123456789012345678901234567890123456789012345678901234567890123456 789012345678901234567890123456789012345678901234567890123456789012345 678901234567890123456789012345678901234567890123456789012345678901234 567890123456789012345678901234567890123456789012345678901234567890123 456789012345678901234567890123456789012345678901234567890123456789012 345678901234567890123456789012345678901234567890123456789012345678901 234567890123456789012345678901234567890123456789012345678901234567890 123456789012345678901234567890123456789012345678901234567890123456789 012345678901234567890123456789012345678901234567890123456789012345678 901234567890123456789",
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+- 0)); +- ~~++ 0));
++ ~~
+ { dg-end-multiline-output "" } */
+ }
+
+diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.cb/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c
+--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals- 1.c 2020-07-22 23:35:18.172393674 -0700
++++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals- 1.c 2021-12-25 01:20:53.491636427 -0800
+@@ -335,11 +335,11 @@ pr87652 (const char *stem, int counter)
+ /* { dg-error "unable to read substring location: unable to read source line" "" { target c } 329 } */
+ /* { dg-error "unable to read substring location: failed to get ordinary maps" "" { target c++ } 329 } */
+ /* { dg-begin-multiline-output "" }
+- __emit_string_literal_range(__FILE__":%5d: " format, \
++ __emit_string_literal_range(__FILE__":%5d: " format, \
+ ^~~~~~~~
+ { dg-end-multiline-output "" { target c } } */
+ /* { dg-begin-multiline-output "" }
+- __emit_string_literal_range(__FILE__":%5d: " format, \
++ __emit_string_literal_range(__FILE__":%5d: " format, \
+ ^
+ { dg-end-multiline-output "" { target c++ } } */
+
+diff --gita/gcc/testsuite/gcc.dg/redecl-4.cb/gcc/testsuite/gcc.dg/redecl-4.c
+--- a/gcc/testsuite/gcc.dg/redecl-4.c 2020-07-22 23:35:18.192393895 -0700
++++ b/gcc/testsuite/gcc.dg/redecl-4.c 2021-12-25 01:20:53.491636427 -0800
+@@ -15,7 +15,7 @@ f (void)
+ /* Should get format warnings even though the built-in declaration
+ isn't "visible". */
+ printf (
+- "%s", 1); /* { dg-warning "8:format" } */
++ "%s", 1); /* { dg-warning "15:format" } */
+ /* The type of strcmp here should have no prototype. */ + if (0)
+ strcmp (1);
+diff --git a/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops.C b/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops.C
+--- a/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops.C 2020-07-22 23:35:17.972391472 -0700
++++ b/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops.C 2021-12-25 01:20:53.491636427 -0800
+@@ -33,10 +33,10 @@ inttest_2(void)
+ ~~~~~~~~~~~~~~~~
+ |
+ s+- + some_other_function ()); +- ^ ~~~~~~~~~~~~~~~~~~~~~~ +- | +- t++ +
some_other_function());
++ ^ ~~~~~~~~~~~~~~~~~~~~~~
++ |
++ t
+ { dg-end-multiline-output "" } */
+ }
+
+diff --git a/gcc/testsuite/g++.dg/parse/error4.C b/gcc/testsuite/g++.dg/parse/error4.C
+--- a/gcc/testsuite/g++.dg/parse/error4.C 2020-07-22 23:35:18.012391910 -0700
++++ b/gcc/testsuite/g++.dg/parse/error4.C 2021-12-25 01:20:53.491636427 -0800
+@@ -7,4 +7,4 @@ struct X {
+ int);
+ };
+
+-// { dg-error "4:'itn' has not been declared" "" { target *-*-* } 6 }
++// { dg-error "18:'itn' has not been declared" "" { target *-*-* } 6 }
+diff --git a/gcc/testsuite/gfortran.dg/diagnostic-format-json-1.F90 b/gcc/testsuite/gfortran.dg/diagnostic-format-json-1.F90 +--- a/gcc/testsuite/gfortran.dg/diagnostic-format-json-1.F90 2020- 07-22 23:35:18.512397420 -0700
++++ b/gcc/testsuite/gfortran.dg/diagnostic-format-json-1.F90 2021- 12-25 01:20:53.491636427 -0800
+@@ -8,17 +8,22 @@
+ ! We can't rely on any ordering of the keys.
+
+ ! { dg-regexp "\"kind\": \"error\"" }
++! { dg-regexp "\"column-origin\": 1" }
+ ! { dg-regexp "\"message\": \"#error message\"" }
+
+ ! { dg-regexp "\"caret\": \{" }
+ ! { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 1.F90\"" }
+ ! { dg-regexp "\"line\": 4" }
+ ! { dg-regexp "\"column\": 2" }
++! { dg-regexp "\"display-column\": 2" }
++! { dg-regexp "\"byte-column\": 2" }
+
+ ! { dg-regexp "\"finish\": \{" }
+ ! { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 1.F90\"" }
+ ! { dg-regexp "\"line\": 4" }
+ ! { dg-regexp "\"column\": 6" }
++! { dg-regexp "\"display-column\": 6" }
++! { dg-regexp "\"byte-column\": 6" }
+
+ ! { dg-regexp "\"locations\": \[\[\{\}, \]*\]" }
+ ! { dg-regexp "\"children\": \[\[\]\[\]\]" }
+diff --git a/gcc/testsuite/gfortran.dg/diagnostic-format-json-2.F90 b/gcc/testsuite/gfortran.dg/diagnostic-format-json-2.F90 +--- a/gcc/testsuite/gfortran.dg/diagnostic-format-json-2.F90 2020- 07-22 23:35:18.512397420 -0700
++++ b/gcc/testsuite/gfortran.dg/diagnostic-format-json-2.F90 2021- 12-25 01:20:53.491636427 -0800
+@@ -8,6 +8,7 @@
+ ! We can't rely on any ordering of the keys.
+
+ ! { dg-regexp "\"kind\": \"warning\"" }
++! { dg-regexp "\"column-origin\": 1" }
+ ! { dg-regexp "\"message\": \"#warning message\"" }
+ ! { dg-regexp "\"option\": \"-Wcpp\"" }
+ ! { dg-regexp "\"option_url\": \"\[^\n\r\"\]*#index-Wcpp\"" } +@@ -16,11 +17,15 @@
+ ! { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 2.F90\"" }
+ ! { dg-regexp "\"line\": 4" }
+ ! { dg-regexp "\"column\": 2" }
++! { dg-regexp "\"display-column\": 2" }
++! { dg-regexp "\"byte-column\": 2" }
+
+ ! { dg-regexp "\"finish\": \{" }
+ ! { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 2.F90\"" }
+ ! { dg-regexp "\"line\": 4" }
+ ! { dg-regexp "\"column\": 8" }
++! { dg-regexp "\"display-column\": 8" }
++! { dg-regexp "\"byte-column\": 8" }
+
+ ! { dg-regexp "\"locations\": \[\[\{\}, \]*\]" }
+ ! { dg-regexp "\"children\": \[\[\]\[\]\]" }
+diff --git a/gcc/testsuite/gfortran.dg/diagnostic-format-json-3.F90 b/gcc/testsuite/gfortran.dg/diagnostic-format-json-3.F90 +--- a/gcc/testsuite/gfortran.dg/diagnostic-format-json-3.F90 2020- 07-22 23:35:18.512397420 -0700
++++ b/gcc/testsuite/gfortran.dg/diagnostic-format-json-3.F90 2021- 12-25 01:20:53.491636427 -0800
+@@ -8,6 +8,7 @@
+ ! We can't rely on any ordering of the keys.
+
+ ! { dg-regexp "\"kind\": \"error\"" }
++! { dg-regexp "\"column-origin\": 1" }
+ ! { dg-regexp "\"message\": \"#warning message\"" }
+ ! { dg-regexp "\"option\": \"-Werror=cpp\"" }
+ ! { dg-regexp "\"option_url\": \"\[^\n\r\"\]*#index-Wcpp\"" } +@@ -16,11 +17,15 @@
+ ! { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 3.F90\"" }
+ ! { dg-regexp "\"line\": 4" }
+ ! { dg-regexp "\"column\": 2" }
++! { dg-regexp "\"display-column\": 2" }
++! { dg-regexp "\"byte-column\": 2" }
+
+ ! { dg-regexp "\"finish\": \{" }
+ ! { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 3.F90\"" }
+ ! { dg-regexp "\"line\": 4" }
+ ! { dg-regexp "\"column\": 8" }
++! { dg-regexp "\"display-column\": 8" }
++! { dg-regexp "\"byte-column\": 8" }
+
+ ! { dg-regexp "\"locations\": \[\[\{\}, \]*\]" }
+ ! { dg-regexp "\"children\": \[\[\]\[\]\]" }
+diff --git a/gcc/testsuite/go.dg/arrayclear.go b/gcc/testsuite/go.dg/arrayclear.go
+--- a/gcc/testsuite/go.dg/arrayclear.go 2020-07-22 23:35:18.588398257 -0700
++++ b/gcc/testsuite/go.dg/arrayclear.go 2021-12-25 01:20:53.491636427 -0800
+@@ -1,5 +1,8 @@
+ // { dg-do compile }
+ // { dg-options "-fgo-debug-optimization" }
++// This comment is necessary to work around a dejagnu bug. Otherwise, the
++// column of the second error message would equal the row of the first one, and
++// since the errors are also identical, dejagnu is not able to distinguish them.
+
+ package p
+
+diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/crash11.C b/gcc/testsuite/g++.old-deja/g++.brendan/crash11.C
+--- a/gcc/testsuite/g++.old-deja/g++.brendan/crash11.C 2020-07-22 23:35:18.048392308 -0700
++++ b/gcc/testsuite/g++.old-deja/g++.brendan/crash11.C 2021-12-25 01:20:53.491636427 -0800
+@@ -9,13 +9,13 @@ class A {
+ int h;
+ A() { i=10; j=20; }
+ virtual voidf1(){printf("i=%d j=%d\n",i,j); } +- friend virtual voidf2(){printf("i=%d j=%d\n",i,j); } // { dg-error "9:virtual functions cannot be friends" }
++ friend virtual voidf2(){printf("i=%d j=%d\n",i,j); } // { dg-error "16:virtual functions cannot be friends" }
+ };
+
+ class B : public A {
+ public:
+ virtual voidf1(){printf("i=%d j=%d\n",i,j); }// { dg-error "" } member.*// ERROR - member.*
+- friend virtual voidf2(){printf("i=%d j=%d\n",i,j); } // { dg-error "9:virtual functions cannot be friends" }
++ friend virtual voidf2(){printf("i=%d j=%d\n",i,j); } // { dg-error "16:virtual functions cannot be friends" }
+ // { dg-error "private" "" { target *-*-* } .-1 }
+ };
+
+diff --git a/gcc/testsuite/g++.old-deja/g++.pt/overload2.C b/gcc/testsuite/g++.old-deja/g++.pt/overload2.C
+--- a/gcc/testsuite/g++.old-deja/g++.pt/overload2.C 2020-07-22 23:35:18.072392572 -0700
++++ b/gcc/testsuite/g++.old-deja/g++.pt/overload2.C 2021-12-25 01:20:53.491636427 -0800
+@@ -12,5 +12,5 @@ int
+main()
+ {
+ C<char*> c;
+- char* p = Z(c.O); //{ dg-error "13:'Z' was not declared" } ambiguous c.O
++ char* p = Z(c.O); //{ dg-error "29:'Z' was not declared" } ambiguous c.O
+ }
+diff --git a/gcc/testsuite/g++.old-deja/g++.robertl/eb109.C b/gcc/testsuite/g++.old-deja/g++.robertl/eb109.C
+--- a/gcc/testsuite/g++.old-deja/g++.robertl/eb109.C 2020-07-22 23:35:18.076392617 -0700
++++ b/gcc/testsuite/g++.old-deja/g++.robertl/eb109.C 2021-12-25 01:20:53.491636427 -0800
+@@ -48,8 +48,8 @@ ostream& operator<<(ostream& os, Graph<V +
+ // The compiler does not like this line!!!!!!
+ typename Graph<VertexType, EdgeType>::Successor::iterator +- startN = G[i].second.begin(), // { dg-error "14:no match" } no index operator
+- endN = G[i].second.end(); // { dg-error "14:no match" } no index operator
++ startN = G[i].second.begin(), // { dg-error "21:no match" } no index operator
++ endN = G[i].second.end(); // { dg-error "21:no match" } no index operator
+
+ while(startN != endN)
+ {
+diff --git a/gcc/tree-diagnostic-path.cc b/gcc/tree-diagnostic- path.cc
+--- a/gcc/tree-diagnostic-path.cc 2020-07-22 23:35:18.628398698 -0700
++++ b/gcc/tree-diagnostic-path.cc 2021-12-25 01:20:53.491636427 -0800
+@@ -493,7 +493,7 @@default_tree_diagnostic_path_printer(di + doesn't have access to trees (for m_fndecl). */
+
+json::value*
+-default_tree_make_json_for_path (diagnostic_context*, ++default_tree_make_json_for_path (diagnostic_context*context, + constdiagnostic_path*path)
+ {
+json::array*path_array= newjson::array();
+@@ -504,7 +504,8 @@default_tree_make_json_for_path(diagnos +json::object*event_obj= newjson::object();
+ if (event.get_location ())
+ event_obj->set ("location",
+- json_from_expanded_location (event.get_location ()));
++ json_from_expanded_location (context, ++
event.get_location ()));
+label_textevent_text(event.get_desc (false));
+event_obj->set("description", newjson::string(event_text.m_buffer));
+ event_text.maybe_free ();
+diff --gita/libcpp/charset.cb/libcpp/charset.c
+--- a/libcpp/charset.c 2020-07-22 23:35:18.712399623 -0700 ++++ b/libcpp/charset.c 2021-12-25 01:20:53.491636427 -0800 +@@ -2276,49 +2276,90 @@cpp_string_location_reader::get_next() + return result;
+ }
+
+-/* Helper forcpp_byte_column_to_display_columnand its inverse. Given a
+- pointer to a UTF-8-encoded character, compute its display width. *INBUFP
+- points on entry to the start of the UTF-8 encoding of the character, and
+- is updated to point just after the last byte of the encoding. *INBYTESLEFTP
+- contains on entry the remaining size of the buffer into which *INBUFP
+- points, and this is also updated accordingly. If *INBUFP does not
++cpp_display_width_computation::
++cpp_display_width_computation (const char *data, intdata_length, int tabstop) :
++m_begin(data),
++m_next(m_begin),
++m_bytes_left(data_length),
++m_tabstop(tabstop),
++m_display_cols(0)
++{
++gcc_assert(m_tabstop> 0);
++}
++
++
++/* The main implementation function for classcpp_display_width_computation.
++m_nextpoints on entry to the start of the UTF-8 encoding of the next
++ character, and is updated to point just after the last byte of the encoding.
++m_bytes_leftcontains on entry the remaining size of the buffer into which
++m_nextpoints, and this is also updated accordingly. Ifm_nextdoes not
+ point to a valid UTF-8-encoded sequence, then it will be treated as a single
+- byte with display width 1. */
++ byte with display width 1.m_cur_display_colis the current display column,
++ relative to which tab stops should be expanded. Returns the display width of
++ the codepoint just processed. */
++-static inline int +-compute_next_display_width (const uchar **inbufp, size_t*inbytesleftp)
++int ++cpp_display_width_computation::process_next_codepoint ()
+ {
+cppchar_tc;
+- if (one_utf8_to_cppchar(inbufp, inbytesleftp, &c) != 0) ++ intnext_width;
++
++ if (*m_next== '\t')
++ {
++ ++m_next;
++ --m_bytes_left;
++next_width=m_tabstop- (m_display_cols%m_tabstop); ++ }
++ else if (one_utf8_to_cppchar((const uchar **)&m_next,&m_bytes_left, &c)
++ != 0)
+ {
+ /* Input is not convertible to UTF-8. This could be fine, e.g. in a
+ string literal, so don't complain. Just treat it as if it has a width
+ of one. */+- ++*inbufp; +- --*inbytesleftp; +- return 1;++ ++m_next;
++ --m_bytes_left;
++next_width= 1;
++ }
++ else
++ {
++ /*one_utf8_to_cppchar()has updatedm_nextandm_bytes_leftfor us. */
++next_width=cpp_wcwidth(c);
+ }
+
+- /*one_utf8_to_cppchar()has updated inbufp and inbytesleftp for us. */
+- returncpp_wcwidth(c);
++m_display_cols+=next_width;
++ returnnext_width;
++}
++
++/* Utility to advance the byte stream by the minimum amount needed to consume
++ N display columns. Returns the number of display columns that were
++ actually skipped. This could be less than N, if there was not enough data,
++ or more than N, if the last character to be skipped had a sufficiently large
++ display width. */
++int ++cpp_display_width_computation::advance_display_cols (int n) ++{
++ const int start =m_display_cols;
++ const int target = start + n;
++ while (m_display_cols< target && !done ())
++process_next_codepoint();
++ returnm_display_cols- start;
+ }
+
+ /* For the string of lengthDATA_LENGTHbytes that begins at DATA, compute
+ how many display columns are occupied by the first COLUMN bytes. COLUMN
+ may exceedDATA_LENGTH, in which case the phantom bytes at the end are
+- treated as if they have display width 1. */
++ treated as if they have display width 1. Tabs are expanded to the next tab
++ stop, relative to the start of DATA. */
+
+ int
+cpp_byte_column_to_display_column(const char *data, intdata_length,
+- int column)
++ int column, int tabstop)
+ {+- int display_col = 0; +- const uchar *udata = (const uchar *) data; + const int offset = MAX (0, column - data_length); +- size_t inbytesleft = column - offset; +- while (inbytesleft) +- display_col += compute_next_display_width (&udata,&inbytesleft);
+- returndisplay_col+ offset;
++cpp_display_width_computationdw (data, column - offset, tabstop);
++ while (!dw.done ())
++ dw.process_next_codepoint ();
++ return dw.display_cols_processed () + offset;
+ }
+
+ /* For the string of lengthDATA_LENGTHbytes that begins at DATA, compute
+@@ -2328,14 +2369,11 @@cpp_byte_column_to_display_column(const +
+ int
+cpp_display_column_to_byte_column(const char *data, intdata_length,
+- intdisplay_col)
++ intdisplay_col, int tabstop)
+ {+- int column = 0; +- const uchar *udata = (const uchar *) data; +- size_t inbytesleft = data_length; +- while (column < display_col && inbytesleft) +- column += compute_next_display_width (&udata, &inbytesleft); +- return data_length - inbytesleft + MAX (0, display_col - column);++
cpp_display_width_computationdw (data,data_length, tabstop); ++ const intavail_display= dw.advance_display_cols (display_col); ++ return dw.bytes_processed () + MAX (0,display_col-avail_display);
+ }
+
+ /* Our own version of wcwidth(). We don't use the actualwcwidth()in glibc,
+diff --gita/libcpp/include/cpplib.hb/libcpp/include/cpplib.h+--- a/libcpp/include/cpplib.h 2020-07-22 23:35:18.712399623 -0700 ++++ b/libcpp/include/cpplib.h 2021-12-25 01:20:53.491636427 -0800 +@@ -312,9 +312,6 @@ enumcpp_normalize_level{
+ carries all the options visible to the command line. */
+ structcpp_options
+ {+- /* Characters between tab stops. */ +- unsigned int tabstop; +-+ /* The language we're preprocessing. */
+ enumc_langlang;
+
+@@ -1322,14 +1319,43 @@ extern const char *cpp_get_userdef_suff+ (constcpp_token*);
+
+ /* Incharset.c*/
++
++/* A class to manage the state while converting a UTF-8 sequence tocppchar_t
++ and computing the display width one character at a time. */ ++classcpp_display_width_computation{
++ public:
++cpp_display_width_computation(const char *data, intdata_length, ++ int tabstop);
++ const char*next_byte() const { returnm_next; }
++ intbytes_processed() const { returnm_next-m_begin; } ++ intbytes_left() const { returnm_bytes_left; }
++ bool done () const { return !bytes_left (); }
++ intdisplay_cols_processed() const { returnm_display_cols; } ++
++ intprocess_next_codepoint();
++ intadvance_display_cols(int n);
++
++ private:
++ const char *constm_begin;
++ const char*m_next;
++size_tm_bytes_left;
++ const intm_tabstop;
++ intm_display_cols;
++};
++
++/* Convenience functions that are simple use cases for class ++ cpp_display_width_computation. Tab characters will be expanded to spaces
++ as determined by TABSTOP. */
+ intcpp_byte_column_to_display_column(const char *data, intdata_length,+- int column); +-inline int cpp_display_width (const char *data, int data_length)++ int column, int tabstop); ++inline int
cpp_display_width(const char *data, intdata_length, ++ int tabstop)
+ {
+- returncpp_byte_column_to_display_column(data,data_length,data_length);
++ returncpp_byte_column_to_display_column(data,data_length,data_length,
++ tabstop);
+ }
+ intcpp_display_column_to_byte_column(const char *data, intdata_length,
+- intdisplay_col); ++ intdisplay_col, int tabstop);
+ intcpp_wcwidth(cppchar_tc);
+
+ #endif /* !LIBCPP_CPPLIB_H*/meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +11
-0+diff --git a/libcpp/init.c b/libcpp/init.c +--- a/libcpp/init.c 2020-07-22 23:35:18.712399623 -0700 ++++ b/libcpp/init.c 2021-12-25 01:20:53.491636427 -0800 +@@ -190,7 +190,6 @@ cpp_create_reader (enum c_lang lang, cpp + CPP_OPTION (pfile, discard_comments) = 1; + CPP_OPTION (pfile, discard_comments_in_macro_exp) = 1; + CPP_OPTION (pfile, max_include_depth) = 200; +- CPP_OPTION (pfile, tabstop) = 8; + CPP_OPTION (pfile, operator_names) = 1; + CPP_OPTION (pfile, warn_trigraphs) = 2; + CPP_OPTION (pfile, warn_endif_labels) = 1;meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +1
-0@@ -0,0 +1,2270 @@ +From bd5e882cf6e0def3dd1bc106075d59a303fe0d1e Mon Sep 17 00:00:002001
meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +3
-0+From: David Malcolm <[email protected]> +Date: Mon, 18 Oct 2021 18:55:31 -0400 +Subject: [PATCH] diagnostics: escape non-ASCII source bytes forcertain
+ diagnosticsmeta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +5
-0+MIME-Version: 1.0 +Content-Type: text/plain; charset=utf8 +Content-Transfer-Encoding: 8bit + +This patch adds support to GCC's diagnostic subsystem for escapingcertain
meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +3
-0+bytes and Unicode characters when quoting source code. + +Specifically, this patch adds a new flag
rich_location::m_escape_on_output
+which is a hint from a diagnostic that non-ASCII bytes in the pertinentmeta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +12
-0+lines of the user's source code should be escaped when printed. + +The patch sets this for the following diagnostics: +- when complaining about stray bytes in the program (when these +are non-printable) +- when complaining about "null character(s) ignored"); +- for -Wnormalized= (and generate source ranges for such warnings) + +The escaping is controlled by a new option: + -fdiagnostics-escape-format=[unicode|bytes] + +For example, consider a diagnostic involing a source line containingthe
+string "before" followed by the Unicode character U+03C0 ("GREEK SMALLmeta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +2
-0+LETTER PI", with UTF-8 encoding 0xCF 0x80) followed by the byte 0xBF +(a stray UTF-8 trailing byte), followed by the string "after", wherethe
meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +25
-0+diagnostic highlights the U+03C0 character. + +By default, this line will be printed verbatim to the user when +reporting a diagnostic at it, as: + + beforeÏXafter + ^ + +(using X for the stray byte to avoid putting invalid UTF-8 in this +commit message) + +If the diagnostic sets the "escape" flag, it will be printed as: + + before<U+03C0><BF>after + ^~~~~~~~ + +with -fdiagnostics-escape-format=unicode (the default), or as: + + before<CF><80><BF>after + ^~~~~~~~ + +if the user supplies -fdiagnostics-escape-format=bytes. + +This only affects how the source is printed; it does not affect +how column numbers that are printed (as per -fdiagnostics-column-unit=
meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +4
-0+and -fdiagnostics-column-origin=). + +gcc/c-family/ChangeLog: + * c-lex.c (c_lex_with_flags): When complaining about non-printable
+ CPP_OTHER tokens, set the "escape on output" flag.meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +11
-0+ +gcc/ChangeLog: + * common.opt (fdiagnostics-escape-format=): New. + (diagnostics_escape_format): New enum. + (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE): New enum value. + (DIAGNOSTICS_ESCAPE_FORMAT_BYTES): Likewise. + * diagnostic-format-json.cc (json_end_diagnostic): Add + "escape-source" attribute. + * diagnostic-show-locus.c + (exploc_with_display_col::exploc_with_display_col): Replace + "tabstop" param with a cpp_char_column_policy and add an"aspect"
+ param. Use these to computem_display_colaccordingly. + (structchar_display_policy): New struct.
+ (layout::m_policy): New field.
+ (layout::m_escape_on_output): New field.
+ (def_policy): New function.
+ (make_range): Update for changes toexploc_with_display_colctor.
+ (default_print_decoded_ch): New.
+ (width_per_escaped_byte): New.
+ (escape_as_bytes_width): New.
+ (escape_as_bytes_print): New.
+ (escape_as_unicode_width): New.
+ (escape_as_unicode_print): New.
+ (make_policy): New.
+ (layout::layout): Initialize new fields. Updatem_explocctor
+ call for above change to ctor.
+ (layout::maybe_add_location_range): Update for changes to + exploc_with_display_col ctor.
+ (layout::calculate_x_offset_display): Update for change to + cpp_display_width.
+ (layout::print_source_line): Pass policy
+ tocpp_display_width_computation. Capturecpp_decoded_charwhen
+ calling process_next_codepoint. Move printing of source code to
+ m_policy.m_print_cb.
+ (line_label::line_label): Pass in policy rather than context. + (layout::print_any_labels): Update for change toline_labelctor.
+ (get_affected_range): Pass in policy rather than context, updating
+ calls tolocation_compute_display_columnaccordingly. + (get_printed_columns): Likewise, also forcpp_display_width. + (correction::correction): Pass in policy rather than tabstop. + (correction::compute_display_cols): Passm_policyrather than + m_tabstop tocpp_display_width.
+ (correction::m_tabstop): Replace with...
+ (correction::m_policy): ...this.
+ (line_corrections::line_corrections): Pass in policy rather than
+ context.
+ (line_corrections::m_context): Replace with...
+ (line_corrections::m_policy): ...this.
+ (line_corrections::add_hint): Update to usem_policyrather than
+ m_context.
+ (line_corrections::add_hint): Likewise.
+ (layout::print_trailing_fixits): Likewise.
+ (selftest::test_display_widths): New.
+ (selftest::test_layout_x_offset_display_utf8): Update to use + policy rather than tabstop.
+ (selftest::test_one_liner_labels_utf8): Add test of escaping + source lines.
+ (selftest::test_diagnostic_show_locus_one_liner_utf8): Update to
+ use policy rather than tabstop.
+ (selftest::test_overlapped_fixit_printing): Likewise. + (selftest::test_overlapped_fixit_printing_utf8): Likewise. + (selftest::test_overlapped_fixit_printing_2): Likewise. + (selftest::test_tab_expansion): Likewise.
+ (selftest::test_escaping_bytes_1): New.
+ (selftest::test_escaping_bytes_2): New.
+ (selftest::diagnostic_show_locus_c_tests): Call the new tests.
+ *diagnostic.c(diagnostic_initialize): Initialize + context->escape_format.
+ (convert_column_unit): Update to use default character width policy.
+ (selftest::test_diagnostic_get_location_text): Likewise. + *diagnostic.h(enumdiagnostics_escape_format): New enum. + (diagnostic_context::escape_format): New field.
+ * doc/invoke.texi (-fdiagnostics-escape-format=): New option. + (-fdiagnostics-format=): Add "escape-source" attribute to examples
+ of JSON output, and document it.
+ *input.c(location_compute_display_column): Pass in "policy" + rather than "tabstop", passing to
+ cpp_byte_column_to_display_column.
+ (selftest::test_cpp_utf8): Update to usecpp_char_column_policy.
+ *input.h(classcpp_char_column_policy): New forward decl. + (location_compute_display_column): Pass in "policy" rather than
+ "tabstop".
+ *opts.c(common_handle_option): Handle
+ OPT_fdiagnostics_escape_format_.
+ *selftest.c(temp_source_file::temp_source_file): New ctor + overload taking asize_t.
+ *selftest.h(temp_source_file::temp_source_file): Likewise.meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +3
-0+ +gcc/testsuite/ChangeLog: + * c-c++-common/diagnostic-format-json-1.c: Add regexp toconsume
+ "escape-source" attribute.
+ *c-c++-common/diagnostic-format-json-2.c: Likewise. + *c-c++-common/diagnostic-format-json-3.c: Likewise. + *c-c++-common/diagnostic-format-json-4.c: Likewise, twice. + *c-c++-common/diagnostic-format-json-5.c: Likewise. + *gcc.dg/cpp/warn-normalized-4-bytes.c: New test. + *gcc.dg/cpp/warn-normalized-4-unicode.c: New test. + *gcc.dg/encoding-issues-bytes.c: New test.
+ *gcc.dg/encoding-issues-unicode.c: New test.
+ * gfortran.dg/diagnostic-format-json-1.F90: Add regexp to consume
+ "escape-source" attribute.
+ * gfortran.dg/diagnostic-format-json-2.F90: Likewise. + * gfortran.dg/diagnostic-format-json-3.F90: Likewise.meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +5
-0+ +libcpp/ChangeLog: + * charset.c (convert_escape): Use encoding_rich_location when + complaining about nonprintable unknown escape sequences. + (cpp_display_width_computation::::cpp_display_width_computation):
+ Pass in policy rather than tabstop.
+ (cpp_display_width_computation::process_next_codepoint): Add "out"
+ param and populate *out if non-NULL.
+ (cpp_display_width_computation::advance_display_cols): Pass NULL
+ toprocess_next_codepoint.
+ (cpp_byte_column_to_display_column): Pass in policy rather than
+ tabstop. Pass NULL toprocess_next_codepoint.
+ (cpp_display_column_to_byte_column): Pass in policy rather than
+ tabstop.
+ *errors.c(cpp_diagnostic_get_current_location): New function,
+ splitting out the logic from...
+ (cpp_diagnostic): ...here.
+ (cpp_warning_at): New function.
+ (cpp_pedwarning_at): New function.
+ *include/cpplib.h(cpp_warning_at): New decl forrich_location.
+ (cpp_pedwarning_at): Likewise.
+ (structcpp_decoded_char): New.
+ (structcpp_char_column_policy): New.
+ (cpp_display_width_computation::cpp_display_width_computation ):
+ Replace "tabstop" param with "policy".
+ (cpp_display_width_computation::process_next_codepoint): Add "out"
+ param.
+ (cpp_display_width_computation::m_tabstop): Replace with... + (cpp_display_width_computation::m_policy): ...this. + (cpp_byte_column_to_display_column): Replace "tabstop" param with
+ "policy".
+ (cpp_display_width): Likewise.
+ (cpp_display_column_to_byte_column): Likewise.
+ *include/line-map.h(rich_location::escape_on_output_p):
New.
+ (rich_location::set_escape_on_output): New.
+ (rich_location::m_escape_on_output): New.
+ *internal.h(cpp_diagnostic_get_current_location): New decl. + (classencoding_rich_location): New.
+ *lex.c(skip_whitespace): Useencoding_rich_locationwhen + complaining about null characters.
+ (warn_about_normalization): Generate a source range when + complaining about improperly normalized tokens, rather than just a
+ point, and useencoding_rich_locationso that the source code + is escaped on printing.
+ *line-map.c(rich_location::rich_location): Initialize + m_escape_on_output.meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +5
-0+ +Signed-off-by: David Malcolm <[email protected]> + +CVE: CVE-2021-42574 +Upstream-Status: Backport[https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=bd5e882cf6e0def3dd1bc
106075d59a303fe0d1e]meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +37
-0+Signed-off-by: Pgowda <[email protected]> + +--- + gcc/c-family/c-lex.c | 6 +- + gcc/common.opt | 13 + + gcc/diagnostic-format-json.cc | 3 + + gcc/diagnostic-show-locus.c | 580 +++++++++++++++--- + gcc/diagnostic.c | 10 +- + gcc/diagnostic.h | 18 + + gcc/doc/invoke.texi | 43 +- + gcc/input.c | 62 +- + gcc/input.h | 7 +- + gcc/opts.c | 4 + + gcc/selftest.c | 15 + + gcc/selftest.h | 2 + + .../c-c++-common/diagnostic-format-json-1.c | 1 + + .../c-c++-common/diagnostic-format-json-2.c | 1 + + .../c-c++-common/diagnostic-format-json-3.c | 1 + + .../c-c++-common/diagnostic-format-json-4.c | 2 + + .../c-c++-common/diagnostic-format-json-5.c | 1 + + .../gcc.dg/cpp/warn-normalized-4-bytes.c | 21 + + .../gcc.dg/cpp/warn-normalized-4-unicode.c | 19 + + gcc/testsuite/gcc.dg/encoding-issues-bytes.c | Bin 0 -> 595 bytes + .../gcc.dg/encoding-issues-unicode.c | Bin 0 -> 613 bytes + .../gfortran.dg/diagnostic-format-json-1.F90 | 1 + + .../gfortran.dg/diagnostic-format-json-2.F90 | 1 + + .../gfortran.dg/diagnostic-format-json-3.F90 | 1 + + libcpp/charset.c | 63 +- + libcpp/errors.c | 82 ++- + libcpp/include/cpplib.h | 76 ++- + libcpp/include/line-map.h | 13 + + libcpp/internal.h | 23 + + libcpp/lex.c | 38 +- + libcpp/line-map.c | 3 +- + 31 files changed, 942 insertions(+), 168 deletions(-) + create mode 100644 gcc/testsuite/gcc.dg/cpp/warn-normalized-4-
bytes.c
+ create mode 100644 gcc/testsuite/gcc.dg/cpp/warn-normalized-4-unicode.c
+ create mode 100644gcc/testsuite/gcc.dg/encoding-issues-bytes.c
+ create mode 100644gcc/testsuite/gcc.dg/encoding-issues-unicode.cmeta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +13
-0+ +diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c +--- a/gcc/c-family/c-lex.c 2020-07-22 23:35:17.296384022 -0700 ++++ b/gcc/c-family/c-lex.c 2021-12-25 01:30:50.669689023 -0800 +@@ -587,7 +587,11 @@ c_lex_with_flags (tree *value, location_ + else if (ISGRAPH (c)) + error_at (*loc, "stray %qc in program", (int) c); + else +- error_at (*loc, "stray %<\\%o%> in program", (int) c); ++ { ++ rich_location rich_loc (line_table, *loc); ++ rich_loc.set_escape_on_output (true); ++ error_at (&rich_loc, "stray %<\\%o%> in program", (int)c);
++ }
+ }
+ goto retry;
+
+diff --git a/gcc/common.opt b/gcc/common.opt
+--- a/gcc/common.opt 2021-12-25 01:29:12.915317374 -0800 ++++ b/gcc/common.opt 2021-12-25 01:30:50.669689023 -0800 +@@ -1337,6 +1337,10 @@ fdiagnostics-format=
+ Common Joined RejectNegativeEnum(diagnostics_output_format)
+ -fdiagnostics-format=[text|json] Select output format. +
++fdiagnostics-escape-format=
++Common Joined RejectNegativeEnum(diagnostics_escape_format)++-fdiagnostics-escape-format=[unicode|bytes] Select how to escape non-printable-ASCII bytes in the source for diagnostics that suggest it.
++
+ ; Required for these enum values.
+ SourceInclude
+diagnostic.h
+@@ -1351,6 +1355,15 @@ EnumValue
+Enum(diagnostics_column_unit)String(byte)Value(DIAGNOSTICS_COLUMN_UNIT_BYTE)
+
+ Enum
++Name(diagnostics_escape_format) Type(int)
++
++EnumValue
++Enum(diagnostics_escape_format) String(unicode)Value(DIAGNOSTICS_ESCAPE_FORMAT_UNICODE)
++
++EnumValue
++Enum(diagnostics_escape_format) String(bytes)Value(DIAGNOSTICS_ESCAPE_FORMAT_BYTES)
++
++Enum
+Name(diagnostics_output_format)Type(int)
+
+ EnumValue
+diff --gita/gcc/diagnostic.cb/gcc/diagnostic.c
+--- a/gcc/diagnostic.c 2021-12-25 01:29:12.915317374 -0800 ++++ b/gcc/diagnostic.c 2021-12-25 01:30:50.669689023 -0800 +@@ -223,6 +223,7 @@diagnostic_initialize(diagnostic_contex+context->column_unit=DIAGNOSTICS_COLUMN_UNIT_DISPLAY; +context->column_origin= 1;
+context->tabstop= 8;
++context->escape_format=DIAGNOSTICS_ESCAPE_FORMAT_UNICODE; +context->edit_context_ptr= NULL;
+context->diagnostic_group_nesting_depth= 0;
+context->diagnostic_group_emission_count= 0;
+@@ -2152,8 +2153,8 @@test_diagnostic_get_location_text() + const char *const content = "smile \xf0\x9f\x98\x82\n"; + const intline_bytes= strlen (content) - 1;
+ const intdef_tabstop= 8;
+- const intdisplay_width=cpp_display_width(content,line_bytes,
+-def_tabstop); ++ constcpp_char_column_policypolicy (def_tabstop,cpp_wcwidth); ++ const intdisplay_width=cpp_display_width(content,line_bytes, policy);
+ASSERT_EQ(line_bytes- 2,display_width);
+temp_source_filetmp (SELFTEST_LOCATION, ".c", content); + const char *const fname = tmp.get_filename ();
+diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format- json.cc
+--- a/gcc/diagnostic-format-json.cc 2021-12-25 01:29:12.915317374 -0800
++++ b/gcc/diagnostic-format-json.cc 2021-12-25 01:30:50.669689023 -0800
+@@ -264,6 +264,9 @@json_end_diagnostic(diagnostic_context+json::value*path_value=context->make_json_for_path(context, path);
+diag_obj->set("path",path_value);
+ }
++
++diag_obj->set("escape-source",
++ newjson::literal(richloc->escape_on_output_p()));
+ }
+
+ /* No-op implementation of "begin_group_cb" for JSON output. */ +diff --gita/gcc/diagnostic.hb/gcc/diagnostic.h
+--- a/gcc/diagnostic.h 2021-12-25 01:29:12.919317307 -0800 ++++ b/gcc/diagnostic.h 2021-12-25 01:30:50.669689023 -0800 +@@ -38,6 +38,20 @@ enumdiagnostics_column_unit
+DIAGNOSTICS_COLUMN_UNIT_BYTE
+ };
+
++/* An enum for controlling how to print non-ASCII characters/bytes when
++ a diagnostic suggests escaping the source code on output. */ ++
++enumdiagnostics_escape_format
++{
++ /* Escape non-ASCII Unicode characters in the form <U+XXXX> and ++ non-UTF-8 bytes in the form <XX>. */
++DIAGNOSTICS_ESCAPE_FORMAT_UNICODE,
++
++ /* Escape non-ASCII bytes in the form <XX> (thus showing the underlying
++ encoding of non-ASCII Unicode characters). */
++DIAGNOSTICS_ESCAPE_FORMAT_BYTES
++};
++
+ /* Enum for overriding the standard output format. */
+
+ enumdiagnostics_output_format
+@@ -303,6 +317,10 @@ structdiagnostic_context
+ /* The size of the tabstop for tab expansion. */
+ int tabstop;
+
++ /* How should non-ASCII/non-printable bytes be escaped when ++ a diagnostic suggests escaping the source code on output. */ ++ enumdiagnostics_escape_formatescape_format;
++
+ /* If non-NULL, anedit_contextto which fix-it hints should be + applied, for generating patches. */
+edit_context*edit_context_ptr;
+diff --gita/gcc/diagnostic-show-locus.cb/gcc/diagnostic-show-locus.c
+--- a/gcc/diagnostic-show-locus.c 2021-12-25 01:29:12.919317307 -0800
++++ b/gcc/diagnostic-show-locus.c 2021-12-25 01:30:50.673688956 -0800
+@@ -175,10 +175,26 @@ enumcolumn_unit{
+ classexploc_with_display_col: publicexpanded_location
+ {
+ public:
+-exploc_with_display_col(constexpanded_location&exploc, int tabstop)+- : expanded_location (exploc), +- m_display_col (location_compute_display_column (exploc,tabstop))
+- {}
++exploc_with_display_col(constexpanded_location&exploc, ++ constcpp_char_column_policy&policy, ++ enumlocation_aspectaspect)
++ :expanded_location(exploc),
++m_display_col(location_compute_display_column(exploc, policy))
++ {
++ if (exploc.column > 0)
++ {
++ /*m_display_colis now the final column of the byte. ++ If escaping has happened, we may want the first column instead. */
++ if (aspect !=LOCATION_ASPECT_FINISH)
++ {
++expanded_locationprev_exploc(exploc);
++ prev_exploc.column--;
++ intprev_display_col
++ = (location_compute_display_column(prev_exploc, policy));
++m_display_col=prev_display_col+ 1;
++ }
++ }
++ }
+
+ intm_display_col;
+ };
+@@ -313,6 +329,31 @@test_line_span()
+
+ #endif /* #ifCHECKING_P*/
+
++/* A bundle of information containing how to print unicode ++ characters and bytes when quoting source code.
++
++ Provides a unified place to support escaping some subset ++ of characters to some format.
++
++ Extendschar_column_policy; printing is split out to avoid ++ libcpp having to know about pretty_printer. */
++
++structchar_display_policy: publiccpp_char_column_policy++{
++ public:
++char_display_policy(int tabstop,
++ int (*width_cb) (cppchar_tc),
++ void (*print_cb) (pretty_printer*pp, ++ constcpp_decoded_char&cp)) ++ :cpp_char_column_policy(tabstop,width_cb),
++m_print_cb(print_cb)
++ {
++ }
++
++ void (*m_print_cb) (pretty_printer*pp,
++ constcpp_decoded_char&cp);
++};
++
+ /* A class to control the overall layout when printing a diagnostic.
+
+ The layout is determined within the constructor.
+@@ -345,6 +386,8 @@ class layout
+
+ voidprint_line(linenum_typerow);
+
++ voidon_bad_codepoint(const char *ptr,cppchar_tch,size_tch_sz);
++
+ private:
+ boolwill_show_line_p(linenum_typerow) const;
+ voidprint_leading_fixits(linenum_typerow);
+@@ -386,6 +429,7 @@ class layout
+ private:
+diagnostic_context*m_context;
+pretty_printer*m_pp;
++char_display_policym_policy;
+location_tm_primary_loc;
+exploc_with_display_colm_exploc;
+ colorizerm_colorizer;
+@@ -398,6 +442,7 @@ class layout
+auto_vec<line_span>m_line_spans;
+ intm_linenum_width;
+ intm_x_offset_display;
++ boolm_escape_on_output;
+ };
+
+ /* Implementation of "class colorizer". */
+@@ -646,6 +691,11 @@layout_range::intersects_line_p(linenum
+ /* Default for when we don't care what the tab expansion is set to. */
+ static const intdef_tabstop= 8;
+
++staticcpp_char_column_policydef_policy()
++{
++ returncpp_char_column_policy(8,cpp_wcwidth);
++}
++
+ /* Create some expanded locations for testing layout_range. The filename
+ member of the explocs is set to the empty string. This member will only be
+ inspected by the calls tolocation_compute_display_column()made from the
+@@ -662,10 +712,13 @@make_range(intstart_line, intstart_co+ = {"",start_line,start_col, NULL, false};
+ constexpanded_locationfinish_exploc
+ = {"",end_line,end_col, NULL, false};
+- returnlayout_range(exploc_with_display_col(start_exploc,def_tabstop),
+-exploc_with_display_col(finish_exploc,def_tabstop),
++ returnlayout_range(exploc_with_display_col(start_exploc,def_policy(),
++ LOCATION_ASPECT_START ),
++exploc_with_display_col(finish_exploc,def_policy(),
++ LOCATION_ASPECT_FINIS H),
+SHOW_RANGE_WITHOUT_CARET,
+-exploc_with_display_col(start_exploc,def_tabstop),
++exploc_with_display_col(start_exploc,def_policy(),
++ LOCATION_ASPECT_CARET ),
+ 0, NULL);
+ }
+
+@@ -950,6 +1003,164 @@fixit_cmp(const void*p_a, const void * + returnhint_a->get_start_loc() -hint_b->get_start_loc();
+ }
+
++/* Callbacks for use when not escaping the source. */ ++
++/* The default callback forchar_column_policy::m_width_cbis cpp_wcwidth. */
++
++/* Callback forchar_display_policy::m_print_cbfor printing source chars
++ when not escaping the source. */
++
++static void
++default_print_decoded_ch (pretty_printer*pp,
++ constcpp_decoded_char&decoded_ch) ++{
++ for (const char *ptr = decoded_ch.m_start_byte;
++ ptr != decoded_ch.m_next_byte; ptr++)
++ {
++ if (*ptr == '\0' || *ptr == '\r')
++ {
++pp_space(pp);
++ continue;
++ }
++
++pp_character(pp, *ptr);
++ }
++}
++
++/* Callbacks for use with DIAGNOSTICS_ESCAPE_FORMAT_BYTES. */ ++
++static const intwidth_per_escaped_byte= 4;
++
++/* Callback forchar_column_policy::m_width_cbfor determining the ++ display width when escaping with DIAGNOSTICS_ESCAPE_FORMAT_BYTES. */
++
++static int
++escape_as_bytes_width (cppchar_tch)
++{
++ if (ch <0x80&& ISPRINT (ch))
++ returncpp_wcwidth(ch);
++ else
++ {
++ if (ch <=0x7F) return 1 *width_per_escaped_byte; ++ if (ch <=0x7FF) return 2 *width_per_escaped_byte; ++ if (ch <=0xFFFF) return 3 *width_per_escaped_byte; ++ return 4 *width_per_escaped_byte;
++ }
++}
++
++/* Callback forchar_display_policy::m_print_cbfor printing source chars
++ when escaping with DIAGNOSTICS_ESCAPE_FORMAT_BYTES. */ ++
++static void
++escape_as_bytes_print (pretty_printer*pp,
++ constcpp_decoded_char&decoded_ch) ++{
++ if (!decoded_ch.m_valid_ch)
++ {
++ for (const char *iter = decoded_ch.m_start_byte; ++ iter != decoded_ch.m_next_byte; ++iter)
++ {
++ char buf[16];
++ sprintf (buf, "<%02x>", (unsigned char)*iter); ++pp_string(pp, buf);
++ }
++ return;
++ }
++
++cppchar_tch = decoded_ch.m_ch;
++ if (ch <0x80&& ISPRINT (ch))
++pp_character(pp, ch);
++ else
++ {
++ for (const char *iter = decoded_ch.m_start_byte; ++ iter < decoded_ch.m_next_byte; ++iter)
++ {
++ char buf[16];
++ sprintf (buf, "<%02x>", (unsigned char)*iter); ++pp_string(pp, buf);
++ }
++ }
++}
++
++/* Callbacks for use with DIAGNOSTICS_ESCAPE_FORMAT_UNICODE. */ ++
++/* Callback forchar_column_policy::m_width_cbfor determining the ++ display width when escaping with DIAGNOSTICS_ESCAPE_FORMAT_UNICODE. */
++
++static int
++escape_as_unicode_width (cppchar_tch)
++{
++ if (ch <0x80&& ISPRINT (ch))
++ returncpp_wcwidth(ch);
++ else
++ {
++ // Width of "<U+%04x>"
++ if (ch >0xfffff)
++ return 10;
++ else if (ch >0xffff)
++ return 9;
++ else
++ return 8;
++ }
++}
++
++/* Callback forchar_display_policy::m_print_cbfor printing source chars
++ when escaping with DIAGNOSTICS_ESCAPE_FORMAT_UNICODE. */ ++
++static void
++escape_as_unicode_print (pretty_printer*pp,
++ constcpp_decoded_char&decoded_ch) ++{
++ if (!decoded_ch.m_valid_ch)
++ {
++escape_as_bytes_print(pp,decoded_ch);
++ return;
++ }
++
++cppchar_tch = decoded_ch.m_ch;
++ if (ch <0x80&& ISPRINT (ch))
++pp_character(pp, ch);
++ else
++ {
++ char buf[16];
++ sprintf (buf, "<U+%04X>", ch);
++pp_string(pp, buf);
++ }
++}
++
++/* Populate achar_display_policybased on DC and RICHLOC. */ ++
++staticchar_display_policy
++make_policy (constdiagnostic_context&dc,
++ constrich_location&richloc)
++{
++ /* The default is to not escape non-ASCII bytes. */ ++char_display_policyresult
++ (dc.tabstop,cpp_wcwidth,default_print_decoded_ch); ++
++ /* If the diagnostic suggests escaping non-ASCII bytes, then ++ use policy from user-supplied options. */
++ if (richloc.escape_on_output_p ())
++ {
++ result.m_undecoded_byte_width =width_per_escaped_byte; ++ switch (dc.escape_format)
++ {
++ default:
++gcc_unreachable();
++ caseDIAGNOSTICS_ESCAPE_FORMAT_UNICODE:
++ result.m_width_cb =escape_as_unicode_width;
++ result.m_print_cb =escape_as_unicode_print;
++ break;
++ caseDIAGNOSTICS_ESCAPE_FORMAT_BYTES:
++ result.m_width_cb =escape_as_bytes_width;
++ result.m_print_cb =escape_as_bytes_print;
++ break;
++ }
++ }
++
++ return result;
++}
++
+ /* Implementation of class layout. */
+
+ /* Constructor for class layout.
+@@ -966,8 +1177,10 @@layout::layout(diagnostic_context* con + diagnostic_tdiagnostic_kind)
+ :m_context(context),
+m_pp(context->printer),
++m_policy(make_policy(*context, *richloc)),
+m_primary_loc(richloc->get_range(0)->m_loc),
+-m_exploc(richloc->get_expanded_location(0),context->tabstop), ++m_exploc(richloc->get_expanded_location(0),m_policy, ++LOCATION_ASPECT_CARET),
+m_colorizer(context,diagnostic_kind),
+m_colorize_source_p(context->colorize_source_p),
+m_show_labels_p(context->show_labels_p),
+@@ -977,7 +1190,8 @@layout::layout(diagnostic_context* con +m_fixit_hints(richloc->get_num_fixit_hints()),
+m_line_spans(1 +richloc->get_num_locations()),
+m_linenum_width(0),
+-m_x_offset_display(0)
++m_x_offset_display(0),
++m_escape_on_output(richloc->escape_on_output_p())
+ {
+ for (unsigned int idx = 0; idx <richloc->get_num_locations(); idx++)
+ {
+@@ -1063,10 +1277,13 @@layout::maybe_add_location_range(const +
+ /* Everything is now known to be in the correct source file, + but it may require further sanitization. */
+-layout_rangeri (exploc_with_display_col(start, m_context-Quoted 1 line
tabstop),
+-
exploc_with_display_col(finish, m_context-Quoted 1 line
tabstop),
++
layout_rangeri (exploc_with_display_col(start,m_policy, ++LOCATION_ASPECT_START), ++exploc_with_display_col(finish,m_policy, ++LOCATION_ASPECT_FINISH), +loc_range->m_range_display_kind,
+-exploc_with_display_col(caret, m_context-Quoted 1 line
tabstop),
++
exploc_with_display_col(caret,m_policy, ++LOCATION_ASPECT_CARET), +original_idx,loc_range->m_label);
+
+ /* If we have a range that finishes before it starts (perhaps +@@ -1400,7 +1617,7 @@layout::calculate_x_offset_display() + =get_line_bytes_without_trailing_whitespace(line.get_buffer (),
+ line.length ()); + inteol_display_column
+- =cpp_display_width(line.get_buffer (),line_bytes, m_context-Quoted 1 line
tabstop);
++ =
cpp_display_width(line.get_buffer (),line_bytes,m_policy); + if (caret_display_column>eol_display_column
+ || !caret_display_column)
+ {
+@@ -1479,7 +1696,7 @@layout::print_source_line(linenum_type+ /* This object helps to keep track of which display column we are at, which is
+ necessary for computing the line bounds in display units, for doing
+ tab expansion, and for implementing m_x_offset_display. */ +-cpp_display_width_computationdw (line,line_bytes, m_context-Quoted 1 line
tabstop);
++
cpp_display_width_computationdw (line,line_bytes,m_policy); +
+ /* Skip the firstm_x_offset_displaydisplay columns. In case the leading
+ portion that will be skipped ends with a character with wcwidth > 1, then
+@@ -1527,7 +1744,8 @@layout::print_source_line(linenum_type+ tabs and replacing some control bytes with spaces as necessary. */
+ const char *c = dw.next_byte ();
+ const intstart_disp_col= dw.display_cols_processed () + 1; +- const intthis_display_width= dw.process_next_codepoint (); ++cpp_decoded_charcp;
++ const intthis_display_width= dw.process_next_codepoint (&cp);
+ if (*c == '\t')
+ {
+ /* The returned display width is the number of spaces into which the
+@@ -1536,15 +1754,6 @@layout::print_source_line(linenum_type+pp_space(m_pp);
+ continue;
+ }+- if (*c == '\0' || *c == '\r') +- { +- /* cpp_wcwidth() promises to return 1 for all control bytes, and we +- want to output these as a single space too, so this case is +- actually the same as the '\t' case. */ +- gcc_assert (this_display_width == 1); +- pp_space (m_pp); +- continue; +- }+
+ /* We have a (possibly multibyte) character to output; update the line
+ bounds if it is not whitespace. */
+@@ -1556,7 +1765,8 @@layout::print_source_line(linenum_type+ }
+
+ /* Output the character. */
+- while (c != dw.next_byte ())pp_character(m_pp, *c++); ++ m_policy.m_print_cb (m_pp, cp);
++ c = dw.next_byte ();
+ }
+print_newline();
+ return lbounds;
+@@ -1655,14 +1865,14 @@layout::print_annotation_line(linenum_t
+ classline_label
+ {
+ public:
+-line_label(diagnostic_context*context, intstate_idx, int column,
++line_label(constcpp_char_column_policy&policy,
++ intstate_idx, int column,
+label_texttext)
+ :m_state_idx(state_idx),m_column(column),
+m_text(text),m_label_line(0),m_has_vbar(true)
+ {
+ const int bytes = strlen (text.m_buffer);+- m_display_width +- = cpp_display_width (text.m_buffer, bytes, context->tabstop);++
m_display_width=cpp_display_width(text.m_buffer, bytes, policy);
+ }
+
+ /* Sorting is primarily by column, then by state index. */ +@@ -1722,7 +1932,7 @@layout::print_any_labels(linenum_typer + if (text.m_buffer == NULL)
+ continue;
+
+- labels.safe_push (line_label(m_context, i,disp_col, text)); ++ labels.safe_push (line_label(m_policy, i,disp_col, text)); + }
+ }
+
+@@ -2002,7 +2212,7 @@ public:
+
+ /* Get the range of bytes or display columns that HINT would affect. */
+ staticcolumn_range
+-get_affected_range (diagnostic_context*context, ++get_affected_range (constcpp_char_column_policy&policy, + constfixit_hint*hint, enumcolumn_unitcol_unit)
+ {
+expanded_locationexploc_start=expand_location(hint-Quoted 1 line
get_start_loc());+@@ -2013,13 +2223,11 @@
get_affected_range(diagnostic_context* + intfinish_column;
+ if (col_unit==CU_DISPLAY_COLS)
+ {+- start_column +- = location_compute_display_column (exploc_start, context-Quoted 1 line
tabstop);
++
start_column=location_compute_display_column(exploc_start, policy);
+ if (hint->insertion_p())
+ finish_column =start_column- 1;
+ else+- finish_column +- = location_compute_display_column (exploc_finish, context-Quoted 1 line
tabstop);
++ finish_column =
location_compute_display_column(exploc_finish, policy);
+ }
+ else
+ {
+@@ -2032,12 +2240,13 @@get_affected_range(diagnostic_context*
+ /* Get the range of display columns that would be printed for HINT. */
+
+ staticcolumn_range
+-get_printed_columns (diagnostic_context*context, constfixit_hint*hint)
++get_printed_columns (constcpp_char_column_policy&policy, ++ constfixit_hint*hint)
+ {
+expanded_locationexploc =expand_location(hint->get_start_loc());
+- intstart_column=location_compute_display_column(exploc,context->tabstop);
++ intstart_column=location_compute_display_column(exploc, policy);
+ inthint_width=cpp_display_width(hint->get_string(), hint-Quoted 1 line
get_length(),+-
context->tabstop); ++ policy);
+ intfinal_hint_column=start_column+hint_width- 1; + if (hint->insertion_p())
+ {
+@@ -2047,8 +2256,7 @@get_printed_columns(diagnostic_context+ {
+ exploc =expand_location(hint->get_next_loc()); + --exploc.column;+- int finish_column +- = location_compute_display_column (exploc, context->tabstop);++ int
finish_column=location_compute_display_column(exploc, policy);
+ returncolumn_range(start_column,
+ MAX (finish_column,final_hint_column)); + }
+@@ -2066,13 +2274,13 @@ public:
+column_rangeaffected_columns,
+column_rangeprinted_columns,
+ const char*new_text,size_tnew_text_len, +- int tabstop)
++ constcpp_char_column_policy&policy)
+ :m_affected_bytes(affected_bytes),
+m_affected_columns(affected_columns),
+m_printed_columns(printed_columns),
+m_text(xstrdup (new_text)),
+m_byte_length(new_text_len),
+-m_tabstop(tabstop),
++m_policy(policy),
+m_alloc_sz(new_text_len+ 1)
+ {
+compute_display_cols();
+@@ -2090,7 +2298,7 @@ public:
+
+ voidcompute_display_cols()
+ {
+-m_display_cols=cpp_display_width(m_text,m_byte_length,m_tabstop);
++m_display_cols=cpp_display_width(m_text,m_byte_length,m_policy);
+ }
+
+ void overwrite (intdst_offset, constchar_span&src_span) +@@ -2118,7 +2326,7 @@ public:
+ char*m_text;
+size_tm_byte_length; /* Not including null-terminator. */ + intm_display_cols;
+- intm_tabstop;
++ constcpp_char_column_policy&m_policy;
+size_tm_alloc_sz;
+ };
+
+@@ -2154,15 +2362,16 @@correction::ensure_terminated()
+ classline_corrections
+ {
+ public:
+-line_corrections(diagnostic_context*context, const char *filename,
++line_corrections(constchar_display_policy&policy, ++ const char *filename,
+linenum_typerow)
+- :m_context(context),m_filename(filename),m_row(row) ++ :m_policy(policy),m_filename(filename),m_row(row) + {}
+ ~line_corrections ();
+
+ voidadd_hint(constfixit_hint*hint);
+
+-diagnostic_context*m_context;
++ constchar_display_policy&m_policy;
+ const char*m_filename;
+linenum_typem_row;
+auto_vec<correction *>m_corrections;
+@@ -2208,10 +2417,10 @@source_line::source_line(const char *fi
+ void
+line_corrections::add_hint(constfixit_hint*hint)
+ {
+-column_rangeaffected_bytes=get_affected_range(m_context, hint,CU_BYTES);
+-column_rangeaffected_columns=get_affected_range(m_context, hint,
++column_rangeaffected_bytes=get_affected_range(m_policy, hint,CU_BYTES);
++column_rangeaffected_columns=get_affected_range(m_policy, hint,
+CU_DISPLAY_COLS);
+-column_rangeprinted_columns=get_printed_columns(m_context, hint);
++column_rangeprinted_columns=get_printed_columns(m_policy, hint);
+
+ /* Potentially consolidate. */
+ if (!m_corrections.is_empty ())
+@@ -2280,7 +2489,7 @@line_corrections::add_hint(constfixit_+printed_columns, +hint->get_string(), +hint->get_length(), +-m_context->tabstop)); ++m_policy));
+ }
+
+ /* If there are any fixit hints on source line ROW, print them. +@@ -2294,7 +2503,7 @@layout::print_trailing_fixits(linenum_t
+ {
+ /* Build a list of correction instances for the line, + potentially consolidating hints (for the sake of readability). */
+-line_correctionscorrections (m_context, m_exploc.file, row); ++line_correctionscorrections (m_policy, m_exploc.file, row); + for (unsigned int i = 0; i < m_fixit_hints.length (); i++) + {
+ constfixit_hint*hint = m_fixit_hints[i];
+@@ -2635,6 +2844,59 @@ namespace selftest {
+
+ /* Selftests for diagnostic_show_locus. */
+
++/* Verify thatcpp_display_widthcorrectly handles escaping. */ ++
++static void
++test_display_widths ()
++{
++gcc_rich_locationrichloc (UNKNOWN_LOCATION);
++
++ /* U+03C0 "GREEK SMALL LETTER PI". */
++ const char *pi = "\xCF\x80";
++ /* U+1F642 "SLIGHTLY SMILING FACE". */
++ const char *emoji = "\xF0\x9F\x99\x82";
++ /* Stray trailing byte of a UTF-8 character. */
++ const char *stray = "\xBF";
++ /* U+10FFFF. */
++ const char*max_codepoint= "\xF4\x8F\xBF\xBF";
++
++ /* No escaping. */
++ {
++test_diagnostic_contextdc;
++char_display_policypolicy (make_policy(dc, richloc)); ++ASSERT_EQ(cpp_display_width(pi, strlen (pi), policy), 1); ++ASSERT_EQ(cpp_display_width(emoji, strlen (emoji), policy), 2);
++ASSERT_EQ(cpp_display_width(stray, strlen (stray), policy), 1);
++ /* Don't check width of U+10FFFF; it's in a private use plane. */
++ }
++
++ richloc.set_escape_on_output (true);
++
++ {
++test_diagnostic_contextdc;
++ dc.escape_format =DIAGNOSTICS_ESCAPE_FORMAT_UNICODE; ++char_display_policypolicy (make_policy(dc, richloc)); ++ASSERT_EQ(cpp_display_width(pi, strlen (pi), policy), 8); ++ASSERT_EQ(cpp_display_width(emoji, strlen (emoji), policy), 9);
++ASSERT_EQ(cpp_display_width(stray, strlen (stray), policy), 4);
++ASSERT_EQ(cpp_display_width(max_codepoint, strlen (max_codepoint),
++ policy),
++ strlen ("<U+10FFFF>"));
++ }
++
++ {
++test_diagnostic_contextdc;
++ dc.escape_format =DIAGNOSTICS_ESCAPE_FORMAT_BYTES; ++char_display_policypolicy (make_policy(dc, richloc)); ++ASSERT_EQ(cpp_display_width(pi, strlen (pi), policy), 8); ++ASSERT_EQ(cpp_display_width(emoji, strlen (emoji), policy), 16);
++ASSERT_EQ(cpp_display_width(stray, strlen (stray), policy), 4);
++ASSERT_EQ(cpp_display_width(max_codepoint, strlen (max_codepoint),
++ policy),
++ 16);
++ }
++}
++
+ /* For precise tests of the layout, make clear where the source line will
+ start.test_left_marginsets the total byte count from the left side of the
+ screen to the start of source lines, after the line number and the separator,
+@@ -2704,10 +2966,10 @@test_layout_x_offset_display_utf8(const +char_spanlspan =location_get_source_line(tmp.get_filename (), 1);
+ASSERT_EQ(line_display_cols,
+cpp_display_width(lspan.get_buffer (), lspan.length (), +- def_tabstop));
++ def_policy ()));
+ASSERT_EQ(line_display_cols,
+location_compute_display_column(expand_location(line_end),
+-def_tabstop)); ++def_policy())); +ASSERT_EQ(0, memcmp (lspan.get_buffer () + (emoji_col- 1), + "\xf0\x9f\x98\x82\xf0\x9f\x98\x82", 8)); +
+@@ -2855,12 +3117,13 @@test_layout_x_offset_display_tab(const +ASSERT_EQ('\t', *(lspan.get_buffer () + (tab_col- 1))); + for (int tabstop = 1; tabstop !=num_tabstops; ++tabstop) + {
++cpp_char_column_policypolicy (tabstop,cpp_wcwidth); +ASSERT_EQ(line_bytes+ extra_width[tabstop],
+cpp_display_width(lspan.get_buffer (), lspan.length (),
+- tabstop));
++ policy));
+ASSERT_EQ(line_bytes+ extra_width[tabstop],
+location_compute_display_column(expand_location(line_end),
+- tabstop)); ++ policy)); + }
+
+ /* Check that the tab is expanded to the expected number of spaces. */
+@@ -3992,6 +4255,43 @@test_one_liner_labels_utf8()
+ " bb\xf0\x9f\x98\x82\xf0\x9f\x98\x82\n", +pp_formatted_text(dc.printer));
+ }
++
++ /* Example of escaping the source lines. */
++ {
++text_range_labellabel0 ("label 0\xf0\x9f\x98\x82"); ++text_range_labellabel1 ("label 1\xcf\x80");
++text_range_labellabel2 ("label 2\xcf\x80");
++gcc_rich_locationrichloc (foo, &label0);
++ richloc.add_range (bar,SHOW_RANGE_WITHOUT_CARET, &label1); ++ richloc.add_range (field,SHOW_RANGE_WITHOUT_CARET, &label2); ++ richloc.set_escape_on_output (true);
++
++ {
++test_diagnostic_contextdc;
++ dc.escape_format =DIAGNOSTICS_ESCAPE_FORMAT_UNICODE; ++diagnostic_show_locus(&dc, &richloc,DK_ERROR); ++ASSERT_STREQ(" <U+1F602>_foo = <U+03C0>_bar.<U+1F602>_field<U+03C0>;\n"
++ " ^~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~\n"++ " | | |\n" ++ " | | label 2\xcf\x80\n" ++ " | label 1\xcf\x80\n"++ " label 0\xf0\x9f\x98\x82\n", ++
pp_formatted_text(dc.printer)); ++ }
++ {
++test_diagnostic_contextdc;
++ dc.escape_format =DIAGNOSTICS_ESCAPE_FORMAT_BYTES; ++diagnostic_show_locus(&dc, &richloc,DK_ERROR); ++ASSERT_STREQ
++ (" <f0><9f><98><82>_foo = <cf><80>_bar.<f0><9f><98><82>_field<cf><80>;\n"
++ " ^~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"++ " | | |\n" ++ " | | label 2\xcf\x80\n" ++ " | label 1\xcf\x80\n"++ " label 0\xf0\x9f\x98\x82\n",
++pp_formatted_text(dc.printer));
++ }
++ }
+ }
+
+ /* Make sure that colorization codes don't interrupt a multibyte +@@ -4046,9 +4346,9 @@test_diagnostic_show_locus_one_liner_utf+
+char_spanlspan =location_get_source_line(tmp.get_filename (), 1);
+ASSERT_EQ(25,cpp_display_width(lspan.get_buffer (), lspan.length (),
+-def_tabstop));
++def_policy()));
+ASSERT_EQ(25,location_compute_display_column(expand_location(line_end),
+-def_tabstop)); ++def_policy())); +
+test_one_liner_simple_caret_utf8();
+test_one_liner_caret_and_range_utf8();
+@@ -4434,30 +4734,31 @@test_overlapped_fixit_printing(const li +pp_formatted_text(dc.printer));
+
+ /* Unit-test theline_correctionsmachinery. */
++char_display_policypolicy (make_policy(dc, richloc)); +ASSERT_EQ(3, richloc.get_num_fixit_hints ());
+ constfixit_hint*hint_0= richloc.get_fixit_hint (0); +ASSERT_EQ(column_range(12, 12),
+-get_affected_range(&dc,hint_0,CU_BYTES)); ++get_affected_range(policy,hint_0,CU_BYTES)); +ASSERT_EQ(column_range(12, 12),+- get_affected_range (&dc, hint_0, CU_DISPLAY_COLS)); +- ASSERT_EQ (column_range (12, 22), get_printed_columns (&dc,
hint_0));
++get_affected_range(policy,hint_0,CU_DISPLAY_COLS)); ++ASSERT_EQ(column_range(12, 22),get_printed_columns(policy,hint_0));
+ constfixit_hint*hint_1= richloc.get_fixit_hint (1); +ASSERT_EQ(column_range(18, 18),
+-get_affected_range(&dc,hint_1,CU_BYTES)); ++get_affected_range(policy,hint_1,CU_BYTES)); +ASSERT_EQ(column_range(18, 18),+- get_affected_range (&dc, hint_1, CU_DISPLAY_COLS)); +- ASSERT_EQ (column_range (18, 20), get_printed_columns (&dc,
hint_1));
++get_affected_range(policy,hint_1,CU_DISPLAY_COLS)); ++ASSERT_EQ(column_range(18, 20),get_printed_columns(policy,hint_1));
+ constfixit_hint*hint_2= richloc.get_fixit_hint (2); +ASSERT_EQ(column_range(29, 28),
+-get_affected_range(&dc,hint_2,CU_BYTES)); ++get_affected_range(policy,hint_2,CU_BYTES)); +ASSERT_EQ(column_range(29, 28),+- get_affected_range (&dc, hint_2, CU_DISPLAY_COLS)); +- ASSERT_EQ (column_range (29, 29), get_printed_columns (&dc,
hint_2));
++get_affected_range(policy,hint_2,CU_DISPLAY_COLS)); ++ASSERT_EQ(column_range(29, 29),get_printed_columns(policy,hint_2));
+
+ /* Add each hint in turn to aline_correctionsinstance, + and verify that they are consolidated into one correction instance
+ as expected. */
+-line_correctionslc (&dc, tmp.get_filename (), 1); ++line_correctionslc (policy, tmp.get_filename (), 1); +
+ /* The first replace hint by itself. */
+ lc.add_hint (hint_0);
+@@ -4649,30 +4950,31 @@test_overlapped_fixit_printing_utf8(con +pp_formatted_text(dc.printer));
+
+ /* Unit-test theline_correctionsmachinery. */
++char_display_policypolicy (make_policy(dc, richloc)); +ASSERT_EQ(3, richloc.get_num_fixit_hints ());
+ constfixit_hint*hint_0= richloc.get_fixit_hint (0); +ASSERT_EQ(column_range(14, 14),
+-get_affected_range(&dc,hint_0,CU_BYTES)); ++get_affected_range(policy,hint_0,CU_BYTES)); +ASSERT_EQ(column_range(12, 12),+- get_affected_range (&dc, hint_0, CU_DISPLAY_COLS)); +- ASSERT_EQ (column_range (12, 22), get_printed_columns (&dc,
hint_0));
++get_affected_range(policy,hint_0,CU_DISPLAY_COLS)); ++ASSERT_EQ(column_range(12, 22),get_printed_columns(policy,hint_0));
+ constfixit_hint*hint_1= richloc.get_fixit_hint (1); +ASSERT_EQ(column_range(22, 22),
+-get_affected_range(&dc,hint_1,CU_BYTES)); ++get_affected_range(policy,hint_1,CU_BYTES)); +ASSERT_EQ(column_range(18, 18),+- get_affected_range (&dc, hint_1, CU_DISPLAY_COLS)); +- ASSERT_EQ (column_range (18, 20), get_printed_columns (&dc,
hint_1));
++get_affected_range(policy,hint_1,CU_DISPLAY_COLS)); ++ASSERT_EQ(column_range(18, 20),get_printed_columns(policy,hint_1));
+ constfixit_hint*hint_2= richloc.get_fixit_hint (2); +ASSERT_EQ(column_range(35, 34),
+-get_affected_range(&dc,hint_2,CU_BYTES)); ++get_affected_range(policy,hint_2,CU_BYTES)); +ASSERT_EQ(column_range(30, 29),+- get_affected_range (&dc, hint_2, CU_DISPLAY_COLS)); +- ASSERT_EQ (column_range (30, 30), get_printed_columns (&dc,
hint_2));
++get_affected_range(policy,hint_2,CU_DISPLAY_COLS)); ++ASSERT_EQ(column_range(30, 30),get_printed_columns(policy,hint_2));
+
+ /* Add each hint in turn to aline_correctionsinstance, + and verify that they are consolidated into one correction instance
+ as expected. */
+-line_correctionslc (&dc, tmp.get_filename (), 1); ++line_correctionslc (policy, tmp.get_filename (), 1); +
+ /* The first replace hint by itself. */
+ lc.add_hint (hint_0);
+@@ -4866,15 +5168,16 @@test_overlapped_fixit_printing_2(const + richloc.add_fixit_insert_before (col_21, "}");
+
+ /* These fixits should be accepted; they can't be consolidated. */
++char_display_policypolicy (make_policy(dc, richloc)); +ASSERT_EQ(2, richloc.get_num_fixit_hints ());
+ constfixit_hint*hint_0= richloc.get_fixit_hint (0); +ASSERT_EQ(column_range(23, 22),+- get_affected_range (&dc, hint_0, CU_BYTES)); +- ASSERT_EQ (column_range (23, 23), get_printed_columns (&dc,
hint_0));
++get_affected_range(policy,hint_0,CU_BYTES)); ++ASSERT_EQ(column_range(23, 23),get_printed_columns(policy,hint_0));
+ constfixit_hint*hint_1= richloc.get_fixit_hint (1); +ASSERT_EQ(column_range(21, 20),+- get_affected_range (&dc, hint_1, CU_BYTES)); +- ASSERT_EQ (column_range (21, 21), get_printed_columns (&dc,
hint_1));
++get_affected_range(policy,hint_1,CU_BYTES)); ++ASSERT_EQ(column_range(21, 21),get_printed_columns(policy,hint_1));
+
+ /* Verify that they're printed correctly. */
+diagnostic_show_locus(&dc, &richloc,DK_ERROR);
+@@ -5141,10 +5444,11 @@test_tab_expansion(constline_table_cas+ ....................123 45678901234 56789012345 columns */ +
+ const int tabstop = 8;
++cpp_char_column_policypolicy (tabstop,cpp_wcwidth); + const intfirst_non_ws_byte_col= 7;
+ const intright_quote_byte_col= 15;
+ const intlast_byte_col= 25;
+-ASSERT_EQ(35,cpp_display_width(content,last_byte_col, tabstop));
++ASSERT_EQ(35,cpp_display_width(content,last_byte_col, policy));
+
+temp_source_filetmp (SELFTEST_LOCATION, ".c", content); +line_table_testltt (case_);
+@@ -5187,6 +5491,114 @@test_tab_expansion(constline_table_cas+ }
+ }
+
++/* Verify that the escaping machinery can cope with a variety of different
++ invalid bytes. */
++
++static void
++test_escaping_bytes_1 (constline_table_case&case_)
++{
++ const char content[] = "before\0\1\2\3\r\x80\xff""after\n"; ++ constsize_tsz = sizeof (content);
++temp_source_filetmp (SELFTEST_LOCATION, ".c", content, sz); ++line_table_testltt (case_);
++ constline_map_ordinary*ord_map=linemap_check_ordinary++ (linemap_add(line_table,LC_ENTER, false, tmp.get_filename (), 0));
++linemap_line_start(line_table, 1, 100);
++
++location_tfinish
++ =linemap_position_for_line_and_column(line_table,ord_map, 1, ++ strlen (content)); ++
++ if (finish >LINE_MAP_MAX_LOCATION_WITH_COLS)
++ return;
++
++ /* Locations of the NUL and \r bytes. */
++location_tnul_loc
++ =linemap_position_for_line_and_column(line_table,ord_map, 1, 7);
++location_tr_loc
++ =linemap_position_for_line_and_column(line_table,ord_map, 1, 11);
++gcc_rich_locationrichloc (nul_loc);
++ richloc.add_range (r_loc);
++
++ {
++test_diagnostic_contextdc;
++diagnostic_show_locus(&dc, &richloc,DK_ERROR);
++ASSERT_STREQ(" before \1\2\3 \x80\xff""after\n"
++ " ^ ~\n",
++pp_formatted_text(dc.printer));
++ }
++ richloc.set_escape_on_output (true);
++ {
++test_diagnostic_contextdc;
++ dc.escape_format =DIAGNOSTICS_ESCAPE_FORMAT_UNICODE; ++diagnostic_show_locus(&dc, &richloc,DK_ERROR);
++ASSERT_STREQ
++ (" before<U+0000><U+0001><U+0002><U+0003><U+000D><80><ff>after\n" ++ " ^~~~~~~~ ~~~~~~~~\n", ++pp_formatted_text(dc.printer));
++ }
++ {
++test_diagnostic_contextdc;
++ dc.escape_format =DIAGNOSTICS_ESCAPE_FORMAT_BYTES; ++diagnostic_show_locus(&dc, &richloc,DK_ERROR);
++ASSERT_STREQ(" before<00><01><02><03><0d><80><ff>after\n" ++ " ^~~~ ~~~~\n",
++pp_formatted_text(dc.printer));
++ }
++}
++
++/* As above, but verify that we handle the initial byte of a line ++ correctly. */
++
++static void
++test_escaping_bytes_2 (constline_table_case&case_)
++{
++ const char content[] = "\0after\n";
++ constsize_tsz = sizeof (content);
++temp_source_filetmp (SELFTEST_LOCATION, ".c", content, sz); ++line_table_testltt (case_);
++ constline_map_ordinary*ord_map=linemap_check_ordinary++ (linemap_add(line_table,LC_ENTER, false, tmp.get_filename (), 0));
++linemap_line_start(line_table, 1, 100);
++
++location_tfinish
++ =linemap_position_for_line_and_column(line_table,ord_map, 1, ++ strlen (content)); ++
++ if (finish >LINE_MAP_MAX_LOCATION_WITH_COLS)
++ return;
++
++ /* Location of the NUL byte. */
++location_tnul_loc
++ =linemap_position_for_line_and_column(line_table,ord_map, 1, 1);
++gcc_rich_locationrichloc (nul_loc);
++
++ {
++test_diagnostic_contextdc;
++diagnostic_show_locus(&dc, &richloc,DK_ERROR);
++ASSERT_STREQ(" after\n"
++ " ^\n",
++pp_formatted_text(dc.printer));
++ }
++ richloc.set_escape_on_output (true);
++ {
++test_diagnostic_contextdc;
++ dc.escape_format =DIAGNOSTICS_ESCAPE_FORMAT_UNICODE; ++diagnostic_show_locus(&dc, &richloc,DK_ERROR);
++ASSERT_STREQ(" <U+0000>after\n"
++ " ^~~~~~~~\n",
++pp_formatted_text(dc.printer));
++ }
++ {
++test_diagnostic_contextdc;
++ dc.escape_format =DIAGNOSTICS_ESCAPE_FORMAT_BYTES; ++diagnostic_show_locus(&dc, &richloc,DK_ERROR);
++ASSERT_STREQ(" <00>after\n"
++ " ^~~~\n",
++pp_formatted_text(dc.printer));
++ }
++}
++
+ /* Verify that line numbers are correctly printed for the case of + a multiline range in which the width of the line numbers changes + (e.g. from "9" to "10"). */
+@@ -5243,6 +5655,8 @@diagnostic_show_locus_c_tests()
+test_layout_range_for_single_line();
+test_layout_range_for_multiple_lines();
+
++test_display_widths();
++
+for_each_line_table_case(test_layout_x_offset_display_utf8); +for_each_line_table_case(test_layout_x_offset_display_tab); +
+@@ -5263,6 +5677,8 @@diagnostic_show_locus_c_tests()
+for_each_line_table_case(test_fixit_replace_containing_newline); +for_each_line_table_case(test_fixit_deletion_affecting_newline); +for_each_line_table_case(test_tab_expansion);
++for_each_line_table_case(test_escaping_bytes_1);
++for_each_line_table_case(test_escaping_bytes_2);
+
+test_line_numbers_multiline_range();
+ }
+diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi +--- a/gcc/doc/invoke.texi 2021-12-25 01:29:12.927317174 -0800 ++++ b/gcc/doc/invoke.texi 2021-12-25 01:30:50.681688823 -0800 +@@ -295,7 +295,8 @@ Objective-C and Objective-C++ Dialects}.
+ -fdiagnostics-show-path-depths @gol
+ -fno-show-column @gol
+ -fdiagnostics-column-unit=@r{[}display@r{|}byte@r{]} @gol +--fdiagnostics-column-origin=@var{origin}} ++-fdiagnostics-column-origin=@var{origin} @gol ++-fdiagnostics-escape-format=@r{[}unicode@r{|}bytes@r{]}} +
+ @item Warning Options
+ @xref{Warning Options,,Options to Request or Suppress Warnings}. +@@ -4451,6 +4452,38 @@ first column. The default value of 1 co
+ behavior and to the GNU style guide. Some utilities may perform better with an
+ origin of 0; any non-negative value may be specified.
+
++@item -fdiagnostics-escape-format=@var{FORMAT} ++@opindex fdiagnostics-escape-format
++When GCC prints pertinent source lines for a diagnostic it normally attempts
++to print the source bytes directly. However, some diagnostics relate to encoding
++issues in the source file, such as malformed UTF-8, or issues with Unicode
++normalization. These diagnostics are flagged so that GCC will escape bytes
++that are not printable ASCII when printing their pertinent source lines.
++
++This option controls how such bytes should be escaped. ++
++The default @var{FORMAT}, @samp{unicode} displays Unicode characters that
++are not printable ASCII in the form @samp{<U+XXXX>}, and bytes that do not
++correspond to a Unicode character validly-encoded in UTF-8-encoded will be
++displayed as hexadecimal in the form @samp{<XX>}.
++
++For example, a source line containing the string @samp{before} followed by the
++Unicode character U+03C0 (``GREEK SMALL LETTER PI'', with UTF-8 encoding
++0xCF0x80) followed by the byte0xBF(a stray UTF-8 trailing byte), followed by
++the string @samp{after} will be printed for such a diagnostic as:
++
++@smallexample
++ before<U+03C0><BF>after
++@end smallexample
++
++Setting @var{FORMAT} to @samp{bytes} will display all non- printable-ASCII bytes
++in the form @samp{<XX>}, thus showing the underlying encoding of non-ASCII
++Unicode characters. For the example above, the following will be printed:
++
++@smallexample
++ before<CF><80><BF>after
++@end smallexample
++
+ @item -fdiagnostics-format=@var{FORMAT}
+ @opindex fdiagnostics-format
+ Select a different format for printing diagnostics.
+@@ -4518,9 +4551,11 @@ might be printed in JSON form (after for + @}
+ @}
+ ],
++ "escape-source": false,
+ "message": "...this statement, but the latter is @dots{}"
+ @}
+ ]
++ "escape-source": false,
+ "column-origin": 1,
+ @},
+ @dots{}
+@@ -4607,6 +4642,7 @@ of the expression, which have labels. I + "label": "T @{aka struct t@}"
+ @}
+ ],
++ "escape-source": false,
+ "message": "invalid operands to binary + @dots{}" + @}
+ @end smallexample
+@@ -4660,6 +4696,7 @@ might be printed in JSON form as:
+ @}
+ @}
+ ],
++ "escape-source": false,
+ "message": "\u2018struct s\u2019 has no member named @dots{}"
+ @}
+ @end smallexample
+@@ -4717,6 +4754,10 @@ For example, the intraprocedural example + ]
+ @end smallexample
+
++Diagnostics have a boolean attribute @code{escape-source}, hinting whether
++non-ASCII bytes should be escaped when printing the pertinent lines of
++source code (@code{true} for diagnostics involving source encoding issues).
++
+ @end table
+
+ @node Warning Options
+diff --gita/gcc/input.cb/gcc/input.c
+--- a/gcc/input.c 2021-12-25 01:29:12.927317174 -0800 ++++ b/gcc/input.c 2021-12-25 01:30:50.681688823 -0800 +@@ -913,7 +913,8 @@make_location(location_tcaret,source_+ source line in order to calculate the display width. If that cannot be done
+ for any reason, then returns the byte column as a fallback. */
+ int
+-location_compute_display_column (expanded_locationexploc, int tabstop)
++location_compute_display_column (expanded_locationexploc, ++ constcpp_char_column_policy&policy)
+ {
+ if (!(exploc.file && *exploc.file && exploc.line && exploc.column))
+ return exploc.column;
+@@ -921,7 +922,7 @@location_compute_display_column(expande + /* If line is NULL, this function returns exploc.column which is the
+ desired fallback. */
+ returncpp_byte_column_to_display_column(line.get_buffer (), line.length (),
+- exploc.column, tabstop); ++ exploc.column, policy);
+ }
+
+ /* Dump statistics to stderr about the memory usage of theline_table
+@@ -3609,43 +3610,50 @@test_line_offset_overflow()
+ voidtest_cpp_utf8()
+ {
+ const intdef_tabstop= 8;
++cpp_char_column_policypolicy (def_tabstop,cpp_wcwidth); ++
+ /* Verify that wcwidth of invalid UTF-8 or control bytes is 1. */
+ {
+- intw_bad=cpp_display_width("\xf0!\x9f!\x98!\x82!", 8,def_tabstop);
++ intw_bad=cpp_display_width("\xf0!\x9f!\x98!\x82!", 8, policy);
+ASSERT_EQ(8,w_bad);
+- intw_ctrl=cpp_display_width("\r\n\v\0\1", 5,def_tabstop); ++ intw_ctrl=cpp_display_width("\r\n\v\0\1", 5, policy); +ASSERT_EQ(5,w_ctrl);
+ }
+
+ /* Verify that wcwidth of valid UTF-8 is as expected. */ + {
+- const intw_pi=cpp_display_width("\xcf\x80", 2,def_tabstop);
++ const intw_pi=cpp_display_width("\xcf\x80", 2, policy); +ASSERT_EQ(1,w_pi);
+- const intw_emoji=cpp_display_width("\xf0\x9f\x98\x82", 4,def_tabstop);
++ const intw_emoji=cpp_display_width("\xf0\x9f\x98\x82", 4, policy);
+ASSERT_EQ(2,w_emoji);
+ const intw_umlaut_precomposed=cpp_display_width("\xc3\xbf", 2,
+- def_tabstop); ++ policy); +ASSERT_EQ(1,w_umlaut_precomposed);
+ const intw_umlaut_combining=cpp_display_width("y\xcc\x88", 3,
+-def_tabstop); ++ policy); +ASSERT_EQ(1,w_umlaut_combining);
+- const intw_han=cpp_display_width("\xe4\xb8\xba", 3,def_tabstop);
++ const intw_han=cpp_display_width("\xe4\xb8\xba", 3, policy);
+ASSERT_EQ(2,w_han);
+- const intw_ascii=cpp_display_width("GCC", 3,def_tabstop); ++ const intw_ascii=cpp_display_width("GCC", 3, policy); +ASSERT_EQ(3,w_ascii);
+ const intw_mixed=cpp_display_width("\xcf\x80 = 3.14 \xf0\x9f\x98\x82"
+ "\x9f! \xe4\xb8\xba y\xcc\x88",
+- 24,def_tabstop); ++ 24, policy);
+ASSERT_EQ(18,w_mixed);
+ }
+
+ /* Verify that display width properly expands tabs. */ + {
+ const char *tstr = "\tabc\td";+- ASSERT_EQ (6, cpp_display_width (tstr, 6, 1)); +- ASSERT_EQ (10, cpp_display_width (tstr, 6, 3)); +- ASSERT_EQ (17, cpp_display_width (tstr, 6, 8)); +- ASSERT_EQ (1, cpp_display_column_to_byte_column (tstr, 6, 7,8));
++ASSERT_EQ(6,cpp_display_width(tstr, 6,
++cpp_char_column_policy(1,cpp_wcwidth)));
++ASSERT_EQ(10,cpp_display_width(tstr, 6,
++cpp_char_column_policy(3,cpp_wcwidth)));
++ASSERT_EQ(17,cpp_display_width(tstr, 6,
++cpp_char_column_policy(8,cpp_wcwidth)));
++ASSERT_EQ(1,
++cpp_display_column_to_byte_column
++ (tstr, 6, 7,cpp_char_column_policy(8,cpp_wcwidth)));
+ }
+
+ /* Verify thatcpp_byte_column_to_display_columncan go past the end,
+@@ -3658,13 +3666,13 @@ voidtest_cpp_utf8()
+ /* 111122223456
+ Byte columns. */
+
+-ASSERT_EQ(5,cpp_display_width(str, 6,def_tabstop)); ++ASSERT_EQ(5,cpp_display_width(str, 6, policy)); +ASSERT_EQ(105,
+-cpp_byte_column_to_display_column(str, 6, 106,def_tabstop));
++cpp_byte_column_to_display_column(str, 6, 106, policy));
+ASSERT_EQ(10000,
+-cpp_byte_column_to_display_column(NULL, 0, 10000,def_tabstop));
++cpp_byte_column_to_display_column(NULL, 0, 10000, policy));
+ASSERT_EQ(0,
+-cpp_byte_column_to_display_column(NULL, 10000, 0,def_tabstop));
++cpp_byte_column_to_display_column(NULL, 10000, 0, policy));
+ }
+
+ /* Verify thatcpp_display_column_to_byte_columncan go past the end,
+@@ -3678,25 +3686,25 @@ voidtest_cpp_utf8()
+ /* 000000000000000000000000000000000111111
+ 111122223333444456666777788889999012345
+ Byte columns. */
+-ASSERT_EQ(4,cpp_display_column_to_byte_column(str, 15, 2,def_tabstop));
++ASSERT_EQ(4,cpp_display_column_to_byte_column(str, 15, 2, policy));
+ASSERT_EQ(15,
+-cpp_display_column_to_byte_column(str, 15, 11,def_tabstop));
++cpp_display_column_to_byte_column(str, 15, 11, policy));
+ASSERT_EQ(115,
+-cpp_display_column_to_byte_column(str, 15, 111,def_tabstop));
++cpp_display_column_to_byte_column(str, 15, 111, policy));
+ASSERT_EQ(10000,
+-cpp_display_column_to_byte_column(NULL, 0, 10000,def_tabstop));
++cpp_display_column_to_byte_column(NULL, 0, 10000, policy));
+ASSERT_EQ(0,
+-cpp_display_column_to_byte_column(NULL, 10000, 0,def_tabstop));
++cpp_display_column_to_byte_column(NULL, 10000, 0, policy));
+
+ /* Verify that we do not interrupt a UTF-8 sequence. */ +-ASSERT_EQ(4,cpp_display_column_to_byte_column(str, 15, 1,def_tabstop));
++ASSERT_EQ(4,cpp_display_column_to_byte_column(str, 15, 1, policy));
+
+ for (intbyte_col= 1;byte_col<= 15; ++byte_col) + {
+ const intdisp_col
+- =cpp_byte_column_to_display_column(str, 15,byte_col,def_tabstop);
++ =cpp_byte_column_to_display_column(str, 15,byte_col, policy);
+ const intbyte_col2
+- =cpp_display_column_to_byte_column(str, 15,disp_col,def_tabstop);
++ =cpp_display_column_to_byte_column(str, 15,disp_col, policy);
+
+ /* If we ask for the display column in the middle of a UTF-8 + sequence, it will return the length of the partial sequence,
+diff --gita/gcc/input.hb/gcc/input.h
+--- a/gcc/input.h 2021-12-25 01:29:12.927317174 -0800 ++++ b/gcc/input.h 2021-12-25 01:30:50.681688823 -0800 +@@ -39,8 +39,11 @@STATIC_ASSERT(BUILTINS_LOCATION< RESER
+ extern boolis_location_from_builtin_token(location_t);
+ externexpanded_locationexpand_location(location_t); +
+-extern intlocation_compute_display_column(expanded_locationexploc,
+- int tabstop); ++classcpp_char_column_policy;
++
++extern int
++location_compute_display_column (expanded_locationexploc, ++ constcpp_char_column_policy&policy);
+
+ /* A class capturing the bounds of a buffer, to allow for run-time + bounds-checking in a checked build. */meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +22
-0+diff --git a/gcc/opts.c b/gcc/opts.c +--- a/gcc/opts.c 2021-12-25 01:29:12.927317174 -0800 ++++ b/gcc/opts.c 2021-12-25 01:30:50.681688823 -0800 +@@ -2447,6 +2447,10 @@ common_handle_option (struct gcc_options + dc->column_origin = value; + break; + ++ case OPT_fdiagnostics_escape_format_: ++ dc->escape_format = (enum diagnostics_escape_format)value; ++ break; ++ + case OPT_fdiagnostics_show_cwe: + dc->show_cwe = value; + break; +diff --git a/gcc/selftest.c b/gcc/selftest.c +--- a/gcc/selftest.c 2020-07-22 23:35:17.820389797 -0700 ++++ b/gcc/selftest.c 2021-12-25 01:30:50.681688823 -0800 +@@ -193,6 +193,21 @@ temp_source_file::temp_source_file (cons + fclose (out); + } + ++/* As above, but with a size, to allow for NUL bytes in CONTENT.*/
++
++temp_source_file::temp_source_file (const location &loc, ++ const char *suffix,
++ const char *content, ++size_tsz)
++:named_temp_file(suffix)
++{
++ FILE *out = fopen (get_filename(), "w");
++ if (!out)
++fail_formatted(loc, "unable to open tempfile: %s",get_filename());
++ fwrite (content, sz, 1, out);
++ fclose (out);
++}
++
+ /* Avoid introducing locale-specific differences in the results + by hardcodingopen_quoteand close_quote. */
+
+diff --gita/gcc/selftest.hb/gcc/selftest.h
+--- a/gcc/selftest.h 2020-07-22 23:35:17.820389797 -0700 ++++ b/gcc/selftest.h 2021-12-25 01:30:50.681688823 -0800 +@@ -112,6 +112,8 @@ classtemp_source_file: publicnamed_te+ public:
+temp_source_file(const location &loc, const char *suffix, + const char *content);
++temp_source_file(const location &loc, const char *suffix, ++ const char *content,size_tsz);
+ };
+
+ /* RAII-style class for avoiding introducing locale-specific differences
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-format-json-1.cb/gcc/testsuite/c-c++-common/diagnostic-format-json-1.c+--- a/gcc/testsuite/c-c++-common/diagnostic-format-json-1.c 2021- 12-25 01:29:12.927317174 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-format-json-1.c 2021- 12-25 01:30:50.681688823 -0800
+@@ -9,6 +9,7 @@
+
+ /* { dg-regexp "\"kind\": \"error\"" } */
+ /* { dg-regexp "\"column-origin\": 1" } */
++/* { dg-regexp "\"escape-source\": false" } */
+ /* { dg-regexp "\"message\": \"#error message\"" } */
+
+ /* { dg-regexp "\"caret\": \{" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-format-json-2.cb/gcc/testsuite/c-c++-common/diagnostic-format-json-2.c+--- a/gcc/testsuite/c-c++-common/diagnostic-format-json-2.c 2021- 12-25 01:29:12.927317174 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-format-json-2.c 2021- 12-25 01:30:50.681688823 -0800
+@@ -9,6 +9,7 @@
+
+ /* { dg-regexp "\"kind\": \"warning\"" } */
+ /* { dg-regexp "\"column-origin\": 1" } */
++/* { dg-regexp "\"escape-source\": false" } */
+ /* { dg-regexp "\"message\": \"#warning message\"" } */
+ /* { dg-regexp "\"option\": \"-Wcpp\"" } */
+ /* { dg-regexp "\"option_url\": \"https:\[^\n\r\"\]*#index-Wcpp\"" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-format-json-3.cb/gcc/testsuite/c-c++-common/diagnostic-format-json-3.c+--- a/gcc/testsuite/c-c++-common/diagnostic-format-json-3.c 2021- 12-25 01:29:12.927317174 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-format-json-3.c 2021- 12-25 01:30:50.681688823 -0800
+@@ -9,6 +9,7 @@
+
+ /* { dg-regexp "\"kind\": \"error\"" } */
+ /* { dg-regexp "\"column-origin\": 1" } */
++/* { dg-regexp "\"escape-source\": false" } */
+ /* { dg-regexp "\"message\": \"#warning message\"" } */
+ /* { dg-regexp "\"option\": \"-Werror=cpp\"" } */
+ /* { dg-regexp "\"option_url\": \"https:\[^\n\r\"\]*#index-Wcpp\"" } */
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-format-json-4.cb/gcc/testsuite/c-c++-common/diagnostic-format-json-4.c+--- a/gcc/testsuite/c-c++-common/diagnostic-format-json-4.c 2021- 12-25 01:29:12.927317174 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-format-json-4.c 2021- 12-25 01:30:50.681688823 -0800
+@@ -19,6 +19,7 @@ int test (void)
+
+ /* { dg-regexp "\"kind\": \"note\"" } */
+ /* { dg-regexp "\"message\": \"...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'\"" } */ ++/* { dg-regexp "\"escape-source\": false" } */
+
+ /* { dg-regexp "\"caret\": \{" } */
+ /* { dg-regexp "\"file\": \"\[^\n\r\"\]*diagnostic-format-json- 4.c\"" } */
+@@ -39,6 +40,7 @@ int test (void)
+ /* { dg-regexp "\"kind\": \"warning\"" } */
+ /* { dg-regexp "\"column-origin\": 1" } */
+ /* { dg-regexp "\"message\": \"this 'if' clause does not guard...\"" } */
++/* { dg-regexp "\"escape-source\": false" } */
+ /* { dg-regexp "\"option\": \"-Wmisleading-indentation\"" } */
+ /* { dg-regexp "\"option_url\": \"https:\[^\n\r\"\]*#index- Wmisleading-indentation\"" } */
+
+diff --gita/gcc/testsuite/c-c++-common/diagnostic-format-json-5.cb/gcc/testsuite/c-c++-common/diagnostic-format-json-5.c+--- a/gcc/testsuite/c-c++-common/diagnostic-format-json-5.c 2021- 12-25 01:29:12.927317174 -0800
++++ b/gcc/testsuite/c-c++-common/diagnostic-format-json-5.c 2021- 12-25 01:30:50.681688823 -0800
+@@ -14,6 +14,7 @@ int test (struct s *ptr)
+
+ /* { dg-regexp "\"kind\": \"error\"" } */
+ /* { dg-regexp "\"column-origin\": 1" } */
++/* { dg-regexp "\"escape-source\": false" } */
+ /* { dg-regexp "\"message\": \".*\"" } */
+
+ /* Verify fix-it hints. */
+diff --gita/gcc/testsuite/gcc.dg/cpp/warn-normalized-4-bytes.cb/gcc/testsuite/gcc.dg/cpp/warn-normalized-4-bytes.c
+--- a/gcc/testsuite/gcc.dg/cpp/warn-normalized-4-bytes.c 1969- 12-31 16:00:00.000000000 -0800
++++ b/gcc/testsuite/gcc.dg/cpp/warn-normalized-4-bytes.c 2021- 12-25 01:30:50.681688823 -0800
+@@ -0,0 +1,21 @@
++// { dg-do preprocess }
++// { dg-options "-std=gnu99 -Werror=normalized=nfc -fdiagnostics- show-caret -fdiagnostics-escape-format=bytes" }
++/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
++
++/* འ= U+0F43 TIBETAN LETTER GHA, which has decomposition "0F42 0FB7" i.e.
++ U+0F42 TIBETAN LETTER GA: à½
++ U+0FB7 TIBETAN SUBJOINED LETTER HA: ྷ
++
++ The UTF-8 encoding of U+0F43 TIBETAN LETTER GHA is: E0 BD 83. */
++
++foo before_\u0F43_after bar // { dg-error "`before_.U00000f43_after' is not in NFC .-Werror=normalized=." } ++/* { dg-begin-multiline-output "" }
++ foo before_\u0F43_after bar
++ ^~~~~~~~~~~~~~~~~~~
++ { dg-end-multiline-output "" } */
++
++foo before_à½_after bar // { dg-error "`before_.U00000f43_after' is not in NFC .-Werror=normalized=." }
++/* { dg-begin-multiline-output "" }
++ foo before_<e0><bd><83>_after bar
++ ^~~~~~~~~~~~~~~~~~~~~~~~~
++ { dg-end-multiline-output "" } */
+diff --gita/gcc/testsuite/gcc.dg/cpp/warn-normalized-4-unicode.cb/gcc/testsuite/gcc.dg/cpp/warn-normalized-4-unicode.c+--- a/gcc/testsuite/gcc.dg/cpp/warn-normalized-4-unicode.c 1969- 12-31 16:00:00.000000000 -0800
++++ b/gcc/testsuite/gcc.dg/cpp/warn-normalized-4-unicode.c 2021- 12-25 01:30:50.681688823 -0800
+@@ -0,0 +1,19 @@
++// { dg-do preprocess }
++// { dg-options "-std=gnu99 -Werror=normalized=nfc -fdiagnostics- show-caret -fdiagnostics-escape-format=unicode" }
++/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
++
++/* འ= U+0F43 TIBETAN LETTER GHA, which has decomposition "0F42 0FB7" i.e.
++ U+0F42 TIBETAN LETTER GA: à½
++ U+0FB7 TIBETAN SUBJOINED LETTER HA: ྷ */
++
++foo before_\u0F43_after bar // { dg-error "`before_.U00000f43_after' is not in NFC .-Werror=normalized=." } ++/* { dg-begin-multiline-output "" }
++ foo before_\u0F43_after bar
++ ^~~~~~~~~~~~~~~~~~~
++ { dg-end-multiline-output "" } */
++
++foo before_à½_after bar // { dg-error "`before_.U00000f43_after' is not in NFC .-Werror=normalized=." }
++/* { dg-begin-multiline-output "" }
++ foo before_<U+0F43>_after bar
++ ^~~~~~~~~~~~~~~~~~~~~
++ { dg-end-multiline-output "" } */
+diff --git a/gcc/testsuite/gfortran.dg/diagnostic-format-json-1.F90 b/gcc/testsuite/gfortran.dg/diagnostic-format-json-1.F90 +--- a/gcc/testsuite/gfortran.dg/diagnostic-format-json-1.F90 2021- 12-25 01:29:12.931317107 -0800
++++ b/gcc/testsuite/gfortran.dg/diagnostic-format-json-1.F90 2021- 12-25 01:30:50.681688823 -0800
+@@ -9,6 +9,7 @@
+
+ ! { dg-regexp "\"kind\": \"error\"" }
+ ! { dg-regexp "\"column-origin\": 1" }
++! { dg-regexp "\"escape-source\": false" }
+ ! { dg-regexp "\"message\": \"#error message\"" }
+
+ ! { dg-regexp "\"caret\": \{" }
+diff --git a/gcc/testsuite/gfortran.dg/diagnostic-format-json-2.F90 b/gcc/testsuite/gfortran.dg/diagnostic-format-json-2.F90 +--- a/gcc/testsuite/gfortran.dg/diagnostic-format-json-2.F90 2021- 12-25 01:29:12.931317107 -0800
++++ b/gcc/testsuite/gfortran.dg/diagnostic-format-json-2.F90 2021- 12-25 01:30:50.681688823 -0800
+@@ -9,6 +9,7 @@
+
+ ! { dg-regexp "\"kind\": \"warning\"" }
+ ! { dg-regexp "\"column-origin\": 1" }
++! { dg-regexp "\"escape-source\": false" }
+ ! { dg-regexp "\"message\": \"#warning message\"" }
+ ! { dg-regexp "\"option\": \"-Wcpp\"" }
+ ! { dg-regexp "\"option_url\": \"\[^\n\r\"\]*#index-Wcpp\"" } +diff --git a/gcc/testsuite/gfortran.dg/diagnostic-format-json-3.F90 b/gcc/testsuite/gfortran.dg/diagnostic-format-json-3.F90 +--- a/gcc/testsuite/gfortran.dg/diagnostic-format-json-3.F90 2021- 12-25 01:29:12.931317107 -0800
++++ b/gcc/testsuite/gfortran.dg/diagnostic-format-json-3.F90 2021- 12-25 01:30:50.681688823 -0800
+@@ -9,6 +9,7 @@
+
+ ! { dg-regexp "\"kind\": \"error\"" }
+ ! { dg-regexp "\"column-origin\": 1" }
++! { dg-regexp "\"escape-source\": false" }
+ ! { dg-regexp "\"message\": \"#warning message\"" }
+ ! { dg-regexp "\"option\": \"-Werror=cpp\"" }
+ ! { dg-regexp "\"option_url\": \"\[^\n\r\"\]*#index-Wcpp\"" } +diff --gita/libcpp/charset.cb/libcpp/charset.c
+--- a/libcpp/charset.c 2021-12-25 01:29:12.931317107 -0800 ++++ b/libcpp/charset.c 2021-12-25 01:30:50.681688823 -0800 +@@ -1549,12 +1549,14 @@convert_escape(cpp_reader*pfile, const + "unknown escape sequence: '\\%c'", (int) c); + else
+ {
++encoding_rich_locationrich_loc(pfile);
++
+ /*diagnostic.cdoes not support "%03o". When it does, this
+ code can use %03o directly in the diagnostic again. */ + char buf[32];
+sprintf(buf, "%03o", (int) c);+- cpp_error (pfile, CPP_DL_PEDWARN, +- "unknown escape sequence: '\\%s'", buf);++
cpp_error_at(pfile,CPP_DL_PEDWARN,&rich_loc, ++ "unknown escape sequence: '\\%s'", buf); + }
+ }
+
+@@ -2277,14 +2279,16 @@cpp_string_location_reader::get_next()
+ }
+
+cpp_display_width_computation::
+-cpp_display_width_computation (const char *data, intdata_length, int tabstop) :
++cpp_display_width_computation (const char *data, intdata_length, ++ constcpp_char_column_policy&policy) :
+m_begin(data),
+m_next(m_begin),
+m_bytes_left(data_length),
+-m_tabstop(tabstop),
++m_policy(policy),
+m_display_cols(0)
+ {
+-gcc_assert(m_tabstop> 0);
++gcc_assert(policy.m_tabstop > 0);
++gcc_assert(policy.m_width_cb);
+ }
+
+
+@@ -2296,19 +2300,28 @@cpp_display_width_computation(const cha + point to a valid UTF-8-encoded sequence, then it will be treated as a single
+ byte with display width 1.m_cur_display_colis the current display column,
+ relative to which tab stops should be expanded. Returns the display width of
+- the codepoint just processed. */
++ the codepoint just processed.
++ If OUT is non-NULL, it is populated. */
+
+ int +-cpp_display_width_computation::process_next_codepoint () ++cpp_display_width_computation::process_next_codepoint (cpp_decoded_char*out)
+ {
+cppchar_tc;
+ intnext_width;
+
++ if (out)
++out->m_start_byte=m_next;
++
+ if (*m_next== '\t')
+ {
+ ++m_next;
+ --m_bytes_left;
+-next_width=m_tabstop- (m_display_cols%m_tabstop); ++next_width= m_policy.m_tabstop - (m_display_cols% m_policy.m_tabstop);
++ if (out)
++ {
++out->m_ch= '\t';
++out->m_valid_ch= true;
++ }
+ }
+ else if (one_utf8_to_cppchar((const uchar **)&m_next,&m_bytes_left, &c)
+ != 0)
+@@ -2318,14 +2331,24 @@cpp_display_width_computation::process_n+ of one. */
+ ++m_next;
+ --m_bytes_left;
+-next_width= 1;
++next_width= m_policy.m_undecoded_byte_width;
++ if (out)
++ out->m_valid_ch = false;
+ }
+ else
+ {
+ /*one_utf8_to_cppchar()has updatedm_nextandm_bytes_leftfor us. */
+-next_width=cpp_wcwidth(c);
++next_width= m_policy.m_width_cb (c);
++ if (out)
++ {
++out->m_ch= c;
++out->m_valid_ch= true;
++ }
+ }
+
++ if (out)
++out->m_next_byte=m_next;
++
+m_display_cols+=next_width;
+ returnnext_width;
+ }
+@@ -2341,7 +2364,7 @@cpp_display_width_computation::advance_d+ const int start =m_display_cols;
+ const int target = start + n;
+ while (m_display_cols< target && !done ())
+-process_next_codepoint();
++process_next_codepoint(NULL);
+ returnm_display_cols- start;
+ }
+
+@@ -2349,29 +2372,33 @@cpp_display_width_computation::advance_d+ how many display columns are occupied by the first COLUMN bytes. COLUMN
+ may exceedDATA_LENGTH, in which case the phantom bytes at the end are
+ treated as if they have display width 1. Tabs are expanded to the next tab
+- stop, relative to the start of DATA. */
++ stop, relative to the start of DATA, and non-printable-ASCII characters
++ will be escaped as per POLICY. */
+
+ int
+cpp_byte_column_to_display_column(const char *data, intdata_length,
+- int column, int tabstop) ++ int column,
++ constcpp_char_column_policy&policy)
+ {
+ const int offset = MAX (0, column -data_length);
+-cpp_display_width_computationdw (data, column - offset, tabstop);
++cpp_display_width_computationdw (data, column - offset, policy); + while (!dw.done ())
+- dw.process_next_codepoint ();
++ dw.process_next_codepoint (NULL);
+ return dw.display_cols_processed () + offset;
+ }
+
+ /* For the string of lengthDATA_LENGTHbytes that begins at DATA, compute
+ the least number of bytes that will result in at leastDISPLAY_COLdisplay
+ columns. The return value may exceedDATA_LENGTHif the entire string does
+- not occupy enough display columns. */
++ not occupy enough display columns. Non-printable-ASCII characters
++ will be escaped as per POLICY. */
+
+ int
+cpp_display_column_to_byte_column(const char *data, intdata_length,
+- intdisplay_col, int tabstop) ++ intdisplay_col,
++ constcpp_char_column_policy&policy)
+ {
+-cpp_display_width_computationdw (data,data_length, tabstop); ++cpp_display_width_computationdw (data,data_length, policy); + const intavail_display= dw.advance_display_cols (display_col); + return dw.bytes_processed () + MAX (0,display_col-avail_display);
+ }
+diff --gita/libcpp/errors.cb/libcpp/errors.c
+--- a/libcpp/errors.c 2020-07-22 23:35:18.712399623 -0700 ++++ b/libcpp/errors.c 2021-12-25 01:30:50.681688823 -0800 +@@ -27,6 +27,31 @@ along with this program; see the file CO
+ #include "cpplib.h"
+ #include "internal.h"
+
++/* Get alocation_tfor the current location in PFILE, ++ generally that of the previously lexed token. */
++
++location_t
++cpp_diagnostic_get_current_location (cpp_reader*pfile) ++{
++ if (CPP_OPTION(pfile, traditional))
++ {
++ if (pfile->state.in_directive)
++ returnpfile->directive_line;
++ else
++ returnpfile->line_table->highest_line;
++ }
++ /* We don't want to refer to a token before the beginning of the ++ current run -- that is invalid. */
++ else if (pfile->cur_token==pfile->cur_run->base)
++ {
++ return 0;
++ }
++ else
++ {
++ return pfile->cur_token[-1].src_loc;
++ }
++}
++
+ /* Print a diagnostic at the given location. */
+
+ATTRIBUTE_FPTR_PRINTF(5,0)
+@@ -52,25 +77,7 @@cpp_diagnostic(cpp_reader* pfile, enum + enumcpp_warning_reasonreason,
+ const char *msgid,va_list*ap)
+ {+- location_t src_loc; +- +- if (CPP_OPTION (pfile, traditional)) +- { +- if (pfile->state.in_directive) +- src_loc = pfile->directive_line; +- else +- src_loc = pfile->line_table->highest_line; +- } +- /* We don't want to refer to a token before the beginning of the +- current run -- that is invalid. */ +- else if (pfile->cur_token == pfile->cur_run->base) +- { +- src_loc = 0; +- } +- else +- { +- src_loc = pfile->cur_token[-1].src_loc; +- }++
location_tsrc_loc=cpp_diagnostic_get_current_location(pfile); +rich_locationrichloc (pfile->line_table,src_loc);
+ returncpp_diagnostic_at(pfile, level, reason, &richloc, msgid, ap);
+ }
+@@ -142,6 +149,43 @@cpp_warning_syshdr(cpp_reader* pfile, +
+va_end(ap);
+ return ret;
++}
++
++/* Ascpp_warningabove, but use RICHLOC as the location of the diagnostic. */
++
++boolcpp_warning_at(cpp_reader*pfile, enumcpp_warning_reasonreason,
++rich_location*richloc, const char *msgid, ...) ++{
++va_listap;
++ bool ret;
++
++va_start(ap, msgid);
++
++ ret =cpp_diagnostic_at(pfile,CPP_DL_WARNING, reason, richloc, ++ msgid, &ap);
++
++va_end(ap);
++ return ret;
++
++}
++
++/* Ascpp_pedwarningabove, but use RICHLOC as the location of the ++ diagnostic. */
++
++bool
++cpp_pedwarning_at (cpp_reader* pfile, enumcpp_warning_reasonreason,
++rich_location*richloc, const char *msgid, ...) ++{
++va_listap;
++ bool ret;
++
++va_start(ap, msgid);
++
++ ret =cpp_diagnostic_at(pfile,CPP_DL_PEDWARN, reason, richloc, ++ msgid, &ap);
++
++va_end(ap);
++ return ret;
+ }
+
+ /* Print a diagnostic at a specific location. */
+diff --gita/libcpp/include/cpplib.hb/libcpp/include/cpplib.h+--- a/libcpp/include/cpplib.h 2021-12-25 01:29:12.931317107 -0800 ++++ b/libcpp/include/cpplib.h 2021-12-25 01:30:50.685688757 -0800 +@@ -1176,6 +1176,14 @@ extern boolcpp_warning_syshdr(cpp_read+ const char *msgid, ...)
+ATTRIBUTE_PRINTF_3;
+
++/* As their counterparts above, but use RICHLOC. */ ++extern boolcpp_warning_at(cpp_reader*, enumcpp_warning_reason, ++rich_location*richloc, const char *msgid, ...)
++ATTRIBUTE_PRINTF_4;
++extern boolcpp_pedwarning_at(cpp_reader*, enumcpp_warning_reason,
++rich_location*richloc, const char *msgid, ...)
++ATTRIBUTE_PRINTF_4;
++
+ /* Output a diagnostic with "MSGID: " preceding the
+ error string of errno. No location is printed. */
+ extern boolcpp_errno(cpp_reader*, enumcpp_diagnostic_level, +@@ -1320,42 +1328,95 @@ extern const char *cpp_get_userdef_suff+
+ /* Incharset.c*/
+
++/* The result of attempting to decode a run of UTF-8 bytes. */ ++
++structcpp_decoded_char
++{
++ const char*m_start_byte;
++ const char*m_next_byte;
++
++ boolm_valid_ch;
++cppchar_tm_ch;
++};
++
++/* Information for mapping between code points and display columns. ++
++ This is a tabstop value, along with a callback for getting the ++ widths of characters. Normally this callback iscpp_wcwidth, but we
++ support other schemes for escaping non-ASCII unicode as a series of
++ ASCII chars when printing the user's source code in diagnostic-show-locus.c
++
++ For example, consider:
++ - the Unicode character U+03C0 "GREEK SMALL LETTER PI" (UTF-8:0xCF0x80)
++ - the Unicode character U+1F642 "SLIGHTLY SMILING FACE" ++ (UTF-8:0xF00x9F0x990x82)
++ - the byte0xBF(a stray trailing byte of a UTF-8 character) ++ Normally U+03C0 would occupy one display column, U+1F642 ++ would occupy two display columns, and the stray byte would be ++ printed verbatim as one display column.
++
++ However when escaping them as unicode code points as "<U+03C0>" ++ and "<U+1F642>" they occupy 8 and 9 display columns respectively,
++ and when escaping them as bytes as "<CF><80>" and "<F0><9F><99><82>"
++ they occupy 8 and 16 display columns respectively. In both cases
++ the stray byte is escaped to <BF> as 4 display columns. */ ++
++structcpp_char_column_policy
++{
++cpp_char_column_policy(int tabstop,
++ int (*width_cb) (cppchar_tc)) ++ :m_tabstop(tabstop),
++m_undecoded_byte_width(1),
++m_width_cb(width_cb)
++ {}
++
++ intm_tabstop;
++ /* Width in display columns of a stray byte that isn't decodable ++ as UTF-8. */
++ intm_undecoded_byte_width;
++ int (*m_width_cb) (cppchar_tc);
++};
++
+ /* A class to manage the state while converting a UTF-8 sequence tocppchar_t
+ and computing the display width one character at a time. */
+ classcpp_display_width_computation{
+ public:
+cpp_display_width_computation(const char *data, intdata_length, +- int tabstop);
++ constcpp_char_column_policy&policy);
+ const char*next_byte() const { returnm_next; }
+ intbytes_processed() const { returnm_next-m_begin; } + intbytes_left() const { returnm_bytes_left; }
+ bool done () const { return !bytes_left (); }
+ intdisplay_cols_processed() const { returnm_display_cols; } +
+- intprocess_next_codepoint();
++ intprocess_next_codepoint(cpp_decoded_char*out);
+ intadvance_display_cols(int n);
+
+ private:
+ const char *constm_begin;
+ const char*m_next;
+size_tm_bytes_left;
+- const intm_tabstop;
++ constcpp_char_column_policy&m_policy;
+ intm_display_cols;
+ };
+
+ /* Convenience functions that are simple use cases for class + cpp_display_width_computation. Tab characters will be expanded to spaces
+- as determined by TABSTOP. */
++ as determined by POLICY.m_tabstop, and non-printable-ASCII characters
++ will be escaped as per POLICY. */
++
+ intcpp_byte_column_to_display_column(const char *data, intdata_length,
+- int column, int tabstop); ++ int column,
++ constcpp_char_column_policy&policy);
+ inline intcpp_display_width(const char *data, intdata_length, +- int tabstop)
++ constcpp_char_column_policy&policy)
+ {
+ returncpp_byte_column_to_display_column(data,data_length,data_length,
+- tabstop);
++ policy);
+ }
+ intcpp_display_column_to_byte_column(const char *data, intdata_length,
+- intdisplay_col, int tabstop); ++ intdisplay_col,
++ constcpp_char_column_policy&policy);
+ intcpp_wcwidth(cppchar_tc);
+
+ #endif /* !LIBCPP_CPPLIB_H*/
+diff --gita/libcpp/include/line-map.hb/libcpp/include/line-map.h+--- a/libcpp/include/line-map.h 2020-07-22 23:35:18.712399623 -0700
++++ b/libcpp/include/line-map.h 2021-12-25 01:30:50.685688757 -0800
+@@ -1732,6 +1732,18 @@ classrich_location
+ constdiagnostic_path*get_path() const { returnm_path; } + voidset_path(constdiagnostic_path*path) {m_path= path; } +
++ /* A flag for hinting that the diagnostic involves character encoding
++ issues, and thus that it will be helpful to the user if we show some
++ representation of how the characters in the pertinent source lines
++ are encoded.
++ The default is false (i.e. do not escape).
++ When set to true, non-ASCII bytes in the pertinent source lines will
++ be escaped in a manner controlled by the user-supplied option ++ -fdiagnostics-escape-format=, so that the user can better understand
++ what's going on with the encoding in their source file. */ ++ boolescape_on_output_p() const { returnm_escape_on_output; } ++ voidset_escape_on_output(bool flag) {m_escape_on_output= flag; }
++
+ private:
+ boolreject_impossible_fixit(location_twhere);
+ voidstop_supporting_fixits();
+@@ -1758,6 +1770,7 @@ protected:
+ boolm_fixits_cannot_be_auto_applied;
+
+ constdiagnostic_path*m_path;
++ boolm_escape_on_output;
+ };
+
+ /* A struct for the result ofrange_label::get_text: a NUL- terminated buffer
+diff --gita/libcpp/internal.hb/libcpp/internal.h
+--- a/libcpp/internal.h 2020-07-22 23:35:18.712399623 -0700 ++++ b/libcpp/internal.h 2021-12-25 01:30:50.685688757 -0800 +@@ -758,6 +758,9 @@ struct_cpp_dir_only_callbacks
+ extern void_cpp_preprocess_dir_only(cpp_reader*,
+ const struct_cpp_dir_only_callbacks*);
+
++/* In errors.c */
++externlocation_tcpp_diagnostic_get_current_location(cpp_reader*);
++
+ /* In traditional.c. */
+ extern bool_cpp_scan_out_logical_line(cpp_reader*,cpp_macro*, bool);
+ extern bool_cpp_read_logical_line_trad(cpp_reader*); +@@ -946,6 +949,26 @@ intlinemap_get_expansion_line(class li
+ const char*linemap_get_expansion_filename(classline_maps*, +location_t);
+
++/* A subclass ofrich_locationfor emitting a diagnostic ++ at the current location of the reader, but flagging ++ it withset_escape_on_output(true). */
++classencoding_rich_location: publicrich_location
++{
++ public:
++encoding_rich_location(cpp_reader*pfile)
++ :rich_location(pfile->line_table,
++cpp_diagnostic_get_current_location(pfile)) ++ {
++set_escape_on_output(true);
++ }
++
++encoding_rich_location(cpp_reader*pfile,location_tloc) ++ :rich_location(pfile->line_table, loc)
++ {
++set_escape_on_output(true);
++ }
++};
++
+ #ifdef__cplusplus
+ }
+ #endif
+diff --gita/libcpp/lex.cb/libcpp/lex.c
+--- a/libcpp/lex.c 2021-12-24 20:23:45.568762024 -0800 ++++ b/libcpp/lex.c 2021-12-25 01:30:50.685688757 -0800 +@@ -1268,7 +1268,11 @@skip_whitespace(cpp_reader*pfile, cppc + while (is_nvspace(c));
+
+ if (saw_NUL)
+-cpp_error(pfile,CPP_DL_WARNING, "null character(s) ignored"); ++ {
++encoding_rich_locationrich_loc(pfile);
++cpp_error_at(pfile,CPP_DL_WARNING,&rich_loc,
++ "null character(s) ignored");
++ }
+
+ buffer->cur--;
+ }
+@@ -1297,6 +1301,28 @@warn_about_normalization(cpp_reader*pf + if (CPP_OPTION(pfile,warn_normalize) <NORMALIZE_STATE_RESULT
(s)
+ && !pfile->state.skipping)
+ {
++location_tloc =token->src_loc;
++
++ /* If possible, create a location range for the token. */ ++ if (loc >=RESERVED_LOCATION_COUNT
++ &&token->type!=CPP_EOF
++ /* There must be no line notes to process. */ ++ && (!(pfile->buffer->cur
++ >= pfile->buffer->notes[pfile->buffer->cur_note].pos ++ && !pfile->overlaid_buffer)))
++ {
++source_rangetok_range;
++ tok_range.m_start = loc;
++ tok_range.m_finish
++ =linemap_position_for_column(pfile->line_table, ++CPP_BUF_COLUMN(pfile-Quoted 1 line
buffer,
++ pfile-
Quoted 1 line
buffer->cur));++ loc =
COMBINE_LOCATION_DATA(pfile->line_table, ++ loc,tok_range, NULL); ++ }
++
++encoding_rich_locationrich_loc(pfile, loc); ++
+ /* Make sure that the token is printed using UCNs, even + if we'd otherwise happily print UTF-8. */
+ unsigned char *buf = XNEWVEC (unsigned char,cpp_token_len(token));
+@@ -1304,11 +1330,11 @@warn_about_normalization(cpp_reader*pf +
+ sz =cpp_spell_token(pfile, token, buf, false) - buf; + if (NORMALIZE_STATE_RESULT(s) ==normalized_C) +- cpp_warning_with_line (pfile,CPP_W_NORMALIZE, token-Quoted 1 line
src_loc, 0,+- "`%.*s' is not in NFKC", (int) sz, buf);
++ cpp_warning_at (pfile,CPP_W_NORMALIZE,&rich_loc, ++ "`%.*s' is not in NFKC", (int) sz, buf); + else
+- cpp_warning_with_line (pfile,CPP_W_NORMALIZE, token-Quoted 1 line
src_loc, 0,+- "`%.*s' is not in NFC", (int) sz, buf);
++ cpp_warning_at (pfile,CPP_W_NORMALIZE,&rich_loc, ++ "`%.*s' is not in NFC", (int) sz, buf); + free (buf);
+ }
+ }meta/recipes-devtools/gcc/gcc/0002-CVE-2021-42574.patch new file +13
-0+diff --git a/libcpp/line-map.c b/libcpp/line-map.c +--- a/libcpp/line-map.c 2020-07-22 23:35:18.712399623 -0700 ++++ b/libcpp/line-map.c 2021-12-25 01:30:50.685688757 -0800 +@@ -2007,7 +2007,8 @@ rich_location::rich_location (line_maps + m_fixit_hints (), + m_seen_impossible_fixit (false), + m_fixits_cannot_be_auto_applied (false), +- m_path (NULL) ++ m_path (NULL), ++ m_escape_on_output (false) + { + add_range (loc, SHOW_RANGE_WITH_CARET, label); + }meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +1
-0@@ -0,0 +1,1724 @@ +From 51c500269bf53749b107807d84271385fad35628 Mon Sep 17 00:00:002001
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +3
-0+From: Marek Polacek <[email protected]> +Date: Wed, 6 Oct 2021 14:33:59 -0400 +Subject: [PATCH] libcpp: Implement -Wbidi-chars for CVE-2021-42574[PR103026]
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +3
-0+ +From a link below: +"An issue was discovered in the Bidirectional Algorithm in theUnicode
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +2
-0+Specification through 14.0. It permits the visual reordering of +characters via control sequences, which can be used to craft sourcecode
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +2
-0+that renders different logic than the logical ordering of tokens +ingested by compilers and interpreters. Adversaries can leveragethis to
+encode source code for compilers accepting Unicode such that targetedmeta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +7
-0+vulnerabilities are introduced invisibly to human reviewers." + +More info: +https://nvd.nist.gov/vuln/detail/CVE-2021-42574 +https://trojansource.codes/ + +This is not a compiler bug. However, to mitigate the problem, thispatch
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +2
-0+implements -Wbidi-chars=[none|unpaired|any] to warn about possibly +misleading Unicode bidirectional control characters the preprocessormay
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +4
-0+encounter. + +The default is =unpaired, which warns about improperly terminated +bidirectional control characters; e.g. a LRE without itscorresponding PDF.
+The level =any warns about any use of bidirectional control characters.meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +3
-0+ +This patch handles both UCNs and UTF-8 characters. UCNs designating +bidi characters in identifiers are accepted since r204886. Then7 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +3
-0+good reason to allow mixing them. + +We warn in different contexts: comments (both C and C++-style),5 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +3
-0+can nest so this patch handles that as well. + +I have not included nor tested this at all with Fortran (which also1 line not shown · raw message
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +3
-0+string literals and line comments). + +Dave M. posted patches improving diagnostic involving Unicode1 line not shown · raw message
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +26
-0+This patch does not make use of this new infrastructure yet. + + PR preprocessor/103026 + +gcc/c-family/ChangeLog: + + * c.opt (Wbidi-chars, Wbidi-chars=): New option. + +gcc/ChangeLog: + + * doc/invoke.texi: Document -Wbidi-chars. + +libcpp/ChangeLog: + + * include/cpplib.h (enum cpp_bidirectional_level): New. + (struct cpp_options): Add cpp_warn_bidirectional. + (enum cpp_warning_reason): Add CPP_W_BIDIRECTIONAL. + * internal.h (struct cpp_reader): Add warn_bidi_p member + function. + * init.c (cpp_create_reader): Set cpp_warn_bidirectional. + * lex.c (bidi): New namespace. + (get_bidi_utf8): New function. + (get_bidi_ucn): Likewise. + (maybe_warn_bidi_on_close): Likewise. + (maybe_warn_bidi_on_char): Likewise. + (_cpp_skip_block_comment): Implement warning about7 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +23
-0+ +gcc/testsuite/ChangeLog: + + * c-c++-common/Wbidi-chars-1.c: New test. + * c-c++-common/Wbidi-chars-2.c: New test. + * c-c++-common/Wbidi-chars-3.c: New test. + * c-c++-common/Wbidi-chars-4.c: New test. + * c-c++-common/Wbidi-chars-5.c: New test. + * c-c++-common/Wbidi-chars-6.c: New test. + * c-c++-common/Wbidi-chars-7.c: New test. + * c-c++-common/Wbidi-chars-8.c: New test. + * c-c++-common/Wbidi-chars-9.c: New test. + * c-c++-common/Wbidi-chars-10.c: New test. + * c-c++-common/Wbidi-chars-11.c: New test. + * c-c++-common/Wbidi-chars-12.c: New test. + * c-c++-common/Wbidi-chars-13.c: New test. + * c-c++-common/Wbidi-chars-14.c: New test. + * c-c++-common/Wbidi-chars-15.c: New test. + * c-c++-common/Wbidi-chars-16.c: New test. + * c-c++-common/Wbidi-chars-17.c: New test. + +CVE: CVE-2021-42574 +Upstream-Status: Backport2 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0003-CVE-2021-42574.patch new file +59
-0+Signed-off-by: Pgowda <[email protected]> + +--- + gcc/c-family/c.opt | 24 ++ + gcc/doc/invoke.texi | 21 +- + gcc/testsuite/c-c++-common/Wbidi-chars-1.c | 12 + + gcc/testsuite/c-c++-common/Wbidi-chars-10.c | 27 ++ + gcc/testsuite/c-c++-common/Wbidi-chars-11.c | 13 + + gcc/testsuite/c-c++-common/Wbidi-chars-12.c | 19 + + gcc/testsuite/c-c++-common/Wbidi-chars-13.c | 17 + + gcc/testsuite/c-c++-common/Wbidi-chars-14.c | 38 ++ + gcc/testsuite/c-c++-common/Wbidi-chars-15.c | 59 +++ + gcc/testsuite/c-c++-common/Wbidi-chars-16.c | 26 ++ + gcc/testsuite/c-c++-common/Wbidi-chars-17.c | 30 ++ + gcc/testsuite/c-c++-common/Wbidi-chars-2.c | 9 + + gcc/testsuite/c-c++-common/Wbidi-chars-3.c | 11 + + gcc/testsuite/c-c++-common/Wbidi-chars-4.c | 188 +++++++++ + gcc/testsuite/c-c++-common/Wbidi-chars-5.c | 188 +++++++++ + gcc/testsuite/c-c++-common/Wbidi-chars-6.c | 155 ++++++++ + gcc/testsuite/c-c++-common/Wbidi-chars-7.c | 9 + + gcc/testsuite/c-c++-common/Wbidi-chars-8.c | 13 + + gcc/testsuite/c-c++-common/Wbidi-chars-9.c | 29 ++ + libcpp/include/cpplib.h | 18 +- + libcpp/init.c | 1 + + libcpp/internal.h | 7 + + libcpp/lex.c | 408 +++++++++++++++++++- + 23 files changed, 1315 insertions(+), 7 deletions(-) + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-1.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-10.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-11.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-12.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-13.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-14.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-15.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-16.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-17.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-2.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-3.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-4.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-5.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-6.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-7.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-8.c + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-9.c + +diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt +--- a/gcc/c-family/c.opt 2021-12-25 01:29:12.915317374 -0800 ++++ b/gcc/c-family/c.opt 2021-12-25 01:36:22.040018701 -0800 +@@ -350,6 +350,30 @@ Wbad-function-cast + C ObjC Var(warn_bad_function_cast) Warning + Warn about casting functions to incompatible types. + ++Wbidi-chars ++C ObjC C++ ObjC++ Warning Alias(Wbidi-chars=,any,none) ++; ++ ++Wbidi-chars= ++C ObjC C++ ObjC++ RejectNegative Joined Warning1,721 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0004-CVE-2021-42574.patch new file +1
-0@@ -0,0 +1,138 @@ +From 1a7f2c0774129750fdf73e9f1b78f0ce983c9ab3 Mon Sep 17 00:00:001 line not shown · raw message
meta/recipes-devtools/gcc/gcc/0004-CVE-2021-42574.patch new file +3
-0+From: David Malcolm <[email protected]> +Date: Tue, 2 Nov 2021 09:54:32 -0400 +Subject: [PATCH] libcpp: escape non-ASCII source bytes in -Wbidi-2 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0004-CVE-2021-42574.patch new file +17
-0+MIME-Version: 1.0 +Content-Type: text/plain; charset=utf8 +Content-Transfer-Encoding: 8bit + +This flags rich_locations associated with -Wbidi-chars= so that +non-ASCII bytes will be escaped when printing the source lines +(using the diagnostics support I added in +r12-4825-gbd5e882cf6e0def3dd1bc106075d59a303fe0d1e). + +In particular, this ensures that the printed source lines will +be pure ASCII, and thus the visual ordering of the characters +will be the same as the logical ordering. + +Before: + + Wbidi-chars-1.c: In function âmainâ: + Wbidi-chars-1.c:6:43: warning: unpaired UTF-8 bidirectional26 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0004-CVE-2021-42574.patch new file +5
-0+ +After: + + Wbidi-chars-1.c: In function âmainâ: + Wbidi-chars-1.c:6:43: warning: unpaired UTF-8 bidirectional29 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0004-CVE-2021-42574.patch new file +11
-0+ +libcpp/ChangeLog: + PR preprocessor/103026 + * lex.c (maybe_warn_bidi_on_close): Use a rich_location + and call set_escape_on_output (true) on it. + (maybe_warn_bidi_on_char): Likewise. + +Signed-off-by: David Malcolm <[email protected]> + +CVE: CVE-2021-42574 +Upstream-Status: Backport2 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0004-CVE-2021-42574.patch new file +13
-0+Signed-off-by: Pgowda <[email protected]> + +--- + libcpp/lex.c | 29 +++++++++++++++++------------ + 1 file changed, 17 insertions(+), 12 deletions(-) + +diff --git a/libcpp/lex.c b/libcpp/lex.c +--- a/libcpp/lex.c 2021-12-14 20:44:11.647815287 -0800 ++++ b/libcpp/lex.c 2021-12-14 20:43:38.008383220 -0800 +@@ -1427,9 +1427,11 @@ maybe_warn_bidi_on_close (cpp_reader *pf + const location_t loc + = linemap_position_for_column (pfile->line_table, + CPP_BUF_COLUMN (pfile->buffer,64 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0005-CVE-2021-42574.patch new file +1
-0@@ -0,0 +1,575 @@ +From bef32d4a28595e933f24fef378cf052a30b674a7 Mon Sep 17 00:00:001 line not shown · raw message
meta/recipes-devtools/gcc/gcc/0005-CVE-2021-42574.patch new file +3
-0+From: David Malcolm <[email protected]> +Date: Tue, 2 Nov 2021 15:45:22 -0400 +Subject: [PATCH] libcpp: capture and underline ranges in -Wbidi-2 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0005-CVE-2021-42574.patch new file +11
-0+MIME-Version: 1.0 +Content-Type: text/plain; charset=utf8 +Content-Transfer-Encoding: 8bit + +This patch converts the bidi::vec to use a struct so that we can +capture location_t values for the bidirectional control characters. + +Before: + + Wbidi-chars-1.c: In function âmainâ: + Wbidi-chars-1.c:6:43: warning: unpaired UTF-8 bidirectional10 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0005-CVE-2021-42574.patch new file +5
-0+ +After: + + Wbidi-chars-1.c: In function âmainâ: + Wbidi-chars-1.c:6:43: warning: unpaired UTF-8 bidirectional21 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0005-CVE-2021-42574.patch new file +14
-0+ +Signed-off-by: David Malcolm <[email protected]> + +gcc/testsuite/ChangeLog: + PR preprocessor/103026 + * c-c++-common/Wbidi-chars-ranges.c: New test. + +libcpp/ChangeLog: + PR preprocessor/103026 + * lex.c (struct bidi::context): New. + (bidi::vec): Convert to a vec of context rather than unsigned + char. + (bidi::ctx_at): Rename to... + (bidi::pop_kind_at): ...this and reimplement for above35 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0005-CVE-2021-42574.patch new file +5
-0+ +Signed-off-by: David Malcolm <[email protected]> + +CVE: CVE-2021-42574 +Upstream-Status: Backport2 lines not shown · raw message
meta/recipes-devtools/gcc/gcc/0005-CVE-2021-42574.patch new file +9
-1+Signed-off-by: Pgowda <[email protected]> + +--- + .../c-c++-common/Wbidi-chars-ranges.c | 54 ++++ + libcpp/lex.c | 251 ++++++++++++++- --- + 2 files changed, 257 insertions(+), 48 deletions(-) + create mode 100644 gcc/testsuite/c-c++-common/Wbidi-chars-ranges.c + +diff --git a/gcc/testsuite/c-c++-common/Wbidi-chars-ranges.c555 lines not shown · raw message
Part of this message is not shown here. View the raw message.
Quoted 7 lines · Anuj Mittal
I can't apply this.
git am says:
error: cannot convert from Y to UTF-8
fatal: could not parse patch
Key is When git send-email asks for UTF-8 encoding for the patch then do not enter “y” but just press
Enter
Quoted 2,071 lines
Thanks,
Anuj
Quoted 1,954 lines · pgowda
Upstream-Status: Backport
[https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=004bb936d6d5f177af26ad4905595e843d5665a5]
Upstream-Status: Backport
[https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=bd5e882cf6e0def3dd1bc106075d59a303fe0d1e]
Upstream-Status: Backport
[https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=51c500269bf53749b107807d84271385fad35628]
Upstream-Status: Backport
[https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=1a7f2c0774129750fdf73e9f1b78f0ce983c9ab3]
Upstream-Status: Backport
[https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=bef32d4a28595e933f24fef378cf052a30b674a7]Signed-off-by pgowda <[email protected]>--- meta/recipes-devtools/gcc/gcc-10.2.inc | 5 + .../gcc/gcc/0001-CVE-2021-42574.patch | 2906 +++++++++++++++++ .../gcc/gcc/0002-CVE-2021-42574.patch | 2270 +++++++++++++ .../gcc/gcc/0003-CVE-2021-42574.patch | 1724 ++++++++++ .../gcc/gcc/0004-CVE-2021-42574.patch | 138 + .../gcc/gcc/0005-CVE-2021-42574.patch | 575 ++++ 6 files changed, 7618 insertions(+) create mode 100644 meta/recipes-devtools/gcc/gcc/0001-CVE-2021- 42574.patch create mode 100644 meta/recipes-devtools/gcc/gcc/0002-CVE-2021- 42574.patch create mode 100644 meta/recipes-devtools/gcc/gcc/0003-CVE-2021- 42574.patch create mode 100644 meta/recipes-devtools/gcc/gcc/0004-CVE-2021- 42574.patch create mode 100644 meta/recipes-devtools/gcc/gcc/0005-CVE-2021-42574.patch
meta/recipes- renamed from meta/recipes-devtools/gcc/gcc-10.2.inc +0
-0devtools/gcc/gcc-10.2.inc
index5626bf20f0..fd7f16d7bf100644meta/recipes-devtools/gcc/gcc-10.2.inc +5
-0@@ -74,6 +74,11 @@ SRC_URI = "\ file://0002-CVE-2021-35465.patch \ file://0003-CVE-2021-35465.patch \ file://0004-CVE-2021-35465.patch \ + file://0001-CVE-2021-42574.patch \ + file://0002-CVE-2021-42574.patch \ + file://0003-CVE-2021-42574.patch \ + file://0004-CVE-2021-42574.patch \ + file://0005-CVE-2021-42574.patch \ " SRC_URI[sha256sum] ="
b8dd4368bb9c7f0b98188317ee0254dd8cc99d1e3a18d0ff146c855fe16c1d8c"meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +1
-0@@ -0,0 +1,2906 @@ +From 004bb936d6d5f177af26ad4905595e843d5665a5 Mon Sep 17 00:00:002001
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+From: Lewis Hyatt <[email protected]> +Date: Tue, 14 Jul 2020 12:05:56 -0400 +Subject: [PATCH] diagnostics: Support conversion of tabs to spaces[PR49973]
+ [PR86904]meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2
-0+ +Supports conversion of tabs to spaces when outputting diagnostics.Also
+adds -fdiagnostics-column-unit and -fdiagnostics-column-origin options to
+control how the column number is output, thereby resolving the two PRs.meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +5
-0+ +gcc/c-family/ChangeLog: + + PR other/86904 + * c-indentation.c (should_warn_for_misleading_indentation):Get
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2
-0+ global tabstop from the new source. + * c-opts.c (c_common_handle_option): Remove handling of -ftabstop, which
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +12
-0+ is now a common option. + * c.opt: Likewise. + +gcc/ChangeLog: + + PR preprocessor/49973 + PR other/86904 + * common.opt: Handle -ftabstop here instead of in c-family + options. Add -fdiagnostics-column-unit= and + -fdiagnostics-column-origin= options. + * opts.c (common_handle_option): Handle the new options. + * diagnostic-format-json.cc (json_from_expanded_location):Add
+diagnostic_contextargument. Use it to convert column
numbers as permeta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +4
-0+ the new options. + (json_from_location_range): Likewise. + (json_from_fixit_hint): Likewise. + (json_end_diagnostic): Pass the new context argument tohelper
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2
-0+ functions above. Add "column-origin" field to the output. + (test_unknown_location): Add the new context argument tocalls to
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +10
-0+ helper functions. + (test_bad_endpoints): Likewise. + * diagnostic-show-locus.c + (exploc_with_display_col::exploc_with_display_col): Support + tabstop parameter. + (layout_point::layout_point): Make use of class + exploc_with_display_col. + (layout_range::layout_range): Likewise. + (struct line_bounds): Clarify that the units are now always + display columns. Rename members accordingly. Addconstructor.
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +4
-0+ (layout::print_source_line): Add support for tab expansion. + (make_range): Adapt to class layout_range changes. + (layout::maybe_add_location_range): Likewise. + (layout::layout): Adapt to class exploc_with_display_colchanges.
+ (layout::calculate_x_offset_display): Support tabstop
parameter.
+ (layout::print_annotation_line): Adapt to structline_bounds
changes.meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +5
-0+ (layout::print_line): Likewise. + (line_label::line_label): Add diagnostic_context argument. + (get_affected_range): Likewise. + (get_printed_columns): Likewise. + (layout::print_any_labels): Adapt to struct line_labelchanges.
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +5
-0+ (class correction): Add m_tabstop member. + (correction::correction): Add tabstop argument. + (correction::compute_display_cols): Use m_tabstop. + (class line_corrections): Add m_context member. + (line_corrections::line_corrections): Add diagnostic_contextargument.
+ (line_corrections::add_hint): Usem_contextto handle
tabstops.
+ (layout::print_trailing_fixits): Adapt to classline_correctionsmeta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2
-0+ changes. + (test_layout_x_offset_display_utf8): Support tabstopparameter.
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +4
-0+ (test_layout_x_offset_display_tab): New selftest. + (test_one_liner_colorized_utf8): Likewise. + (test_tab_expansion): Likewise. + (test_diagnostic_show_locus_one_liner_utf8): Call the newtests.
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +10
-0+ (diagnostic_show_locus_c_tests): Likewise. + (test_overlapped_fixit_printing): Adapt to helper class and + function changes. + (test_overlapped_fixit_printing_utf8): Likewise. + (test_overlapped_fixit_printing_2): Likewise. + * diagnostic.h (enum diagnostics_column_unit): New enum. + (struct diagnostic_context): Add members for the new options. + (diagnostic_converted_column): Declare. + (json_from_expanded_location): Add new context argument. + * diagnostic.c (diagnostic_initialize): Initialize newmembers.
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+ (diagnostic_converted_column): New function. + (maybe_line_and_column): Be willing to output a column of 0. + (diagnostic_get_location_text): Convert column number as perthe new
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+ options. + (diagnostic_report_current_module): Likewise. + (assert_location_text): Add origin and column_unit argumentsfor
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2
-0+ testing the new functionality. + (test_diagnostic_get_location_text): Test the newfunctionality.
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2
-0+ * doc/invoke.texi: Document the new options and behavior. + * input.h (location_compute_display_column): Add tabstopargument.
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+ * input.c (location_compute_display_column): Likewise. + (test_cpp_utf8): Add selftests for tab expansion. + * tree-diagnostic-path.cc (default_tree_make_json_for_path):Pass the
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +10
-1+ new context argument to json_from_expanded_location(). + +libcpp/ChangeLog: + + PR preprocessor/49973 + PR other/86904 + * include/cpplib.h (struct cpp_options): Removed support for -ftabstop, + which is now handled by diagnostic_context. + (class cpp_display_width_computation): New class. + (cpp_byte_column_to_display_column): Add optional tabstopargument.
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +4
-0+ (cpp_display_width): Likewise. + (cpp_display_column_to_byte_column): Likewise. + * charset.c + (cpp_display_width_computation::cpp_display_width_computation): New
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2
-0+ function. + (cpp_display_width_computation::advance_display_cols):Likewise.
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+ (compute_next_display_width): Removed and implemented this + functionality in a new function... + (cpp_display_width_computation::process_next_codepoint):...here.
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2
-0+ (cpp_byte_column_to_display_column): Added tabstop argument. + Reimplemented in terms of class
cpp_display_width_computation.meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2
-0+ (cpp_display_column_to_byte_column): Likewise. + * init.c (cpp_create_reader): Remove handling of -ftabstop,which is now
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +7
-0+ handled by diagnostic_context. + +gcc/testsuite/ChangeLog: + + PR preprocessor/49973 + PR other/86904 + * c-c++-common/Wmisleading-indentation-3.c: Adjust expectedoutput
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +19
-0+ for new defaults. + * c-c++-common/Wmisleading-indentation.c: Likewise. + * c-c++-common/diagnostic-format-json-1.c: Likewise. + * c-c++-common/diagnostic-format-json-2.c: Likewise. + * c-c++-common/diagnostic-format-json-3.c: Likewise. + * c-c++-common/diagnostic-format-json-4.c: Likewise. + * c-c++-common/diagnostic-format-json-5.c: Likewise. + * c-c++-common/missing-close-symbol.c: Likewise. + * g++.dg/diagnostic/bad-binary-ops.C: Likewise. + * g++.dg/parse/error4.C: Likewise. + * g++.old-deja/g++.brendan/crash11.C: Likewise. + * g++.old-deja/g++.pt/overload2.C: Likewise. + * g++.old-deja/g++.robertl/eb109.C: Likewise. + * gcc.dg/analyzer/malloc-paths-9.c: Likewise. + * gcc.dg/bad-binary-ops.c: Likewise. + * gcc.dg/format/branch-1.c: Likewise. + * gcc.dg/format/pr79210.c: Likewise. + * gcc.dg/plugin/diagnostic-test-expressions-1.c: Likewise. + * gcc.dg/plugin/diagnostic-test-string-literals-1.c:Likewise.
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +17
-0+ * gcc.dg/redecl-4.c: Likewise. + * gfortran.dg/diagnostic-format-json-1.F90: Likewise. + * gfortran.dg/diagnostic-format-json-2.F90: Likewise. + * gfortran.dg/diagnostic-format-json-3.F90: Likewise. + * go.dg/arrayclear.go: Add a comment explaining why adding a + comment was necessary to work around a dejagnu bug. + * c-c++-common/diagnostic-units-1.c: New test. + * c-c++-common/diagnostic-units-2.c: New test. + * c-c++-common/diagnostic-units-3.c: New test. + * c-c++-common/diagnostic-units-4.c: New test. + * c-c++-common/diagnostic-units-5.c: New test. + * c-c++-common/diagnostic-units-6.c: New test. + * c-c++-common/diagnostic-units-7.c: New test. + * c-c++-common/diagnostic-units-8.c: New test. + +CVE: CVE-2021-42574 +Upstream-Status: Backport[https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=004bb936d6d5f177af26ad
4905595e843d5665a5]meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +61
-1+Signed-off-by: Pgowda <[email protected]> +--- + gcc/c-family/c-indentation.c | 5 +- + gcc/c-family/c-opts.c | 6 - + gcc/c-family/c.opt | 4 - + gcc/common.opt | 21 + + gcc/diagnostic-format-json.cc | 55 +- + gcc/diagnostic-show-locus.c | 504 +++++++++++++-- --- + gcc/diagnostic.c | 113 +++- + gcc/diagnostic.h | 28 +- + gcc/doc/invoke.texi | 68 ++- + gcc/input.c | 72 ++- + gcc/input.h | 4 +- + gcc/opts.c | 14 + + .../c-c++-common/Wmisleading-indentation-3.c | 12 +- + .../c-c++-common/Wmisleading-indentation.c | 6 +- + .../c-c++-common/diagnostic-format-json-1.c | 5 + + .../c-c++-common/diagnostic-format-json-2.c | 5 + + .../c-c++-common/diagnostic-format-json-3.c | 5 + + .../c-c++-common/diagnostic-format-json-4.c | 9 + + .../c-c++-common/diagnostic-format-json-5.c | 9 + + .../c-c++-common/diagnostic-units-1.c | 28 + + .../c-c++-common/diagnostic-units-2.c | 28 + + .../c-c++-common/diagnostic-units-3.c | 28 + + .../c-c++-common/diagnostic-units-4.c | 28 + + .../c-c++-common/diagnostic-units-5.c | 28 + + .../c-c++-common/diagnostic-units-6.c | 28 + + .../c-c++-common/diagnostic-units-7.c | 28 + + .../c-c++-common/diagnostic-units-8.c | 28 + + .../c-c++-common/missing-close-symbol.c | 6 +- + .../g++.dg/diagnostic/bad-binary-ops.C | 8 +- + gcc/testsuite/g++.dg/parse/error4.C | 2 +- + .../g++.old-deja/g++.brendan/crash11.C | 4 +- + gcc/testsuite/g++.old-deja/g++.pt/overload2.C | 2 +- + .../g++.old-deja/g++.robertl/eb109.C | 4 +- + .../gcc.dg/analyzer/malloc-paths-9.c | 2 +- + gcc/testsuite/gcc.dg/bad-binary-ops.c | 8 +- + gcc/testsuite/gcc.dg/format/branch-1.c | 2 +- + gcc/testsuite/gcc.dg/format/pr79210.c | 2 +- + .../plugin/diagnostic-test-expressions-1.c | 16 +- + .../diagnostic-test-string-literals-1.c | 4 +- + gcc/testsuite/gcc.dg/redecl-4.c | 2 +- + .../gfortran.dg/diagnostic-format-json-1.F90 | 5 + + .../gfortran.dg/diagnostic-format-json-2.F90 | 5 + + .../gfortran.dg/diagnostic-format-json-3.F90 | 5 + + gcc/testsuite/go.dg/arrayclear.go | 3 + + gcc/tree-diagnostic-path.cc | 5 +- + libcpp/charset.c | 98 ++-- + libcpp/include/cpplib.h | 40 +- + libcpp/init.c | 1 - + 48 files changed, 1106 insertions(+), 287 deletions(-) + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-1.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-2.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-3.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-4.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-5.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-6.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-7.c + create mode 100644 gcc/testsuite/c-c++-common/diagnostic-units-8.c + +diff --git a/gcc/c-family/c-indentation.c b/gcc/c-family/c-
indentation.c
+---a/gcc/c-family/c-indentation.c2020-07-22 23:35:17.296384022
-0700
++++b/gcc/c-family/c-indentation.c2021-12-25 01:20:53.475636694
-0800
+@@ -24,8 +24,7 @@ along with GCC; see the file COPYING3.
+ #include "c-common.h"
+ #include "c-indentation.h"
+ #include "selftest.h"+- +-extern cpp_options *cpp_opts;++#include "
diagnostic.h"meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +5
-0+ + /* Round up VIS_COLUMN to nearest tab stop. */ + +@@ -294,7 +293,7 @@ should_warn_for_misleading_indentation ( + expanded_location next_stmt_exploc = expand_location(
next_stmt_loc);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +17
-0+ expanded_location guard_exploc = expand_location (guard_loc); + +- const unsigned int tab_width = cpp_opts->tabstop; ++ const unsigned int tab_width = global_dc->tabstop; + + /* They must be in the same file. */ + if (next_stmt_exploc.file != body_exploc.file) +diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt +--- a/gcc/c-family/c.opt 2021-12-24 20:23:42.816809230 -0800 ++++ b/gcc/c-family/c.opt 2021-12-25 01:20:53.475636694 -0800 +@@ -1876,10 +1876,6 @@ Enum(strong_eval_order) String(some) Val + EnumValue + Enum(strong_eval_order) String(all) Value(2) + +-ftabstop= +-C ObjC C++ ObjC++ Joined RejectNegative UInteger +--ftabstop=<number> Distance between tab stops for columnreporting.
+-
+ ftemplate-backtrace-limit=
+ C++ ObjC++ Joined RejectNegative UIntegerVar(template_backtrace_limit)Init(10)
+ Set the maximum number of template instantiation notes for a single warning or error.meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +26
-0+diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c +--- a/gcc/c-family/c-opts.c 2021-12-24 20:23:44.824774786 -0800 ++++ b/gcc/c-family/c-opts.c 2021-12-25 01:20:53.475636694 -0800 +@@ -504,12 +504,6 @@ c_common_handle_option (size_t scode, co + cpp_opts->track_macro_expansion = 2; + break; + +- case OPT_ftabstop_: +- /* It is documented that we silently ignore silly values. */ +- if (value >= 1 && value <= 100) +- cpp_opts->tabstop = value; +- break; +- + case OPT_fexec_charset_: + cpp_opts->narrow_charset = arg; + break; +diff --git a/gcc/common.opt b/gcc/common.opt +--- a/gcc/common.opt 2021-12-24 20:23:42.480814993 -0800 ++++ b/gcc/common.opt 2021-12-25 01:20:53.475636694 -0800 +@@ -1325,6 +1325,14 @@ Enum(diagnostic_url_rule) String(always) + EnumValue + Enum(diagnostic_url_rule) String(auto) Value(DIAGNOSTICS_URL_AUTO) + ++fdiagnostics-column-unit= ++Common Joined RejectNegative Enum(diagnostics_column_unit) ++-fdiagnostics-column-unit=[display|byte] Select whether columnnumbers are output as display columns (default) or raw bytes. ++
++fdiagnostics-column-origin=
++Common Joined RejectNegative UInteger ++-fdiagnostics-column-origin=<number> Set the number of the first column. The default is 1-based as per GNU style, but some utilities may expect 0-based, for example.
++
+ fdiagnostics-format=
+ Common Joined RejectNegativeEnum(diagnostics_output_format)
+ -fdiagnostics-format=[text|json] Select output format.
+@@ -1334,6 +1342,15 @@ SourceInclude
+diagnostic.h
+
+ Enum
++Name(diagnostics_column_unit) Type(int)
++
++EnumValue
++Enum(diagnostics_column_unit) String(display)Value(DIAGNOSTICS_COLUMN_UNIT_DISPLAY)
++
++EnumValue
++Enum(diagnostics_column_unit) String(byte)Value(DIAGNOSTICS_COLUMN_UNIT_BYTE)
++
++Enum
+Name(diagnostics_output_format)Type(int)
+
+ EnumValue
+@@ -1362,6 +1379,10 @@ fdiagnostics-path-format=
+ Common Joined RejectNegativeVar(flag_diagnostics_path_format)Enum(diagnostic_path_format)Init(DPF_INLINE_EVENTS)
+ Specify how to print any control-flow path associated with a diagnostic.
+
++ftabstop=
++Common Joined RejectNegative UInteger
++-ftabstop=<number> Distance between tab stops for column
reporting.
++
+ Enum
+Name(diagnostic_path_format)Type(int)meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +27
-0+ +diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c +--- a/gcc/diagnostic.c 2020-07-22 23:35:17.556386887 -0700 ++++ b/gcc/diagnostic.c 2021-12-25 01:23:41.300841207 -0800 +@@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. + #include "selftest.h" + #include "selftest-diagnostic.h" + #include "opts.h" ++#include "cpplib.h" + + #ifdef HAVE_TERMIOS_H + # include <termios.h> +@@ -219,6 +220,9 @@ diagnostic_initialize (diagnostic_contex + context->min_margin_width = 0; + context->show_ruler_p = false; + context->parseable_fixits_p = false; ++ context->column_unit = DIAGNOSTICS_COLUMN_UNIT_DISPLAY; ++ context->column_origin = 1; ++ context->tabstop = 8; + context->edit_context_ptr = NULL; + context->diagnostic_group_nesting_depth = 0; + context->diagnostic_group_emission_count = 0; +@@ -353,8 +357,51 @@ diagnostic_get_color_for_kind (diagnosti + return diagnostic_kind_color[kind]; + } + ++/* Given an expanded_location, convert the column (which is in 1-based bytes)
++ to the requested units, without converting the origin.
++ Return -1 if the column is invalid (<= 0). */
++
++static int
++convert_column_unit (enumdiagnostics_column_unitcolumn_unit,
++ int tabstop,
++expanded_locations)
++{
++ if (s.column <= 0)
++ return -1;
++
++ switch (column_unit)
++ {
++ default:
++gcc_unreachable();
++
++ caseDIAGNOSTICS_COLUMN_UNIT_DISPLAY:++ { ++ cpp_char_column_policy policy (tabstop, cpp_wcwidth); ++ return location_compute_display_column (s, policy); ++ }++
++ caseDIAGNOSTICS_COLUMN_UNIT_BYTE:
++ return s.column;
++ }
++}
++
++/* Given anexpanded_location, convert the column (which is in 1- based bytes)
++ to the requested units and origin. Return -1 if the column is
++ invalid (<= 0). */
++int
++diagnostic_converted_column (diagnostic_context*context,expanded_locations)
++{
++ intone_based_col
++ =convert_column_unit(context->column_unit,context->tabstop,
s);
++ if (one_based_col<= 0)
++ return -1;
++ returnone_based_col+ (context->column_origin- 1); ++}
++
+ /* Return a formatted line and column ':%line:%column'. Elided if+- zero. The result is a statically allocated buffer. */ ++ line == 0 or col < 0. (A column of 0 may be valid due to the ++ -fdiagnostics-column-origin option.) ++ The result is a statically allocated buffer. */meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +17
-0+ + static const char * + maybe_line_and_column (int line, int col) +@@ -363,8 +410,9 @@ maybe_line_and_column (int line, int col + + if (line) + { +- size_t l = snprintf (result, sizeof (result), +- col ? ":%d:%d" : ":%d", line, col); ++ size_t l ++ = snprintf (result, sizeof (result), ++ col >= 0 ? ":%d:%d" : ":%d", line, col); + gcc_checking_assert (l < sizeof (result)); + } + else +@@ -383,8 +431,14 @@ diagnostic_get_location_text (diagnostic + const char *locus_cs = colorize_start (pp_show_color (pp),"locus");
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +27
-0+ const char *locus_ce = colorize_stop (pp_show_color (pp)); + const char *file = s.file ? s.file : progname; +- int line = strcmp (file, N_("<built-in>")) ? s.line : 0; +- int col = context->show_column ? s.column : 0; ++ int line = 0; ++ int col = -1; ++ if (strcmp (file, N_("<built-in>"))) ++ { ++ line = s.line; ++ if (context->show_column) ++ col = diagnostic_converted_column (context, s); ++ } + + const char *line_col = maybe_line_and_column (line, col); + return build_message_string ("%s%s%s:%s", locus_cs, file, +@@ -650,14 +704,20 @@ diagnostic_report_current_module (diagno + if (! MAIN_FILE_P (map)) + { + bool first = true; ++ expanded_location s = {}; + do + { + where = linemap_included_from (map); + map = linemap_included_from_linemap (line_table, map); +- const char *line_col +- = maybe_line_and_column (SOURCE_LINE (map, where), +- first && context-Quoted 1 line
show_column+- ?
SOURCE_COLUMN(map, where)
: 0);++ s.file = LINEMAP_FILE (map); ++ s.line = SOURCE_LINE (map, where); ++ int col = -1; ++ if (first && context->show_column)++ {
++ s.column =SOURCE_COLUMN(map, where);
++ col =diagnostic_converted_column(context, s);
++ }
++ const char*line_col=maybe_line_and_column(s.line,
col);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +36
-0+ static const char *const msgs[] = + { + N_("In file included from"), +@@ -666,7 +726,7 @@ diagnostic_report_current_module (diagno + unsigned index = !first; + pp_verbatim (context->printer, "%s%s %r%s%s%R", + first ? "" : ",\n", _(msgs[index]), +- "locus", LINEMAP_FILE (map), line_col); ++ "locus", s.file, line_col); + first = false; + } + while (! MAIN_FILE_P (map)); +@@ -2042,10 +2102,15 @@ test_print_parseable_fixits_replace () + static void + assert_location_text (const char *expected_loc_text, + const char *filename, int line, int column, +- bool show_column) ++ bool show_column, ++ int origin = 1, ++ enum diagnostics_column_unit column_unit ++ = DIAGNOSTICS_COLUMN_UNIT_BYTE) + { + test_diagnostic_context dc; + dc.show_column = show_column; ++ dc.column_unit = column_unit; ++ dc.column_origin = origin; + + expanded_location xloc; + xloc.file = filename; +@@ -2069,7 +2134,10 @@ test_diagnostic_get_location_text () + assert_location_text ("PROGNAME:", NULL, 0, 0, true); + assert_location_text ("<built-in>:", "<built-in>", 42, 10, true); + assert_location_text ("foo.c:42:10:", "foo.c", 42, 10, true); +- assert_location_text ("foo.c:42:", "foo.c", 42, 0, true); ++ assert_location_text ("foo.c:42:9:", "foo.c", 42, 10, true, 0); ++ assert_location_text ("foo.c:42:1010:", "foo.c", 42, 10, true,1001);
++ for (int origin = 0; origin != 2; ++origin)
++assert_location_text("foo.c:42:", "foo.c", 42, 0, true,
origin);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +9
-0+ assert_location_text ("foo.c:", "foo.c", 0, 10, true); + assert_location_text ("foo.c:42:", "foo.c", 42, 10, false); + assert_location_text ("foo.c:", "foo.c", 0, 10, false); +@@ -2077,6 +2145,41 @@ test_diagnostic_get_location_text () + maybe_line_and_column (INT_MAX, INT_MAX); + maybe_line_and_column (INT_MIN, INT_MIN); + ++ { ++ /* In order to test display columns vs byte columns, we need tocreate a
++ file forlocation_get_source_line()to read. */
++++ const char *const content = "smile \xf0\x9f\x98\x82\n"; ++ const int line_bytes = strlen (content) - 1; ++ const int def_tabstop = 8; ++ const int display_width = cpp_display_width (content, line_bytes, ++ def_tabstop); ++ ASSERT_EQ (line_bytes - 2, display_width); ++ temp_source_file tmp (SELFTEST_LOCATION, ".c", content); ++ const char *const fname = tmp.get_filename (); ++ const int buf_len = strlen (fname) + 16; ++ char *const expected = XNEWVEC (char, buf_len);++
++ snprintf (expected,buf_len, "%s:1:%d:", fname,line_bytes);
++assert_location_text(expected, fname, 1,line_bytes, true,
++ 1,DIAGNOSTICS_COLUMN_UNIT_BYTE);
++
++ snprintf (expected,buf_len, "%s:1:%d:", fname,line_bytes-
1);
++assert_location_text(expected, fname, 1,line_bytes, true,
++ 0,DIAGNOSTICS_COLUMN_UNIT_BYTE);
++
++ snprintf (expected,buf_len, "%s:1:%d:", fname,display_width);
++assert_location_text(expected, fname, 1,line_bytes, true,
++ 1,DIAGNOSTICS_COLUMN_UNIT_DISPLAY);
++
++ snprintf (expected,buf_len, "%s:1:%d:", fname,display_width-
1);
++assert_location_text(expected, fname, 1,line_bytes, true,
++ 0,DIAGNOSTICS_COLUMN_UNIT_DISPLAY);
++
++ XDELETEVEC (expected);
++ }
++
++meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +4
-0+ progname = old_progname; + } + +diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
+--- a/gcc/diagnostic-format-json.cc 2020-07-22 23:35:17.556386887
-0700
++++ b/gcc/diagnostic-format-json.cc 2021-12-25 01:20:53.475636694
-0800
+@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.
+ #include "system.h"
+ #include "coretypes.h"
+ #include "diagnostic.h"
++#include "selftest-diagnostic.h"
+ #include "diagnostic-metadata.h"
+ #include "json.h"
+ #include "selftest.h"
+@@ -43,21 +44,43 @@ staticjson::array*cur_children_array;
+ /* Generate a JSON object for LOC. */
+
+json::value*
+-json_from_expanded_location (location_tloc) ++json_from_expanded_location (diagnostic_context*context,location_tloc)
+ {meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +8
-0+ expanded_location exploc = expand_location (loc); + json::object *result = new json::object (); + if (exploc.file) + result->set ("file", new json::string (exploc.file)); + result->set ("line", new json::integer_number (exploc.line)); +- result->set ("column", new json::integer_number (exploc.column)); ++ ++ const enum diagnostics_column_unit orig_unit = context-Quoted 1 line
column_unit;++ struct
++ {
++ const char *name;
++ enumdiagnostics_column_unitunit;
++ } column_fields[] = {
++ {"display-column",DIAGNOSTICS_COLUMN_UNIT_DISPLAY},
++ {"byte-column",DIAGNOSTICS_COLUMN_UNIT_BYTE}++ }; ++ int the_column = INT_MIN; ++ for (int i = 0; i != sizeof column_fields / sizeof(
*column_fields); ++i)
++ {
++context->column_unit= column_fields[i].unit;
++ const int col =diagnostic_converted_column(context,
exploc);
++result->set(column_fields[i].name, newjson::integer_number
(col));
++ if (column_fields[i].unit ==orig_unit)
++the_column= col;
++ }++ gcc_assert (the_column != INT_MIN); ++ result->set ("column", new json::integer_number (the_column)); ++ context->column_unit = orig_unit;meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +7
-0+ return result; + } + + /* Generate a JSON object for LOC_RANGE. */ + + static json::object * +-json_from_location_range (const location_range *loc_range, unsigned
range_idx)
++json_from_location_range (diagnostic_context*context,
++ constlocation_range*loc_range, unsignedrange_idx)
+ {meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +8
-0+ location_t caret_loc = get_pure_location (loc_range->m_loc); + +@@ -68,13 +91,13 @@ json_from_location_range (const location + location_t finish_loc = get_finish (loc_range->m_loc); + + json::object *result = new json::object (); +- result->set ("caret", json_from_expanded_location (caret_loc)); ++ result->set ("caret", json_from_expanded_location (context,
caret_loc));meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +4
-0+ if (start_loc != caret_loc + && start_loc != UNKNOWN_LOCATION) +- result->set ("start", json_from_expanded_location (start_loc)); ++ result->set ("start", json_from_expanded_location (context,
start_loc));meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+ if (finish_loc != caret_loc + && finish_loc != UNKNOWN_LOCATION) +- result->set ("finish", json_from_expanded_location(
finish_loc));
++result->set("finish",json_from_expanded_location(context,finish_loc));meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +9
-0+ + if (loc_range->m_label) + { +@@ -91,14 +114,14 @@ json_from_location_range (const location + /* Generate a JSON object for HINT. */ + + static json::object * +-json_from_fixit_hint (const fixit_hint *hint) ++json_from_fixit_hint (diagnostic_context *context, const fixit_hint*hint)
+ {meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +4
-0+ json::object *fixit_obj = new json::object (); + + location_t start_loc = hint->get_start_loc (); +- fixit_obj->set ("start", json_from_expanded_location(
start_loc));
++fixit_obj->set("start",json_from_expanded_location(context,start_loc));+ location_t next_loc = hint->get_next_loc (); +- fixit_obj->set ("next", json_from_expanded_location (next_loc)); ++ fixit_obj->set ("next", json_from_expanded_location (context,
next_loc));
+fixit_obj->set("string", newjson::string(hint->get_string
()));meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +6
-0+ + return fixit_obj; +@@ -190,11 +213,13 @@ json_end_diagnostic (diagnostic_context + else + { + /* Otherwise, make diag_obj be the top-level object withinthe group;
+- add a "children" array. */ ++ add a "children" array and record the column origin. */meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +6
-0+ toplevel_array->append (diag_obj); + cur_group = diag_obj; + cur_children_array = new json::array (); + diag_obj->set ("children", cur_children_array); ++ diag_obj->set ("column-origin", ++ new json::integer_number (context-Quoted 1 line
column_origin));meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +8
-0+ } + + const rich_location *richloc = diagnostic->richloc; +@@ -205,7 +230,7 @@ json_end_diagnostic (diagnostic_context + for (unsigned int i = 0; i < richloc->get_num_locations (); i++) + { + const location_range *loc_range = richloc->get_range (i); +- json::object *loc_obj = json_from_location_range (loc_range,i);
++json::object*loc_obj=json_from_location_range(context,loc_range, i);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +5
-0+ if (loc_obj) + loc_array->append (loc_obj); + } +@@ -217,7 +242,7 @@ json_end_diagnostic (diagnostic_context + for (unsigned int i = 0; i < richloc->get_num_fixit_hints ();i++)
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +4
-0+ { + const fixit_hint *hint = richloc->get_fixit_hint (i); +- json::object *fixit_obj = json_from_fixit_hint (hint); ++ json::object *fixit_obj = json_from_fixit_hint (context,hint);
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +20
-0+ fixit_array->append (fixit_obj); + } + } +@@ -320,7 +345,8 @@ namespace selftest { + static void + test_unknown_location () + { +- delete json_from_expanded_location (UNKNOWN_LOCATION); ++ test_diagnostic_context dc; ++ delete json_from_expanded_location (&dc, UNKNOWN_LOCATION); + } + + /* Verify that we gracefully handle attempts to serialize bad +@@ -338,7 +364,8 @@ test_bad_endpoints () + loc_range.m_range_display_kind = SHOW_RANGE_WITH_CARET; + loc_range.m_label = NULL; + +- json::object *obj = json_from_location_range (&loc_range, 0); ++ test_diagnostic_context dc; ++ json::object *obj = json_from_location_range (&dc, &loc_range,0);
+ /* We should have a "caret" value, but no "start" or "finish"
values. */meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +11
-0+ ASSERT_TRUE (obj != NULL); + ASSERT_TRUE (obj->get ("caret") != NULL); +diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h +--- a/gcc/diagnostic.h 2020-07-22 23:35:17.556386887 -0700 ++++ b/gcc/diagnostic.h 2021-12-25 01:20:53.479636627 -0800 +@@ -24,6 +24,20 @@ along with GCC; see the file COPYING3. + #include "pretty-print.h" + #include "diagnostic-core.h" + ++/* An enum for controlling what units to use for the column number ++ when diagnostics are output, used by the -fdiagnostics-column-unit option.
++ Tabs will be expanded or not according to the value of -
ftabstop. The origin
++ (default 1) is controlled by -fdiagnostics-column-origin. */
++
++enumdiagnostics_column_unit
++{
++ /* The default from GCC 11 onwards: display columns. */ ++DIAGNOSTICS_COLUMN_UNIT_DISPLAY,
++
++ /* The behavior in GCC 10 and earlier: simple bytes. */ ++DIAGNOSTICS_COLUMN_UNIT_BYTE
++};
++
+ /* Enum for overriding the standard output format. */meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +10
-0+ + enum diagnostics_output_format +@@ -280,6 +294,15 @@ struct diagnostic_context + rest of the diagnostic. */ + bool parseable_fixits_p; + ++ /* What units to use when outputting the column number. */ ++ enum diagnostics_column_unit column_unit; ++ ++ /* The origin for the column number (1-based or 0-basedtypically). */
++ intcolumn_origin;
++
++ /* The size of the tabstop for tab expansion. */ ++ int tabstop;
++meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +7
-0+ /* If non-NULL, an edit_context to which fix-it hints should be + applied, for generating patches. */ + edit_context *edit_context_ptr; +@@ -458,6 +481,8 @@ diagnostic_same_line (const diagnostic_c + } + + extern const char *diagnostic_get_color_for_kind (diagnostic_tkind);
++extern intdiagnostic_converted_column(diagnostic_context*context,
++expanded_locations);
+
+ /* Pure text formatting support functions. */
+ extern char*file_name_as_prefix(diagnostic_context*, const char *);
+@@ -470,6 +495,7 @@ extern voiddiagnostic_output_format_ini
+ /* Compute the number of digits in the decimal representation of an integer. */
+ extern intnum_digits(int);
+
+-externjson::value*json_from_expanded_location(location_tloc); ++externjson::value*json_from_expanded_location(diagnostic_context*context,
++location_tloc);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+ + #endif /* ! GCC_DIAGNOSTIC_H */ +diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-
locus.c
+---a/gcc/diagnostic-show-locus.c2020-07-22 23:35:17.556386887
-0700
++++b/gcc/diagnostic-show-locus.c2021-12-25 01:20:53.479636627
-0800
+@@ -175,9 +175,10 @@ enumcolumn_unit{
+ classexploc_with_display_col: publicexpanded_location
+ {
+ public:+- exploc_with_display_col (const expanded_location &exploc) ++ exploc_with_display_col (const expanded_location &exploc, int tabstop) + : expanded_location (exploc), +- m_display_col (location_compute_display_column (exploc)) {} ++ m_display_col (location_compute_display_column (exploc,tabstop))
++ {}meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +13
-0+ + int m_display_col; + }; +@@ -189,11 +190,11 @@ class exploc_with_display_col : public e + class layout_point + { + public: +- layout_point (const expanded_location &exploc) ++ layout_point (const exploc_with_display_col &exploc) + : m_line (exploc.line) + { + m_columns[CU_BYTES] = exploc.column; +- m_columns[CU_DISPLAY_COLS] = location_compute_display_column(exploc);
++ m_columns[CU_DISPLAY_COLS] = exploc.m_display_col;meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +21
-0+ } + + linenum_type m_line; +@@ -205,10 +206,10 @@ class layout_point + class layout_range + { + public: +- layout_range (const expanded_location *start_exploc, +- const expanded_location *finish_exploc, ++ layout_range (const exploc_with_display_col &start_exploc, ++ const exploc_with_display_col &finish_exploc, + enum range_display_kind range_display_kind, +- const expanded_location *caret_exploc, ++ const exploc_with_display_col &caret_exploc, + unsigned original_idx, + const range_label *label); + +@@ -226,22 +227,18 @@ class layout_range + + /* A struct for use by layout::print_source_line for telling + layout::print_annotation_line the extents of the source linethat
+- it printed, so that underlines can be clipped appropriately. */ ++ it printed, so that underlines can be clipped appropriately.Units
++ are 1-based display columns. */meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +12
-0+ + struct line_bounds + { +- int m_first_non_ws; +- int m_last_non_ws; ++ int m_first_non_ws_disp_col; ++ int m_last_non_ws_disp_col; + +- void convert_to_display_cols (char_span line) ++ line_bounds () + { +- m_first_non_ws = cpp_byte_column_to_display_column(line.get_buffer (),
+- line.length
(),
+-m_first_non_ws) ; +- +- m_last_non_ws = cpp_byte_column_to_display_column(line.get_buffer (),
+- line.length
(),
+-m_last_non_ws);
++m_first_non_ws_disp_col=INT_MAX;
++m_last_non_ws_disp_col= 0;meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +8
-0+ } + }; + +@@ -351,8 +348,8 @@ class layout + private: + bool will_show_line_p (linenum_type row) const; + void print_leading_fixits (linenum_type row); +- void print_source_line (linenum_type row, const char *line, int
line_bytes,+- line_bounds *lbounds_out); ++ line_bounds print_source_line (linenum_type row, const char*line,
++ intline_bytes);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+ bool should_print_annotation_line_p (linenum_type row) const; + void start_annotation_line (char margin_char = ' ') const; + void print_annotation_line (linenum_type row, const line_boundslbounds);
+@@ -513,16 +510,16 @@colorizer::get_color_by_name(const charmeta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +6
-0+ Initialize various layout_point fields from expanded_location + equivalents; we've already filtered on file. */ + +-layout_range::layout_range (const expanded_location *start_exploc, +- const expanded_location *finish_exploc, ++layout_range::layout_range (const exploc_with_display_col
&start_exploc,
++ constexploc_with_display_col&finish_exploc,
+ enumrange_display_kindrange_display_kind,+- const expanded_location *caret_exploc, ++ const exploc_with_display_col
&caret_exploc,meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +17
-0+ unsigned original_idx, + const range_label *label) +-: m_start (*start_exploc), +- m_finish (*finish_exploc), ++: m_start (start_exploc), ++ m_finish (finish_exploc), + m_range_display_kind (range_display_kind), +- m_caret (*caret_exploc), ++ m_caret (caret_exploc), + m_original_idx (original_idx), + m_label (label) + { +@@ -646,6 +643,9 @@ layout_range::intersects_line_p (linenum + + #if CHECKING_P + ++/* Default for when we don't care what the tab expansion is setto. */
++static const intdef_tabstop= 8;
++
+ /* Create some expanded locations for testinglayout_range. The filename
+ member of the explocs is set to the empty string. This member
will only be
+ inspected by the calls tolocation_compute_display_column()made
from the
+@@ -662,8 +662,11 @@make_range(intstart_line, intstart_cometa/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +4
-0+ = {"", start_line, start_col, NULL, false}; + const expanded_location finish_exploc + = {"", end_line, end_col, NULL, false}; +- return layout_range (&start_exploc, &finish_exploc,
SHOW_RANGE_WITHOUT_CARET,+- &start_exploc, 0, NULL); ++ return layout_range (exploc_with_display_col (start_exploc,
def_tabstop),
++exploc_with_display_col(finish_exploc,def_tabstop),
++SHOW_RANGE_WITHOUT_CARET,
++exploc_with_display_col(start_exploc,def_tabstop),
++ 0, NULL);
+ }meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +16
-0+ + /* Selftests for layout_range::contains_point and +@@ -964,7 +967,7 @@ layout::layout (diagnostic_context * con + : m_context (context), + m_pp (context->printer), + m_primary_loc (richloc->get_range (0)->m_loc), +- m_exploc (richloc->get_expanded_location (0)), ++ m_exploc (richloc->get_expanded_location (0), context->tabstop), + m_colorizer (context, diagnostic_kind), + m_colorize_source_p (context->colorize_source_p), + m_show_labels_p (context->show_labels_p), +@@ -1060,7 +1063,10 @@ layout::maybe_add_location_range (const + + /* Everything is now known to be in the correct source file, + but it may require further sanitization. */ +- layout_range ri (&start, &finish, loc_range-Quoted 1 line
m_range_display_kind, &caret,++
layout_rangeri (exploc_with_display_col(start, m_context-Quoted 1 line
tabstop),
++
exploc_with_display_col(finish, m_context-Quoted 1 line
tabstop),
++
loc_range->m_range_display_kind,
++exploc_with_display_col(caret, m_context-Quoted 1 line
tabstop),
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +5
-0+ original_idx, loc_range->m_label); + + /* If we have a range that finishes before it starts (perhaps +@@ -1394,7 +1400,7 @@ layout::calculate_x_offset_display () + = get_line_bytes_without_trailing_whitespace (line.get_buffer(),
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +4
-0+ line.length ()); + int eol_display_column +- = cpp_display_width (line.get_buffer (), line_bytes); ++ = cpp_display_width (line.get_buffer (), line_bytes, m_context-Quoted 1 line
tabstop);
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +7
-0+ if (caret_display_column > eol_display_column + || !caret_display_column) + { +@@ -1445,16 +1451,13 @@ layout::calculate_x_offset_display () + } + + /* Print line ROW of source code, potentially colorized at anyranges, and
+- populate *LBOUNDS_OUT. +- LINE is the source line (not necessarily 0-terminated) and LINE_BYTES +- is its length in bytes. +- This function deals only with byte offsets, not display columns, so +- m_x_offset_display must be converted from display to byte units. In +- particular, LINE_BYTES and LBOUNDS_OUT are in bytes. */ ++ return the line bounds. LINE is the source line (notnecessarily
++ 0-terminated) andLINE_BYTESis its length in bytes. In order
to handle both
++ colorization and tab expansion, this function tracks the line
position in
++ both byte and display column units. */
++-void +-layout::print_source_line (linenum_type row, const char *line, int
line_bytes,
+-line_bounds*lbounds_out)
++line_bounds
++layout::print_source_line (linenum_typerow, const char *line, intline_bytes)
+ {meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +7
-0+ m_colorizer.set_normal_text (); + +@@ -1469,30 +1472,29 @@ layout::print_source_line (linenum_type + else + pp_space (m_pp); + +- /* We will stop printing the source line at any trailingwhitespace, and start
+- printing it as per m_x_offset_display. */ ++ /* We will stop printing the source line at any trailing whitespace. */meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2
-0+ line_bytes = get_line_bytes_without_trailing_whitespace (line, +
line_bytes);+- int x_offset_bytes = 0; +- if (m_x_offset_display) +- { +- x_offset_bytes = cpp_display_column_to_byte_column (line,
line_bytes,
+-m_x_offset_display);
+- /* In case the leading portion of the line that will be
skipped over ends
+- with a character with wcwidth > 1, then it is possible we
skipped too+- much, so account for that by padding with spaces. */ +- const int overage +- = cpp_byte_column_to_display_column (line, line_bytes, x_offset_bytes) +- - m_x_offset_display; +- for (int column = 0; column < overage; ++column) +- pp_space (m_pp); +- line += x_offset_bytes; +- } + +- /* Print the line. */ +- int first_non_ws = INT_MAX; +- int last_non_ws = 0; +- for (int col_byte = 1 + x_offset_bytes; col_byte <= line_bytes;col_byte++)
++ /* This object helps to keep track of which display column we are at, which is
++ necessary for computing the line bounds in display units, for
doing
++ tab expansion, and for implementingm_x_offset_display. */
++cpp_display_width_computationdw (line,line_bytes, m_context-Quoted 1 line
tabstop);
++
++ /* Skip the firstm_x_offset_displaydisplay columns. In case the leading
++ portion that will be skipped ends with a character with
wcwidth > 1, then
++ it is possible we skipped too much, so account for that by
padding with
++ spaces. Note that this does the right thing too in case a tab
was the last
++ character to be skipped over; the tab is effectively replaced
by the
++ correct number of trailing spaces needed to offset by the
desired number of
++ display columns. */
++ for (intskipped_display_cols= dw.advance_display_cols (m_x_offset_display);
++skipped_display_cols>m_x_offset_display; --skipped_display_cols)
++pp_space(m_pp);
++++ /* Print the line and compute the line_bounds. */ ++ line_bounds lbounds; ++ while (!dw.done ())meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +2
-0+ { + /* Assuming colorization is enabled for the caret andunderline
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +21
-0+ characters, we may also colorize the associated characters +@@ -1510,7 +1512,8 @@ layout::print_source_line (linenum_type + { + bool in_range_p; + point_state state; +- in_range_p = get_state_at_point (row, col_byte, ++ const int start_byte_col = dw.bytes_processed () + 1; ++ in_range_p = get_state_at_point (row, start_byte_col, + 0, INT_MAX, + CU_BYTES, + &state); +@@ -1519,22 +1522,44 @@ layout::print_source_line (linenum_type + else + m_colorizer.set_normal_text (); + } +- char c = *line; +- if (c == '\0' || c == '\t' || c == '\r') +- c = ' '; +- if (c != ' ') ++ ++ /* Get the display width of the next character to be output,expanding
++ tabs and replacing some control bytes with spaces as
necessary. */++ const char *c = dw.next_byte (); ++ const int start_disp_col = dw.display_cols_processed () + 1; ++ const int this_display_width = dw.process_next_codepoint (); ++ if (*c == '\t') ++ {++ /* The returned display width is the number of spaces into
which the
++ tab should be expanded. */
++ for (int i = 0; i !=this_display_width; ++i)
++pp_space(m_pp);
++ continue;++ } ++ if (*c == '\0' || *c == '\r') + { +- last_non_ws = col_byte; +- if (first_non_ws == INT_MAX) +- first_non_ws = col_byte; ++ /* cpp_wcwidth() promises to return 1 for all controlbytes, and we
++ want to output these as a single space too, so this case
is
++ actually the same as the '\t' case. */++ gcc_assert (this_display_width == 1); ++ pp_space (m_pp); ++ continue; + } +- pp_character (m_pp, c); +- line++;++
++ /* We have a (possibly multibyte) character to output; update
the line
++ bounds if it is not whitespace. */
++ if (*c != ' ')
++ {
++ lbounds.m_last_non_ws_disp_col = dw.display_cols_processed
();
++ if (lbounds.m_first_non_ws_disp_col ==INT_MAX)
++ lbounds.m_first_non_ws_disp_col =start_disp_col;
++ }
++
++ /* Output the character. */
++ while (c != dw.next_byte ())pp_character(m_pp, *c++);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +14
-0+ } + print_newline (); +- +- lbounds_out->m_first_non_ws = first_non_ws; +- lbounds_out->m_last_non_ws = last_non_ws; ++ return lbounds; + } + + /* Determine if we should print an annotation line for ROW. +@@ -1576,14 +1601,13 @@ layout::start_annotation_line (char marg + } + + /* Print a line consisting of the caret/underlines for the given +- source line. This function works with display columns, ratherthan byte
+- counts; in particular, LBOUNDS should be in display column units. */ ++ source line. */+
+ void
+layout::print_annotation_line(linenum_typerow, constline_boundslbounds)
+ {meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +13
-0+ int x_bound = get_x_bound_for_row (row, m_exploc.m_display_col, +- lbounds.m_last_non_ws); ++ lbounds.m_last_non_ws_disp_col); + + start_annotation_line (); + pp_space (m_pp); +@@ -1593,8 +1617,8 @@ layout::print_annotation_line (linenum_t + bool in_range_p; + point_state state; + in_range_p = get_state_at_point (row, column, +- lbounds.m_first_non_ws, +- lbounds.m_last_non_ws, ++lbounds.m_first_non_ws_disp_col,
++
lbounds.m_last_non_ws_disp_col,meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +9
-0+ CU_DISPLAY_COLS, + &state); + if (in_range_p) +@@ -1631,12 +1655,14 @@ layout::print_annotation_line (linenum_t + class line_label + { + public: +- line_label (int state_idx, int column, label_text text) ++ line_label (diagnostic_context *context, int state_idx, intcolumn,
++label_texttext)meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +22
-0+ : m_state_idx (state_idx), m_column (column), + m_text (text), m_label_line (0), m_has_vbar (true) + { + const int bytes = strlen (text.m_buffer); +- m_display_width = cpp_display_width (text.m_buffer, bytes); ++ m_display_width ++ = cpp_display_width (text.m_buffer, bytes, context->tabstop); + } + + /* Sorting is primarily by column, then by state index. */ +@@ -1696,7 +1722,7 @@ layout::print_any_labels (linenum_type r + if (text.m_buffer == NULL) + continue; + +- labels.safe_push (line_label (i, disp_col, text)); ++ labels.safe_push (line_label (m_context, i, disp_col, text)); + } + } + +@@ -1976,7 +2002,8 @@ public: + + /* Get the range of bytes or display columns that HINT wouldaffect. */
+ staticcolumn_range
+-get_affected_range (constfixit_hint*hint, enumcolumn_unitcol_unit)
++get_affected_range (diagnostic_context*context,
++ constfixit_hint*hint, enumcolumn_unitcol_unit)
+ {
+expanded_locationexploc_start=expand_location(hint-Quoted 1 line
get_start_loc());+
expanded_locationexploc_finish=expand_location(hint-Quoted 1 line
get_next_loc());+@@ -1986,11 +2013,13 @@
get_affected_range(constfixit_hint*himeta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +4
-0+ int finish_column; + if (col_unit == CU_DISPLAY_COLS) + { +- start_column = location_compute_display_column(
exploc_start);
++start_column
++ =location_compute_display_column(exploc_start, context-Quoted 1 line
tabstop);
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +4
-0+ if (hint->insertion_p ()) + finish_column = start_column - 1; + else +- finish_column = location_compute_display_column(
exploc_finish);
++finish_column
++ =location_compute_display_column(exploc_finish, context-Quoted 1 line
tabstop);
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +5
-0+ } + else + { +@@ -2003,12 +2032,12 @@ get_affected_range (const fixit_hint *hi + /* Get the range of display columns that would be printed forHINT. */
+
+ staticcolumn_range
+-get_printed_columns (constfixit_hint*hint) ++get_printed_columns (diagnostic_context*context, constfixit_hint*hint)
+ {
+expanded_locationexploc =expand_location(hint->get_start_loc
());+- int start_column = location_compute_display_column (exploc); +- int hint_width = cpp_display_width (hint->get_string (), +- hint->get_length ()); ++ int start_column = location_compute_display_column (exploc,
context->tabstop);
++ inthint_width=cpp_display_width(hint->get_string(), hint-Quoted 1 line
get_length(),++
context->tabstop);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +35
-0+ int final_hint_column = start_column + hint_width - 1; + if (hint->insertion_p ()) + { +@@ -2018,7 +2047,8 @@ get_printed_columns (const fixit_hint *h + { + exploc = expand_location (hint->get_next_loc ()); + --exploc.column; +- int finish_column = location_compute_display_column (exploc); ++ int finish_column ++ = location_compute_display_column (exploc, context->tabstop); + return column_range (start_column, + MAX (finish_column, final_hint_column)); + } +@@ -2035,12 +2065,14 @@ public: + correction (column_range affected_bytes, + column_range affected_columns, + column_range printed_columns, +- const char *new_text, size_t new_text_len) ++ const char *new_text, size_t new_text_len, ++ int tabstop) + : m_affected_bytes (affected_bytes), + m_affected_columns (affected_columns), + m_printed_columns (printed_columns), + m_text (xstrdup (new_text)), + m_byte_length (new_text_len), ++ m_tabstop (tabstop), + m_alloc_sz (new_text_len + 1) + { + compute_display_cols (); +@@ -2058,7 +2090,7 @@ public: + + void compute_display_cols () + { +- m_display_cols = cpp_display_width (m_text, m_byte_length); ++ m_display_cols = cpp_display_width (m_text, m_byte_length,
m_tabstop);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +18
-0+ } + + void overwrite (int dst_offset, const char_span &src_span) +@@ -2086,6 +2118,7 @@ public: + char *m_text; + size_t m_byte_length; /* Not including null-terminator. */ + int m_display_cols; ++ int m_tabstop; + size_t m_alloc_sz; + }; + +@@ -2121,13 +2154,15 @@ correction::ensure_terminated () + class line_corrections + { + public: +- line_corrections (const char *filename, linenum_type row) +- : m_filename (filename), m_row (row) ++ line_corrections (diagnostic_context *context, const char*filename,
++linenum_typerow)
++ :m_context(context),m_filename(filename),m_row(row)meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +14
-0+ {} + ~line_corrections (); + + void add_hint (const fixit_hint *hint); + ++ diagnostic_context *m_context; + const char *m_filename; + linenum_type m_row; + auto_vec <correction *> m_corrections; +@@ -2173,9 +2208,10 @@ source_line::source_line (const char *fi + void + line_corrections::add_hint (const fixit_hint *hint) + { +- column_range affected_bytes = get_affected_range (hint,
CU_BYTES);
+-column_rangeaffected_columns=get_affected_range(hint,CU_DISPLAY_COLS);+- column_range printed_columns = get_printed_columns (hint); ++ column_range affected_bytes = get_affected_range (m_context,hint,
CU_BYTES);
++column_rangeaffected_columns=get_affected_range(m_context, hint,
++CU_DISPLAY_COLS);
++column_rangeprinted_columns=get_printed_columns(m_context, hint);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +17
-0+ + /* Potentially consolidate. */ + if (!m_corrections.is_empty ()) +@@ -2243,7 +2279,8 @@ line_corrections::add_hint (const fixit_ + affected_columns, + printed_columns, + hint->get_string (), +- hint->get_length ())); ++ hint->get_length (), ++ m_context->tabstop)); + } + + /* If there are any fixit hints on source line ROW, print them. +@@ -2257,7 +2294,7 @@ layout::print_trailing_fixits (linenum_t + { + /* Build a list of correction instances for the line, + potentially consolidating hints (for the sake ofreadability). */
+- line_corrections corrections (m_exploc.file, row); ++ line_corrections corrections (m_context, m_exploc.file, row);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +10
-0+ for (unsigned int i = 0; i < m_fixit_hints.length (); i++) + { + const fixit_hint *hint = m_fixit_hints[i]; +@@ -2499,15 +2536,11 @@ layout::print_line (linenum_type row) + if (!line) + return; + +- line_bounds lbounds; + print_leading_fixits (row); +- print_source_line (row, line.get_buffer (), line.length (),&lbounds);
++ constline_boundslbounds
++ =print_source_line(row, line.get_buffer (), line.length ());meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +13
-0+ if (should_print_annotation_line_p (row)) +- { +- if (lbounds.m_first_non_ws != INT_MAX) +- lbounds.convert_to_display_cols (line); +- print_annotation_line (row, lbounds); +- } ++ print_annotation_line (row, lbounds); + if (m_show_labels_p) + print_any_labels (row); + print_trailing_fixits (row); +@@ -2670,9 +2703,11 @@ test_layout_x_offset_display_utf8 (const + + char_span lspan = location_get_source_line (tmp.get_filename (),1);
+ASSERT_EQ(line_display_cols,
+-cpp_display_width(lspan.get_buffer (), lspan.length
()));
++cpp_display_width(lspan.get_buffer (), lspan.length (),
++def_tabstop));
+ASSERT_EQ(line_display_cols,
+-location_compute_display_column(expand_location
(line_end)));
++location_compute_display_column(expand_location
(line_end),
++def_tabstop));meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +12
-0+ ASSERT_EQ (0, memcmp (lspan.get_buffer () + (emoji_col - 1), + "\xf0\x9f\x98\x82\xf0\x9f\x98\x82", 8)); + +@@ -2774,6 +2809,111 @@ test_layout_x_offset_display_utf8 (const + + } + ++static void ++test_layout_x_offset_display_tab (const line_table_case &case_) ++{ ++ const char *content ++ = "This line is very long, so that we can use it to test thelogic for "
++ "clipping long lines. Also this: `\t' is a tab that occupies
1 byte and "
++ "a variable number of display columns, starting at column
#103.\n";
++
++ /* Number of bytes in the line, subtracting one to remove the newline. */
++ const intline_bytes= strlen (content) - 1;
++
++ /* The column where the tab begins. Byte or display is the same as there are
++ no multibyte characters earlier on the line. */
++ const inttab_col= 103;
++
++ /* Effective extra size of the tab beyond what a single space would have taken
++ up, indexed by tabstop. */++ static const int num_tabstops = 11; ++ int extra_width[num_tabstops]; ++ for (int tabstop = 1; tabstop != num_tabstops; ++tabstop)++ {
++ const intthis_tab_size= tabstop - (tab_col- 1) % tabstop;
++ extra_width[tabstop] =this_tab_size- 1;
++ }
++ /* Example of this calculation: if tabstop is 10, the tab starting at column
++ #103 has to expand into 8 spaces, covering columns 103-110, so
that the
++ next character is at column #111. So it takes up 7 more
columns than
++ a space would have taken up. */
++ASSERT_EQ(7, extra_width[10]);
++
++temp_source_filetmp (SELFTEST_LOCATION, ".c", content); ++line_table_testltt (case_);
++
++linemap_add(line_table,LC_ENTER, false, tmp.get_filename (), 1);
++
++location_tline_end=linemap_position_for_column(line_table,line_bytes);
++
++ /* Don't attempt to run the tests if column data might be unavailable. */
++ if (line_end>LINE_MAP_MAX_LOCATION_WITH_COLS)
++ return;
++
++ /* Check thatcpp_display_widthhandles the tabs as expected. */ ++char_spanlspan =location_get_source_line(tmp.get_filename (), 1);
++ASSERT_EQ('\t', *(lspan.get_buffer () + (tab_col- 1))); ++ for (int tabstop = 1; tabstop !=num_tabstops; ++tabstop)
++ {
++ASSERT_EQ(line_bytes+ extra_width[tabstop],
++cpp_display_width(lspan.get_buffer (), lspan.length
(),
++ tabstop));
++ASSERT_EQ(line_bytes+ extra_width[tabstop],
++location_compute_display_column(expand_location
(line_end),
++ tabstop));
++ }
++
++ /* Check that the tab is expanded to the expected number of spaces. */
++rich_locationrichloc (line_table,
++linemap_position_for_column(line_table,
++tab_col+ 1));
++ for (int tabstop = 1; tabstop !=num_tabstops; ++tabstop)
++ {++ test_diagnostic_context dc; ++ dc.tabstop = tabstop; ++ layout test_layout (&dc, &richloc, DK_ERROR); ++ test_layout.print_line (1); ++ const char *out = pp_formatted_text (dc.printer); ++ ASSERT_EQ (NULL, strchr (out, '\t')); ++ const char *left_quote = strchr (out, '`'); ++ const char *right_quote = strchr (out, '\''); ++ ASSERT_NE (NULL, left_quote); ++ ASSERT_NE (NULL, right_quote); ++ ASSERT_EQ (right_quote - left_quote, extra_width[tabstop] +2);
++ }
++
++ /* Check that the line is offset properly and that the tab is broken up
++ into the expected number of spaces when it is the last
character skipped
++ over. */
++ for (int tabstop = 1; tabstop !=num_tabstops; ++tabstop)
++ {++ test_diagnostic_context dc; ++ dc.tabstop = tabstop; ++ static const int small_width = 24; ++ dc.caret_max_width = small_width - 4; ++ dc.min_margin_width = test_left_margin - test_linenum_sep + 1; ++ dc.show_line_numbers_p = true; ++ layout test_layout (&dc, &richloc, DK_ERROR); ++ test_layout.print_line (1);++
++ /* We have arranged things so that two columns will be
printed before
++ the caret. If the tab results in more than one space, this
should
++ produce two spaces in the output; otherwise, it will be a
single space
++ preceded by the opening quote before the tab character. */
++ const char *output1
++ = " 1 | ' is a tab that occupies 1 byte and a variable
number of "
++ "display columns, starting at column #103.\n"
++ " | ^\n\n";
++ const char *output2
++ = " 1 | ` ' is a tab that occupies 1 byte and a variable
number of "
++ "display columns, starting at column #103.\n"
++ " | ^\n\n";
++ const char*expected_output= (extra_width[tabstop] ? output1
: output2);
++ASSERT_STREQ(expected_output,pp_formatted_text
(dc.printer));
++ }
++}
++
++
+ /* Verify thatdiagnostic_show_locusworks sanely onUNKNOWN_LOCATION. */meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +15
-0+ + static void +@@ -3854,6 +3994,27 @@ test_one_liner_labels_utf8 () + } + } + ++/* Make sure that colorization codes don't interrupt a multibyte ++ sequence, which would corrupt it. */ ++static void ++test_one_liner_colorized_utf8 () ++{ ++ test_diagnostic_context dc; ++ dc.colorize_source_p = true; ++ diagnostic_color_init (&dc, DIAGNOSTICS_COLOR_YES); ++ const location_t pi = linemap_position_for_column (line_table,12);
++rich_locationrichloc (line_table, pi);
++diagnostic_show_locus(&dc, &richloc,DK_ERROR);
++
++ /* In order to avoid having the test depend on exactly how the colorization
++ was effected, just confirm there are two pi characters in the
output. */++ const char *result = pp_formatted_text (dc.printer); ++ const char *null_term = result + strlen (result); ++ const char *first_pi = strstr (result, "\xcf\x80"); ++ ASSERT_TRUE (first_pi && first_pi <= null_term - 2); ++ ASSERT_STR_CONTAINS (first_pi + 2, "\xcf\x80");++}
++
+ /* Run the various one-liner tests. */meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +6
-0+ + static void +@@ -3884,8 +4045,10 @@ test_diagnostic_show_locus_one_liner_utf + ASSERT_EQ (31, LOCATION_COLUMN (line_end)); + + char_span lspan = location_get_source_line (tmp.get_filename (),1);
+-ASSERT_EQ(25,cpp_display_width(lspan.get_buffer (), lspan.length ()));
+-ASSERT_EQ(25,location_compute_display_column(expand_location(line_end)));
++ASSERT_EQ(25,cpp_display_width(lspan.get_buffer (), lspan.length (),
++def_tabstop));
++ASSERT_EQ(25,location_compute_display_column(expand_location(line_end),
++def_tabstop));meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +16
-0+ + test_one_liner_simple_caret_utf8 (); + test_one_liner_caret_and_range_utf8 (); +@@ -3900,6 +4063,7 @@ test_diagnostic_show_locus_one_liner_utf + test_one_liner_many_fixits_1_utf8 (); + test_one_liner_many_fixits_2_utf8 (); + test_one_liner_labels_utf8 (); ++ test_one_liner_colorized_utf8 (); + } + + /* Verify that gcc_rich_location::add_location_if_nearby works. */ +@@ -4272,25 +4436,28 @@ test_overlapped_fixit_printing (const li + /* Unit-test the line_corrections machinery. */ + ASSERT_EQ (3, richloc.get_num_fixit_hints ()); + const fixit_hint *hint_0 = richloc.get_fixit_hint (0); +- ASSERT_EQ (column_range (12, 12), get_affected_range (hint_0,
CU_BYTES));
+ASSERT_EQ(column_range(12, 12),
+-get_affected_range(hint_0,CU_DISPLAY_COLS));
+-ASSERT_EQ(column_range(12, 22),get_printed_columns
(hint_0));
++get_affected_range(&dc,hint_0,CU_BYTES));
++ASSERT_EQ(column_range(12, 12),
++get_affected_range(&dc,hint_0,CU_DISPLAY_COLS));
++ASSERT_EQ(column_range(12, 22),get_printed_columns(&dc,hint_0));
+ constfixit_hint*hint_1= richloc.get_fixit_hint (1);
+-ASSERT_EQ(column_range(18, 18),get_affected_range(hint_1,CU_BYTES));
+ASSERT_EQ(column_range(18, 18),
+-get_affected_range(hint_1,CU_DISPLAY_COLS));
+-ASSERT_EQ(column_range(18, 20),get_printed_columns
(hint_1));
++get_affected_range(&dc,hint_1,CU_BYTES));
++ASSERT_EQ(column_range(18, 18),
++get_affected_range(&dc,hint_1,CU_DISPLAY_COLS));
++ASSERT_EQ(column_range(18, 20),get_printed_columns(&dc,hint_1));
+ constfixit_hint*hint_2= richloc.get_fixit_hint (2);
+-ASSERT_EQ(column_range(29, 28),get_affected_range(hint_2,CU_BYTES));
+ASSERT_EQ(column_range(29, 28),
+-get_affected_range(hint_2,CU_DISPLAY_COLS));
+-ASSERT_EQ(column_range(29, 29),get_printed_columns
(hint_2));
++get_affected_range(&dc,hint_2,CU_BYTES));
++ASSERT_EQ(column_range(29, 28),
++get_affected_range(&dc,hint_2,CU_DISPLAY_COLS));
++ASSERT_EQ(column_range(29, 29),get_printed_columns(&dc,hint_2));meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+ + /* Add each hint in turn to a line_corrections instance, + and verify that they are consolidated into one correctioninstance
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +11
-0+ as expected. */ +- line_corrections lc (tmp.get_filename (), 1); ++ line_corrections lc (&dc, tmp.get_filename (), 1); + + /* The first replace hint by itself. */ + lc.add_hint (hint_0); +@@ -4484,25 +4651,28 @@ test_overlapped_fixit_printing_utf8 (con + /* Unit-test the line_corrections machinery. */ + ASSERT_EQ (3, richloc.get_num_fixit_hints ()); + const fixit_hint *hint_0 = richloc.get_fixit_hint (0); +- ASSERT_EQ (column_range (14, 14), get_affected_range (hint_0,
CU_BYTES));
++ASSERT_EQ(column_range(14, 14),
++get_affected_range(&dc,hint_0,CU_BYTES));
+ASSERT_EQ(column_range(12, 12),
+-get_affected_range(hint_0,CU_DISPLAY_COLS));
+-ASSERT_EQ(column_range(12, 22),get_printed_columns
(hint_0));
++get_affected_range(&dc,hint_0,CU_DISPLAY_COLS));
++ASSERT_EQ(column_range(12, 22),get_printed_columns(&dc,hint_0));
+ constfixit_hint*hint_1= richloc.get_fixit_hint (1);
+-ASSERT_EQ(column_range(22, 22),get_affected_range(hint_1,CU_BYTES));
++ASSERT_EQ(column_range(22, 22),
++get_affected_range(&dc,hint_1,CU_BYTES));
+ASSERT_EQ(column_range(18, 18),
+-get_affected_range(hint_1,CU_DISPLAY_COLS));
+-ASSERT_EQ(column_range(18, 20),get_printed_columns
(hint_1));
++get_affected_range(&dc,hint_1,CU_DISPLAY_COLS));
++ASSERT_EQ(column_range(18, 20),get_printed_columns(&dc,hint_1));
+ constfixit_hint*hint_2= richloc.get_fixit_hint (2);
+-ASSERT_EQ(column_range(35, 34),get_affected_range(hint_2,CU_BYTES));
++ASSERT_EQ(column_range(35, 34),
++get_affected_range(&dc,hint_2,CU_BYTES));
+ASSERT_EQ(column_range(30, 29),
+-get_affected_range(hint_2,CU_DISPLAY_COLS));
+-ASSERT_EQ(column_range(30, 30),get_printed_columns
(hint_2));
++get_affected_range(&dc,hint_2,CU_DISPLAY_COLS));
++ASSERT_EQ(column_range(30, 30),get_printed_columns(&dc,hint_2));meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+ + /* Add each hint in turn to a line_corrections instance, + and verify that they are consolidated into one correctioninstance
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +17
-0+ as expected. */ +- line_corrections lc (tmp.get_filename (), 1); ++ line_corrections lc (&dc, tmp.get_filename (), 1); + + /* The first replace hint by itself. */ + lc.add_hint (hint_0); +@@ -4689,6 +4859,8 @@ test_overlapped_fixit_printing_2 (const + + /* Two insertions, in the wrong order. */ + { ++ test_diagnostic_context dc; ++ + rich_location richloc (line_table, col_20); + richloc.add_fixit_insert_before (col_23, "{"); + richloc.add_fixit_insert_before (col_21, "}"); +@@ -4696,14 +4868,15 @@ test_overlapped_fixit_printing_2 (const + /* These fixits should be accepted; they can't beconsolidated. */
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+ ASSERT_EQ (2, richloc.get_num_fixit_hints ()); + const fixit_hint *hint_0 = richloc.get_fixit_hint (0); +- ASSERT_EQ (column_range (23, 22), get_affected_range (hint_0,
CU_BYTES));
+-ASSERT_EQ(column_range(23, 23),get_printed_columns
(hint_0));
++ASSERT_EQ(column_range(23, 22),
++get_affected_range(&dc,hint_0,CU_BYTES));
++ASSERT_EQ(column_range(23, 23),get_printed_columns(&dc,hint_0));
+ constfixit_hint*hint_1= richloc.get_fixit_hint (1);
+-ASSERT_EQ(column_range(21, 20),get_affected_range(hint_1,CU_BYTES));
+-ASSERT_EQ(column_range(21, 21),get_printed_columns
(hint_1));
++ASSERT_EQ(column_range(21, 20),
++get_affected_range(&dc,hint_1,CU_BYTES));
++ASSERT_EQ(column_range(21, 21),get_printed_columns(&dc,hint_1));meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +14
-0+ + /* Verify that they're printed correctly. */ +- test_diagnostic_context dc; + diagnostic_show_locus (&dc, &richloc, DK_ERROR); + ASSERT_STREQ (" int a5[][0][0] = { 1, 2 };\n" + " ^\n" +@@ -4955,6 +5128,65 @@ test_fixit_deletion_affecting_newline (c + pp_formatted_text (dc.printer)); + } + ++static void ++test_tab_expansion (const line_table_case &case_) ++{ ++ /* Create a tempfile and write some text to it. This exampleuses a tabstop
++ of 8, as the column numbers attempt to indicate:
++++ .....................000.01111111111.22222333333 display ++ .....................123.90123456789.56789012345 columns */++ const char *content = " \t This: `\t' is a tab.\n";
++ /* ....................000 00000011111 11111222222 byte
++ ....................123 45678901234 56789012345 columns */
++++ const int tabstop = 8; ++ const int first_non_ws_byte_col = 7; ++ const int right_quote_byte_col = 15; ++ const int last_byte_col = 25; ++ ASSERT_EQ (35, cpp_display_width (content, last_byte_col, tabstop)); ++ ++ temp_source_file tmp (SELFTEST_LOCATION, ".c", content); ++ line_table_test ltt (case_); ++ linemap_add (line_table, LC_ENTER, false, tmp.get_filename (),1);
++
++ /* Don't attempt to run the tests if column data might be unavailable. */
++location_tline_end=linemap_position_for_column(line_table,last_byte_col);
++ if (line_end>LINE_MAP_MAX_LOCATION_WITH_COLS)
++ return;
++
++ /* Check that the leading whitespace with mixed tabs and spaces is expanded
++ into 11 spaces. Recall thatprint_line()also puts one space
before
++ everything too. */
++ {++ test_diagnostic_context dc; ++ dc.tabstop = tabstop; ++ rich_location richloc (line_table, ++ linemap_position_for_column (line_table, ++ first_non_ws_ byte_col)); ++ layout test_layout (&dc, &richloc, DK_ERROR); ++ test_layout.print_line (1); ++ ASSERT_STREQ (" This: ` ' is a tab.\n"++ " ^\n",
++pp_formatted_text(dc.printer));
++ }
++
++ /* Confirm the display width was tracked correctly across the internal tab
++ as well. */
++ {++ test_diagnostic_context dc; ++ dc.tabstop = tabstop; ++ rich_location richloc (line_table, ++ linemap_position_for_column (line_table, ++ right_quote_b yte_col)); ++ layout test_layout (&dc, &richloc, DK_ERROR); ++ test_layout.print_line (1); ++ ASSERT_STREQ (" This: ` ' is a tab.\n"++ " ^\n",
++pp_formatted_text(dc.printer));
++ }
++}
++
+ /* Verify that line numbers are correctly printed for the case ofmeta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +12
-0+ a multiline range in which the width of the line numbers changes + (e.g. from "9" to "10"). */ +@@ -5012,6 +5244,7 @@ diagnostic_show_locus_c_tests () + test_layout_range_for_multiple_lines (); + + for_each_line_table_case (test_layout_x_offset_display_utf8); ++ for_each_line_table_case (test_layout_x_offset_display_tab); + + test_get_line_bytes_without_trailing_whitespace (); + +@@ -5029,6 +5262,7 @@ diagnostic_show_locus_c_tests () + for_each_line_table_case(
test_fixit_insert_containing_newline_2);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +3
-0+ for_each_line_table_case (test_fixit_replace_containing_newline); + for_each_line_table_case (test_fixit_deletion_affecting_newline); ++ for_each_line_table_case (test_tab_expansion);meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch
Quoted 10 lines
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +9
-1+ + test_line_numbers_multiline_range (); + } +diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi +--- a/gcc/doc/invoke.texi 2021-12-24 20:23:46.876739587 -0800 ++++ b/gcc/doc/invoke.texi 2021-12-25 01:20:53.487636494 -0800 +@@ -293,7 +293,9 @@ Objective-C and Objective-C++ Dialects}. + -fdiagnostics-show-template-tree -fno-elide-type @gol + -fdiagnostics-path-format=@r{[}none@r{|}separate-events@r{|}inline-events@r{
Quoted 101 lines
]} @gol
+ -fdiagnostics-show-path-depths @gol
+--fno-show-column}
++-fno-show-column @gol ++-fdiagnostics-column-unit=@r{[}display@r{|}byte@r{]} @gol ++-fdiagnostics-column-origin=@var{origin}}
+
+ @item Warning Options
+ @xref{Warning Options,,Options to Request or Suppress Warnings}. +@@ -4424,6 +4426,31 @@ Do not print column numbers in diagnosti
+ diagnostics are being scanned by a program that does not understand the
+ column numbers, such as @command{dejagnu}.
+
++@item -fdiagnostics-column-unit=@var{UNIT}
++@opindex fdiagnostics-column-unit
++Select the units for the column number. This affects traditional diagnostics
++(in the absence of @option{-fno-show-column}), as well as JSON format
++diagnostics if requested.
++
++The default @var{UNIT}, @samp{display}, considers the number of display
++columns occupied by each character. This may be larger than the number
++of bytes required to encode the character, in the case of tab ++characters, or it may be smaller, in the case of multibyte characters.
++For example, the character ``GREEK SMALL LETTER PI (U+03C0)'' occupies one
++display column, and its UTF-8 encoding requires two bytes; the character
++``SLIGHTLY SMILING FACE (U+1F642)'' occupies two display columns, and
++its UTF-8 encoding requires four bytes.
++
++Setting @var{UNIT} to @samp{byte} changes the column number to the raw byte
++count in all cases, as was traditionally output by GCC prior to version 11.1.0.
++
++@item -fdiagnostics-column-origin=@var{ORIGIN} ++@opindex fdiagnostics-column-origin
++Select the origin for column numbers, i.e. the column number assigned to the
++first column. The default value of 1 corresponds to traditional GCC
++behavior and to the GNU style guide. Some utilities may perform better with an
++origin of 0; any non-negative value may be specified.
++
+ @item -fdiagnostics-format=@var{FORMAT}
+ @opindex fdiagnostics-format
+ Select a different format for printing diagnostics.
+@@ -4459,11 +4486,15 @@ might be printed in JSON form (after formeta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +26
-0+ "locations": [ + @{ + "caret": @{ ++ "display-column": 3, ++ "byte-column": 3, + "column": 3, + "file": "misleading-indentation.c", + "line": 15 + @}, + "finish": @{ ++ "display-column": 4, ++ "byte-column": 4, + "column": 4, + "file": "misleading-indentation.c", + "line": 15 +@@ -4479,6 +4510,8 @@ might be printed in JSON form (after for + "locations": [ + @{ + "caret": @{ ++ "display-column": 5, ++ "byte-column": 5, + "column": 5, + "file": "misleading-indentation.c", + "line": 17 +@@ -4488,6 +4521,7 @@ might be printed in JSON form (after for + "message": "...this statement, but the latter is@dots{}"
meta/recipes-devtools/gcc/gcc/0001-CVE-2021-42574.patch new file +8
-0+ @} + ] ++ "column-origin": 1, + @}, + @dots{} + ] +@@ -4500,10 +4534,34 @@ A diagnostic has a @code{kind}. If this + an @code{option} key describing the command-line option controllingthe
+ warning.
+
+-A diagnostic can contain zero or more locations. Each location has up+-to three positions within it: a @code{caret} position and optional +-@code{start} and @code{finish} positions. A location can also have +-an optional @code{label} string. For example, this error: ++A diagnostic can contain zero or more locations. Each location has
Hi Khem Raj,
Quoted 2 lines
Key is When git send-email asks for UTF-8 encoding for the patch then do not enter “y” but just press Enter
Thanks for informing about the method to post UTF-8 format patches.
Posted the patch as per your suggestion at :-
https://lists.openembedded.org/g/openembedded-core/message/160175
Thanks,
Pgowda