Age | Commit message (Collapse) | Author | Files | Lines |
|
Found by dg-lint.
gcc/testsuite/ChangeLog:
* gcc.dg/ipa/pr110377.c: Fix missing trailing " }" in dg-do
directive.
* gcc.dg/plugin/infoleak-1.c: Fix dg-bogus directive.
* gcc.dg/pr101364-1.c: Fix missing trailing " }" in dg-options
directive.
* gcc.dg/pr113207.c: Fix dg-do.
* gcc.dg/sarif-output/include-chain-2.c: Fix ordering of dg-do
and dg-require-effective-target.
* gcc.dg/strub-pr118007.c: Likewise.
* gcc.dg/tanhbysinh.c: Fix missing whitespace after opening
brace and before closing brace in 6 dg-final directives.
* gcc.dg/uninit-pred-3_c.c: Fix missing whitespace after opening
brace in 6 dg-final directive.
* gcc.dg/uninit-pred-3_d.c: Likewise.
* gcc.dg/variable-sized-type-flex-array.c: Fix missing space
between dg-bogus and message in 2 places.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
|
|
libgdiagnostics was written before the fixes for PR other/116613 allowed
a diagnostic_context to have multiple output sinks.
Hence each libgdiagnostics sink had its own diagnostic_context with just
one diagnostic_output_format.
This wart is no longer necessary and makes it harder to move state
into the manager/context; in particular for quoting source code
from the .sarif file (PR sarif-replay/117943).
Simplify, by making libgdiagnostics' implementation more similar to
GCC's implementation, by moving the diagnostic_context from sink into
diagnostic_manager.
Doing so requires generalizing where the
diagnostic_source_printing_options comes from in class
diagnostic_text_output_format: for GCC we use
the instance within the diagnostic_context, whereas for
libgdiagnostics each diagnostic_text_sink has its own instance.
No functional change intended.
gcc/c-family/ChangeLog:
PR sarif-replay/117943
* c-format.cc (selftest::test_type_mismatch_range_labels): Use
dc.m_source_printing.
* c-opts.cc (c_diagnostic_text_finalizer): Use source-printing
options from text_output.
gcc/cp/ChangeLog:
PR sarif-replay/117943
* error.cc (auto_context_line::~auto_context_line): Use
source-printing options from text_output.
gcc/ChangeLog:
PR sarif-replay/117943
* diagnostic-format-text.cc
(diagnostic_text_output_format::append_note): Use source-printing
options from text_output.
(diagnostic_text_output_format::update_printer): Copy
source-printing options from dc.
(default_diagnostic_text_finalizer): Use source-printing
options from text_output.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Add optional diagnostic_source_printing_options param, using
the context's if null.
(diagnostic_text_output_format::get_source_printing_options): New
accessor.
(diagnostic_text_output_format::m_source_printing): New field.
* diagnostic-path.cc (event_range::print): Use source-printing
options from text_output.
(selftest::test_interprocedural_path_1): Use source-printing
options from dc.
* diagnostic-show-locus.cc
(gcc_rich_location::add_location_if_nearby): Likewise.
(diagnostic_context::maybe_show_locus): Add "opts" param
and use in place of m_source_printing. Pass it to source_policy
ctor.
(diagnostic_source_print_policy::diagnostic_source_print_policy):
Add overload taking a const diagnostic_source_printing_options &.
* diagnostic.cc (diagnostic_context::initialize): Pass nullptr
for source options when creating text sink, so that it uses
the dc's options.
(diagnostic_context::dump): Add an "output sinks:" heading and
print "(none)" if there aren't any.
(diagnostic_context::set_output_format): Split out code into...
(diagnostic_context::remove_all_output_sinks): ...this new
function.
* diagnostic.h
(diagnostic_source_print_policy::diagnostic_source_print_policy):
Add overload taking a const diagnostic_source_printing_options &.
(diagnostic_context::maybe_show_locus): Add "opts" param.
(diagnostic_context::remove_all_output_sinks): New decl.
(diagnostic_context::m_source_printing): New field.
(diagnostic_show_locus): Add "opts" param and pass to
maybe_show_locus.
* libgdiagnostics.cc (sink::~sink): Delete.
(sink::begin_group): Delete.
(sink::end_group): Delete.
(sink::emit): Delete.
(sink::m_dc): Drop field.
(diagnostic_text_sink::on_begin_text_diagnostic): Delete.
(diagnostic_text_sink::get_source_printing_options): Use
m_souece_printing.
(diagnostic_text_sink::m_current_logical_loc): Drop field.
(diagnostic_text_sink::m_inner_sink): New field.
(diagnostic_text_sink::m_source_printing): New field.
(diagnostic_manager::diagnostic_manager): Update for changes
to fields. Initialize m_dc.
(diagnostic_manager::~diagnostic_manager): Call diagnostic_finish.
(diagnostic_manager::get_file_cache): Drop.
(diagnostic_manager::get_dc): New accessor.
(diagnostic_manager::begin_group): Reimplement.
(diagnostic_manager::end_group): Reimplement.
(diagnostic_manager::get_prev_diag_logical_loc): New accessor.
(diagnostic_manager::m_dc): New field.
(diagnostic_manager::m_file_cache): Drop field.
(diagnostic_manager::m_edit_context): Convert to a std::unique_ptr
so that object can be constructed after m_dc is initialized.
(diagnostic_manager::m_prev_diag_logical_loc): New field.
(diagnostic_text_sink::diagnostic_text_sink): Reimplement.
(get_color_rule): Delete.
(diagnostic_text_sink::set_colorize): Reimplement.
(diagnostic_text_sink::text_starter): New.
(sarif_sink::sarif_sink): Reimplement.
(diagnostic_manager::write_patch): Update for change to
m_edit_context.
(diagnostic_manager::emit): Update now that each sink has a
corresponding diagnostic_output_format object within m_dc.
gcc/fortran/ChangeLog:
PR sarif-replay/117943
* error.cc (gfc_diagnostic_text_starter): Use source-printing
options from text_output.
gcc/testsuite/ChangeLog:
PR sarif-replay/117943
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc
(custom_diagnostic_text_finalizer): Use source-printing options
from text_output.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.cc
(xhtml_builder::make_element_for_diagnostic): Use source-printing
options from diagnostic_context.
* gcc.dg/plugin/expensive_selftests_plugin.cc (test_richloc):
Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This patch is a followup to:
"c++: use diagnostic nesting [PR116253]"
This patch tweaks how text output with experimental-nesting=yes
prints nested diagnostics, by omitting the leading "note: " from
nested notes.
This reduces the amount of visual cruft the user has to ignore when
reading C++ template errors; see the examples in the testsuite.
This doesn't affect the output for users who have not opted-in
to nested diagnostic-printing.
gcc/ChangeLog:
PR other/116253
* diagnostic-format-text.cc (build_prefix): Don't add the
"note: " prefix when showing nested diagnostics.
gcc/testsuite/ChangeLog:
PR other/116253
* g++.dg/concepts/nested-diagnostics-1-truncated.C: Update
expected output.
* g++.dg/concepts/nested-diagnostics-1.C: Likewise.
* g++.dg/concepts/nested-diagnostics-2.C: Likewise.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c:
Likewise.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c:
Likewise.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented.c: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Change location_t to be a 64-bit integer instead of a 32-bit integer in
libcpp.
Also included in this change are the two other patches in the original
series which depended on this one; I am committing them all at once in case
it needs to be reverted later:
-Support for 64-bit location_t: gimple parts
The size of struct gimple increased by 8 bytes with the change in size of
location_t from 32- to 64-bit; adjust the WORD markings in the comments
accordingly. It seems that most of the WORD markings were off by one already,
probably not having been updated after a previous reduction in the size of a
gimple, so they have become retroactively correct again, and only a couple
needed adjustment actually.
Also add a comment that there is now 32 bits of unused padding available in
struct gimple for 64-bit hosts.
-Support for 64-bit location_t: Remove -flarge-source-files
The option -flarge-source-files became unnecessary with 64-bit location_t
and harms performance compared to the new default setting, so silently
ignore it.
libcpp/ChangeLog:
* include/cpplib.h (struct cpp_token): Adjust comment about the
struct size.
* include/line-map.h (location_t): Change typedef from 32-bit to 64-bit
integer.
(LINE_MAP_MAX_COLUMN_NUMBER): Increase size to be appropriate for
64-bit location_t.
(LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES): Likewise.
(LINE_MAP_MAX_LOCATION_WITH_COLS): Likewise.
(LINE_MAP_MAX_LOCATION): Likewise.
(MAX_LOCATION_T): Likewise.
(line_map_suggested_range_bits): Likewise.
(struct line_map): Adjust comment about the struct size.
(struct line_map_macro): Likewise.
(struct line_map_ordinary): Likewise. Rearrange fields to optimize
padding.
gcc/testsuite/ChangeLog:
* g++.dg/diagnostic/pr77949.C: Adapt the test for 64-bit location_t,
when the previously expected failure doesn't actually happen.
* g++.dg/modules/loc-prune-4.C: Adjust the expected output for the
64-bit location_t case.
* gcc.dg/plugin/expensive_selftests_plugin.cc: Don't try to test
the maximum supported column number in 64-bit location_t mode.
* gcc.dg/plugin/location_overflow_plugin.cc: Adjust the base_location
so it can effectively test 64-bit location_t.
gcc/ChangeLog:
* gimple.h (struct gphi): Update word marking comments to reflect
the new size of location_t.
(struct gimple): Likewise. Add a comment about padding.
* common.opt: Mark -flarge-source-files as Ignored.
* common.opt.urls: Regenerate.
* doc/invoke.texi: Remove -flarge-source-files.
* toplev.cc (process_options): Remove support for
-flarge-source-files.
|
|
As discussed earlier, we currently clear padding bits even when we
don't have to and that causes pessimization of emitted code,
e.g. for
union U { int a; long b[64]; };
void bar (union U *);
void
foo (void)
{
union U u = { 0 };
bar (&u);
}
we need to clear just u.a, not the whole union, but on the other side
in cases where the standard requires padding bits to be zeroed, like for
C23 {} initializers of aggregates with padding bits, or for C++11 zero
initialization we don't do that.
This patch
a) moves some of the stuff into complete_ctor_at_level_p (but not
all the *p_complete = 0; case, for that it would need to change
so that it passes around the ctor rather than just its type) and
changes the handling of unions
b) introduces a new option, so that users can either get the new
behavior (only what is guaranteed by the standards, the default),
or previous behavior (union padding zero initialization, no such
guarantees in structures) or also a guarantee in structures
c) introduces a new CONSTRUCTOR flag which says that the padding bits
(if any) should be zero initialized (and sets it for now in the C
FE for C23 {} initializers).
Am not sure the CONSTRUCTOR_ZERO_PADDING_BITS flag is really needed
for C23, if there is just empty initializer, I think we already mark
it as incomplete if there are any missing initializers. Maybe with
some designated initializer games, say
void foo () {
struct S { char a; long long b; };
struct T { struct S c; } t = { .c = {}, .c.a = 1, .c.b = 2 };
...
}
Is this supposed to initialize padding bits in C23 and then the .c.a = 1
and .c.b = 2 stores preserve those padding bits, so is that supposed
to be different from struct T t2 = { .c = { 1, 2 } };
? What about just struct T t3 = { .c.a = 1, .c.b = 2 }; ?
And I haven't touched the C++ FE for the flag, because I'm afraid I'm lost
on where exactly is zero-initialization done (vs. other types of
initialization) and where is e.g. zero-initialization of a temporary then
(member-wise) copied.
Say
struct S { char a; long long b; };
struct T { constexpr T (int a, int b) : c () { c.a = a; c.b = b; } S c; };
void bar (T *);
void
foo ()
{
T t (1, 2);
bar (&t);
}
Is the c () value-initialization of t.c followed by c.a and c.b updates
which preserve the zero initialized padding bits? Or is there some
copy construction involved which does member-wise copying and makes the
padding bits undefined?
Looking at (older) clang++ with -O2, it initializes also the padding bits
when c () is used and doesn't with c {}.
For GCC, note that there is that optimization from Alex to zero padding bits
for optimization purposes for small aggregates, so either one needs to look
at -O0 -fdump-tree-gimple dumps, or use larger structures which aren't
optimized that way.
2024-11-28 Jakub Jelinek <jakub@redhat.com>
PR c++/116416
gcc/
* flag-types.h (enum zero_init_padding_bits_kind): New type.
* tree.h (CONSTRUCTOR_ZERO_PADDING_BITS): Define.
* common.opt (fzero-init-padding-bits=): New option.
* expr.cc (categorize_ctor_elements_1): Handle
CONSTRUCTOR_ZERO_PADDING_BITS or
flag_zero_init_padding_bits == ZERO_INIT_PADDING_BITS_ALL. Fix
up *p_complete = -1; setting for unions.
(complete_ctor_at_level_p): Handle unions differently for
flag_zero_init_padding_bits == ZERO_INIT_PADDING_BITS_STANDARD.
* gimple-fold.cc (type_has_padding_at_level_p): Fix up UNION_TYPE
handling, return also true for UNION_TYPE with no FIELD_DECLs
and non-zero size, handle QUAL_UNION_TYPE like UNION_TYPE.
* doc/invoke.texi (-fzero-init-padding-bits=@var{value}): Document.
gcc/c/
* c-parser.cc (c_parser_braced_init): Set CONSTRUCTOR_ZERO_PADDING_BITS
for flag_isoc23 empty initializers.
* c-typeck.cc (constructor_zero_padding_bits): New variable.
(struct constructor_stack): Add zero_padding_bits member.
(really_start_incremental_init): Save and clear
constructor_zero_padding_bits.
(push_init_level): Save constructor_zero_padding_bits. Or into it
CONSTRUCTOR_ZERO_PADDING_BITS from previous value if implicit.
(pop_init_level): Set CONSTRUCTOR_ZERO_PADDING_BITS if
constructor_zero_padding_bits and restore
constructor_zero_padding_bits.
gcc/testsuite/
* gcc.dg/plugin/infoleak-1.c (test_union_2b, test_union_4b): Expect
diagnostics.
* gcc.dg/c23-empty-init-5.c: New test.
* gcc.dg/gnu11-empty-init-1.c: New test.
* gcc.dg/gnu11-empty-init-2.c: New test.
* gcc.dg/gnu11-empty-init-3.c: New test.
* gcc.dg/gnu11-empty-init-4.c: New test.
|
|
In r12-6650-g5c69acb32329d4 we updated our sources from .c to .cc
since for some time GCC has been implemented in C++, not C.
GCC plugins are also implemented in C++, not C, but the plugins
in our testsuite still have .c extensions.
Rename the plugin implementation files in the testsuite from .c to .cc,
for consistency with GCC's implementation files (as opposed to .C,
which is used in C++ parts of the testsuite).
Don't rename the files that the plugins are tested *on*.
gcc/testsuite/ChangeLog:
* g++.dg/plugin/plugin.exp (plugin_test_list): Update for renaming
of all plugin implementation files from .c to .cc.
* g++.dg/plugin/attribute_plugin.c: Rename to...
* g++.dg/plugin/attribute_plugin.cc: ...this.
* g++.dg/plugin/comment_plugin.c: Rename to...
* g++.dg/plugin/comment_plugin.cc: ...this.
* g++.dg/plugin/decl_plugin.c: Rename to...
* g++.dg/plugin/decl_plugin.cc: ...this.
* g++.dg/plugin/def_plugin.c: Rename to...
* g++.dg/plugin/def_plugin.cc: ...this.
* g++.dg/plugin/dumb_plugin.c: Rename to...
* g++.dg/plugin/dumb_plugin.cc: ...this.
* g++.dg/plugin/header_plugin.c: Rename to...
* g++.dg/plugin/header_plugin.cc: ...this.
* g++.dg/plugin/pragma_plugin.c: Rename to...
* g++.dg/plugin/pragma_plugin.cc: ...this.
* g++.dg/plugin/selfassign.c: Rename to...
* g++.dg/plugin/selfassign.cc: ...this.
* g++.dg/plugin/show_template_tree_color_plugin.c: Rename to...
* g++.dg/plugin/show_template_tree_color_plugin.cc: ...this.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Update for renaming
of all plugin implementation files from .c to .cc.
* gcc.dg/plugin/analyzer_cpython_plugin.c: Rename to...
* gcc.dg/plugin/analyzer_cpython_plugin.cc: ...this.
* gcc.dg/plugin/analyzer_gil_plugin.c: Rename to...
* gcc.dg/plugin/analyzer_gil_plugin.cc: ...this.
* gcc.dg/plugin/analyzer_kernel_plugin.c: Rename to...
* gcc.dg/plugin/analyzer_kernel_plugin.cc: ...this.
* gcc.dg/plugin/analyzer_known_fns_plugin.c: Rename to...
* gcc.dg/plugin/analyzer_known_fns_plugin.cc: ...this.
* gcc.dg/plugin/crash_test_plugin.c: Rename to...
* gcc.dg/plugin/crash_test_plugin.cc: ...this.
* gcc.dg/plugin/diagnostic_group_plugin.c: Rename to...
* gcc.dg/plugin/diagnostic_group_plugin.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_show_trees.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_show_trees.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_inlining.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_inlining.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_metadata.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_metadata.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_nesting.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_nesting.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_paths.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_paths.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_string_literals.c: Rename
* gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc: ..to
this.
* gcc.dg/plugin/diagnostic_plugin_test_text_art.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_text_art.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c:
Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc:
...this.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.cc: ...this.
* gcc.dg/plugin/dump_plugin.c: Rename to...
* gcc.dg/plugin/dump_plugin.cc: ...this.
* gcc.dg/plugin/expensive_selftests_plugin.c: Rename to...
* gcc.dg/plugin/expensive_selftests_plugin.cc: ...this.
* gcc.dg/plugin/finish_unit_plugin.c: Rename to...
* gcc.dg/plugin/finish_unit_plugin.cc: ...this.
* gcc.dg/plugin/ggcplug.c: Rename to...
* gcc.dg/plugin/ggcplug.cc: ...this.
* gcc.dg/plugin/location_overflow_plugin.c: Rename to...
* gcc.dg/plugin/location_overflow_plugin.cc: ...this.
* gcc.dg/plugin/must_tail_call_plugin.c: Rename to...
* gcc.dg/plugin/must_tail_call_plugin.cc: ...this.
* gcc.dg/plugin/one_time_plugin.c: Rename to...
* gcc.dg/plugin/one_time_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-01_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-01_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-02_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-02_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-03_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-03_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-04_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-04_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-05_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-05_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-06_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-06_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-07_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-07_plugin.cc: ...this.
* gcc.dg/plugin/selfassign.c: Rename to...
* gcc.dg/plugin/selfassign.cc: ...this.
* gcc.dg/plugin/start_unit_plugin.c: Rename to...
* gcc.dg/plugin/start_unit_plugin.cc: ...this.
* gcc.dg/plugin/wide-int_plugin.c: Rename to...
* gcc.dg/plugin/wide-int_plugin.cc: ...this.
* obj-c++.dg/plugin/plugin.exp: Update for renaming of plugin
implementation file from .c to .cc.
* objc.dg/plugin/plugin.exp: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Previously the diagnostic subsystem supported a one-deep
hierarchy via auto_diagnostic_group, for associating
notes with the warning/error they annotate; this only
affects SARIF output, not text output.
This patch adds support to the diagnostics subsystem for
capturing arbitrarily deep nesting structure within
diagnostic messages.
This patch:
* adds the ability to express nesting internally when
building diagnostics
* captures the nesting in SARIF output in the form documented
in SG15's P3358R0 ("SARIF for Structured Diagnostics") via
a "nestingLevel" property
* adds a new experimental mode to text output to see the
hierarchy, via:
-fdiagnostics-set-output=text:experimental-nesting=yes
* adds test coverage via a plugin, which with the above
option emits:
• note: child 0
• note: grandchild 0 0
• note: grandchild 0 1
• note: grandchild 0 2
• note: child 1
• note: grandchild 1 0
• note: grandchild 1 1
• note: grandchild 1 2
• note: child 2
• note: grandchild 2 0
• note: grandchild 2 1
• note: grandchild 2 2
using '*' rather than '•' if the text_art::theme is ascii-only.
My hope is to eventually:
(a) use this to improve C++'s template diagnostics
(b) remove the "experimental" caveat from the the text output mode
but this patch doesn't touch the C++ frontend, leaving both of these
to followup work.
gcc/c-family/ChangeLog:
PR other/116253
* c-opts.cc (c_diagnostic_text_finalizer): Use
text_output.build_indent_prefix for prefix to
diagnostic_show_locus.
gcc/ChangeLog:
PR other/116253
* diagnostic-core.h (class auto_diagnostic_nesting_level): New.
* diagnostic-format-sarif.cc (class sarif_builder): Update leading
comment re nesting of diagnostics.
(sarif_result::on_nested_diagnostic): Add nestingLevel property.
* diagnostic-format-text.cc (on_report_diagnostic): If we're
showing nested diagnostics, then print changes of location on a
new line, indented, and update m_last_location.
(diagnostic_text_output_format::build_prefix): If m_show_nesting,
then potentially add indentation and a bullet point.
(get_bullet_point_unichar): New.
(use_unicode_p): New.
(diagnostic_text_output_format::build_indent_prefix): New.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Initialize m_show_nesting and m_show_nesting_levels.
(diagnostic_text_output_format::build_indent_prefix): New decl.
(diagnostic_text_output_format::show_nesting_p): New accessor
(diagnostic_text_output_format::show_locations_in_nesting_p):
Likewise.
(diagnostic_text_output_format::set_show_nesting): New.
(diagnostic_text_output_format::set_show_locations_in_nesting):
New.
(diagnostic_text_output_format::set_show_nesting_levels): New.
(diagnostic_text_output_format::m_show_nesting): New field.
(diagnostic_text_output_format::m_show_locations_in_nesting): New
field.
(diagnostic_text_output_format::m_show_nesting_levels): New field.
* diagnostic-global-context.cc
(auto_diagnostic_nesting_level::auto_diagnostic_nesting_level):
New.
(auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level):
New.
* diagnostic-show-locus.cc (layout_printer::print): Temporarily
set DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE.
* diagnostic.cc (diagnostic_context::initialize): Update for
renaming of m_nesting_depth to m_group_nesting_depth and
initialize m_diagnostic_nesting_level.
(diagnostic_context::finish): Update for renaming of
m_nesting_depth to m_group_nesting_depth.
(diagnostic_context::report_diagnostic): Likewise.
(diagnostic_context::begin_group): Likewise.
(diagnostic_context::end_group): Likewise.
(diagnostic_context::push_nesting_level): New.
(diagnostic_context::pop_nesting_level): New.
(diagnostic_context::set_diagnostic_buffer): Update for renaming
of m_nesting_depth to m_group_nesting_depth. Assert that we don't
have nested diagnostics.
* diagnostic.h (diagnostic_context::push_nesting_level): New decl.
(diagnostic_context::pop_nesting_level): New decl.
(diagnostic_context::get_diagnostic_nesting_level): New accessor.
(diagnostic_context::build_indent_prefix): New decl.
(diagnostic_context::m_diagnostic_groups): Rename m_nesting_depth
to m_group_nesting_depth and add field m_diagnostic_nesting_level.
* doc/invoke.texi (fdiagnostics-add-output): Add note about
"experimental" schemes, keys, and values. Add keys
"experimental-nesting", "experimental-nesting-show-locations",
and "experimental-nesting-show-levels" to text scheme.
* opts-diagnostic.cc (text_scheme_handler::make_sink): Add keys
"experimental-nesting", "experimental-nesting-show-locations",
and "experimental-nesting-show-levels".
gcc/testsuite/ChangeLog:
PR other/116253
* gcc.dg/plugin/diagnostic-test-nesting-sarif.c: New test.
* gcc.dg/plugin/diagnostic-test-nesting-sarif.py: New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c:
New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c:
New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented.c: New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-plain.c: New test.
* gcc.dg/plugin/diagnostic_plugin_test_nesting.c: New test plugin.
* gcc.dg/plugin/plugin.exp: Add the above.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This patch generalizes diagnostic_context so that rather than having
a single output format, it has a vector of zero or more.
It adds new two options:
-fdiagnostics-add-output=DIAGNOSTICS-OUTPUT-SPEC
-fdiagnostics-set-output=DIAGNOSTICS-OUTPUT-SPEC
which both take a new configuration syntax of the form SCHEME ("text" or
"sarif"), optionally followed by ":" and one or more KEY=VALUE pairs,
in this form:
<SCHEME>
<SCHEME>:<KEY>=<VALUE>
<SCHEME>:<KEY>=<VALUE>,<KEY2>=<VALUE2>
...etc
where each SCHEME supports some set of keys. For example, it's now
possible to use:
-fdiagnostics-add-output=sarif:version=2.1,file=foo.2.1.sarif \
-fdiagnostics-add-output=sarif:version=2.2-prerelease,file=foo.2.2.sarif
to add a pair of outputs, each writing to a different file, using
versions 2.1 and 2.2 of the SARIF standard respectively, whilst also
emitting the classic text form of the diagnostics to stderr.
I hope the new syntax gives us room to potentially add new kinds of
output sink in the future (e.g. RPC notifications), and to add new
key/value pairs as needed by the different sinks.
Implementation-wise, the diagnostic_context's m_printer which previously
was used directly by the single output format now becomes a "reference
printer", created by the client (such as the frontend), with defaults
modified by command-line options. Each of the multiple output sinks has
its own pretty_printer instance, created by cloning the context's
reference printer.
gcc/ChangeLog:
PR other/116613
* Makefile.in (OBJS-libcommon-target): Add opts-diagnostic.o.
* common.opt (fdiagnostics-add-output=): New.
(fdiagnostics-set-output=): New.
(diagnostics_output_format): Drop sarif-file-2.2-prerelease from
enum.
* common.opt.urls: Regenerate.
* diagnostic-buffer.h (diagnostic_buffer::~diagnostic_buffer): New.
(diagnostic_buffer::ensure_per_format_buffer): Rename to...
(diagnostic_buffer::ensure_per_format_buffers): ...this.
(diagnostic_buffer::m_per_format_buffer): Replace with...
(diagnostic_buffer::m_per_format_buffers): ...this, updating type.
* diagnostic-format-json.cc (json_output_format::update_printer):
New.
(json_output_format::follows_reference_printer_p): New.
(diagnostic_output_format_init_json): Drop redundant call to
set_path_format, as this is not a text output format.
* diagnostic-format-sarif.cc: Include "diagnostic-format-text.h".
(sarif_builder::set_printer): New.
(sarif_builder::sarif_builder): Add "printer" param and use it for
m_printer.
(sarif_builder::make_location_object::escape_nonascii_renderer::render):
Rather than using dc.m_printer, create a
diagnostic_text_output_format instance and use its printer.
(sarif_output_format::follows_reference_printer_p): New.
(sarif_output_format::update_printer): New.
(sarif_output_format::sarif_output_format): Pass in correct
printer to m_builder's ctor.
(diagnostic_output_format_init_sarif): Drop redundant call to
set_path_format, as this is not a text output format. Replace
calls to pp_show_color and set_token_printer with call to
update_printer. Drop redundant call to set_show_highlight_colors,
as this printer does not show colors.
(diagnostic_output_format_init_sarif_file): Split out file opening
into...
(diagnostic_output_format_open_sarif_file): ...this new function.
(make_sarif_sink): New.
(selftest::test_make_location_object): Provide a pp for the
builder.
* diagnostic-format-sarif.h
(diagnostic_output_format_open_sarif_file): New decl.
(make_sarif_sink): New decl.
* diagnostic-format-text.cc (diagnostic_text_output_format::dump):
Dump sm_follows_reference_printer.
(diagnostic_text_output_format::on_report_verbatim): New.
(diagnostic_text_output_format::follows_reference_printer_p): New.
(diagnostic_text_output_format::update_printer): New.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Add optional "follows_reference_printer" param.
(diagnostic_text_output_format::on_report_verbatim): New decl.
(diagnostic_text_output_format::after_diagnostic): Drop "final".
(diagnostic_text_output_format::follows_reference_printer_p): New
decl.
(class diagnostic_text_output_format): Convert private members to
protected.
(diagnostic_text_output_format::m_follows_reference_printer): New
field.
* diagnostic-format.h
(diagnostic_output_format::on_report_verbatim): New vfunc.
(diagnostic_output_format::follows_reference_printer_p): New vfunc.
(diagnostic_output_format::update_printer): New vfunc.
(diagnostic_output_format::get_printer): Use m_printer rather than
a printer from m_context.
(diagnostic_output_format::diagnostic_output_format): Initialize
m_printer by cloning the context's printer.
(diagnostic_output_format::m_printer): New field.
* diagnostic-global-context.cc (verbatim): Reimplement in terms of
global_dc->report_verbatim, moving existing implementation to
diagnostic_text_output_format::on_report_verbatim.
(fnotice): Support multiple output sinks by using a new
global_dc->supports_fnotice_on_stderr_p.
* diagnostic-output-file.h
(diagnostic_output_file::diagnostic_output_file): New default ctor.
(diagnostic_output_file::operator=): Implement move assignment.
* diagnostic-path.cc (selftest::test_interprocedural_path_1): Pass
false for new param of text_output's ctor.
* diagnostic-show-locus.cc
(selftest::test_layout_x_offset_display_utf8): Use reference
printer.
(selftest::test_layout_x_offset_display_tab): Likewise.
(selftest::test_one_liner_fixit_remove): Likewise.
* diagnostic.cc: Include "pretty-print-urlifier.h".
(diagnostic_set_caret_max_width): Update for global_dc's m_printer
becoming reference printer.
(diagnostic_context::initialize): Update for m_printer becoming
m_reference_printer. Use ::make_unique to create it. Update for
m_output_format becoming m_output_sinks.
(diagnostic_context::color_init): Update the reference printer,
then update the printers for any output sinks that follow it.
(diagnostic_context::urls_init): Likewise.
(diagnostic_context::finish): Update comment. Update for
m_output_format becoming m_output_sinks. Update for m_printer
becoming m_reference_printer and use "delete" on it rather than
XDELETE.
(diagnostic_context::dump): Update for m_printer becoming
reference printer, and for multiple output sinks.
(diagnostic_context::set_output_format): Reimplement for
supporting multiple output sinks.
(diagnostic_context::get_output_format): Likewise.
(diagnostic_context::add_sink): New.
(diagnostic_context::supports_fnotice_on_stderr_p): New.
(diagnostic_context::set_pretty_printer): New.
(diagnostic_context::refresh_output_sinks): New.
(diagnostic_context::set_format_decoder): New.
(diagnostic_context::set_show_highlight_colors): New.
(diagnostic_context::set_prefixing_rule): New.
(diagnostic_context::report_diagnostic): Update to support
multiple output sinks.
(diagnostic_context::report_verbatim): New.
(diagnostic_context::emit_diagram): Update to support multiple
output sinks.
(diagnostic_context::error_recursion): Update to use
m_reference_printer.
(fancy_abort): Likewise.
(diagnostic_context::end_group): Update to support multiple
output sinks.
(diagnostic_output_format::dump): Implement.
(diagnostic_output_format::on_report_verbatim): Likewise.
(diagnostic_output_format_init): Drop
DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE_2_2_PRERELEASE.
(diagnostic_context::set_diagnostic_buffer): Reimplement to
support multiple output sinks.
(diagnostic_context::clear_diagnostic_buffer): Likewise.
(diagnostic_context::flush_diagnostic_buffer): Likewise.
(diagnostic_buffer::diagnostic_buffer): Initialize
m_per_format_buffers.
(diagnostic_buffer::~diagnostic_buffer): New dtor.
(diagnostic_buffer::dump): Reimplement to support multiple output
sinks.
(diagnostic_buffer::empty_p): Likewise.
(diagnostic_buffer::move_to): Likewise.
(diagnostic_buffer::ensure_per_format_buffer): Likewise, renaming
to...
(diagnostic_buffer::ensure_per_format_buffers): ...this.
* diagnostic.h
(DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE_2_2_PRERELEASE): Delete.
(class diagnostic_context): Add friend class diagnostic_buffer.
(diagnostic_context::set_pretty_printer): New decl.
(diagnostic_context::refresh_output_sinks): New decl.
(diagnostic_context::report_verbatim): New decl.
(diagnostic_context::get_output_format): Drop.
(diagnostic_context::set_show_highlight_colors): Drop body.
(diagnostic_context::set_format_decoder): New decl.
(diagnostic_context::set_prefixing_rule): New decl.
(diagnostic_context::clone_printer): Reimplement.
(diagnostic_context::get_reference_printer): New accessor.
(diagnostic_context::add_sink): New decl.
(diagnostic_context::supports_fnotice_on_stderr_p): New decl.
(diagnostic_context::m_printer): Replace with...
(diagnostic_context::m_reference_printer): ...this, and make
private.
(diagnostic_context::m_output_format): Replace with...
(diagnostic_context::m_output_sinks): ...this.
(diagnostic_format_decoder): Delete.
(diagnostic_prefixing_rule): Delete.
(diagnostic_ready_p): Delete.
* doc/invoke.texi: Document -fdiagnostics-add-output= and
-fdiagnostics-set-output=.
* gcc.cc: Include "opts-diagnostic.h".
(driver_handle_option): Handle cases OPT_fdiagnostics_add_output_
and OPT_fdiagnostics_set_output_.
* opts-diagnostic.cc: New file.
* opts-diagnostic.h (handle_OPT_fdiagnostics_add_output_): New decl.
(handle_OPT_fdiagnostics_set_output_): New decl.
* opts-global.cc (init_options_once): Update for global_dc's
m_printer becoming reference printer. Call
global_dc->refresh_output_sinks.
* opts.cc (common_handle_option): Replace use of
diagnostic_prefixing_rule with dc->set_prefixing_rule. Handle
cases OPT_fdiagnostics_add_output_ and
OPT_fdiagnostics_set_output_. Update for m_printer becoming
reference printer.
* selftest-diagnostic.cc
(selftest::test_diagnostic_context::test_diagnostic_context):
Update for m_printer becoming reference printer.
(test_diagnostic_context::test_show_locus): Likewise.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest::opts_diagnostic_cc_tests.
* selftest.h (selftest::opts_diagnostic_cc_tests): New decl.
* simple-diagnostic-path.cc
(selftest::simple_diagnostic_path_cc_tests): Use reference
printer.
* toplev.cc (announce_function): Update for global_dc's m_printer
becoming reference printer.
(toplev::main): Likewise.
* tree-diagnostic.cc (tree_diagnostics_defaults): Replace use of
diagnostic_format_decoder with context->set_format_decoder.
* tree-diagnostic.h
(tree_dump_pretty_printer::tree_dump_pretty_printer): Update for
global_dc's m_printer becoming reference printer.
* tree.cc (escaped_string::escape): Likewise.
(selftest::test_escaped_strings): Likewise.
gcc/ada/ChangeLog:
PR other/116613
* gcc-interface/misc.cc (internal_error_function): Update for
m_printer becoming reference printer.
gcc/analyzer/ChangeLog:
PR other/116613
* analyzer-language.cc (on_finish_translation_unit): Update for
m_printer becoming reference printer.
* engine.cc (run_checkers): Likewise.
* program-point.cc (function_point::print_source_line): Likewise.
gcc/c-family/ChangeLog:
PR other/116613
* c-format.cc (selftest::test_type_mismatch_range_labels): Update
for m_printer becoming reference printer.
(selftest::test_type_mismatch_range_labels): Likewise.
gcc/c/ChangeLog:
PR other/116613
* c-objc-common.cc: Include "make-unique.h".
(c_initialize_diagnostics): Use unique_ptr for pretty_printer.
Use context->set_format_decoder.
gcc/cp/ChangeLog:
PR other/116613
* error.cc (cxx_initialize_diagnostics): Use unique_ptr for
pretty_printer. Use context->set_format_decoder.
* module.cc (noisy_p): Update for global_dc's m_printer becoming
reference printer.
gcc/d/ChangeLog:
PR other/116613
* d-diagnostic.cc (d_diagnostic_report_diagnostic): Update for
m_printer becoming reference printer.
gcc/fortran/ChangeLog:
PR other/116613
* error.cc (gfc_diagnostic_build_kind_prefix): Update for
global_dc's m_printer becoming reference printer.
(gfc_diagnostics_init): Replace usage of diagnostic_format_decoder
with global_dc->set_format_decoder.
gcc/jit/ChangeLog:
PR other/116613
* dummy-frontend.cc: Include "make-unique.h".
(class jit_diagnostic_listener): New.
(jit_begin_diagnostic): Update comment.
(jit_end_diagnostic): Drop call to add_diagnostic.
(jit_langhook_init): Set the output format to a new
jit_diagnostic_listener.
* jit-playback.cc (playback::context::add_diagnostic): Add "text"
param and use that rather than trying to get the text from a
pretty_printer.
* jit-playback.h (playback::context::add_diagnostic): Add "text"
param.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/analyzer_cpython_plugin.c (dump_refcnt_info):
Update for global_dc's m_printer becoming reference printer.
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2.2.c: Replace usage
of -fdiagnostics-format=sarif-file-2.2-prerelease with
-fdiagnostics-set-output=sarif:version=2.2-prerelease.
* gcc.dg/plugin/diagnostic_plugin_test_paths.c: Update for
global_dc's m_printer becoming reference printer.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Update for
changes to output formats.
* gcc.dg/plugin/expensive_selftests_plugin.c: Update for
global_dc's m_printer becoming reference printer.
* gcc.dg/sarif-output/add-output-sarif-defaults.c: New test.
* gcc.dg/sarif-output/bad-binary-op.c: New test.
* gcc.dg/sarif-output/bad-binary-op.py: New support script.
* gcc.dg/sarif-output/multiple-outputs.c: New test.
* gcc.dg/sarif-output/multiple-outputs.py: New support script.
* lib/scansarif.exp (verify-sarif-file): Add an optional second
argument specifying the expected filename of the .sarif file.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Previously, various places in the analyzer generated message strings
by cloning the diagnostic_context's pretty_printer, printing to that
pretty_printer's buffer, and then returning a copy of the buffer
contents.
This implicit use of a particular pretty printer doesn't work well for
the "multiple diagnostic output formats" case (PR other/116613), such as
differences in colorization, or in how phase 3 of formatting works.
Hence as enabling work towards that, the following patch reworks the
various functions returning a label_text string in favor of functions
that print to a specific pretty_printer, such as diagnotic_event's
"get_desc" vfunc, which becomes "print_desc". This makes the particular
pretty_printer in use explicit in each case.
Previously, the various pending_diagnostic::describe_* vfuncs returned a
label_text, with the return of an empty string signifying that no
description could be generated. With this patch, these vfuncs gain a
"pretty_printer &" param and a bool return value and now either print to
the pretty_printer and return true, or return false to signify the
"no description available" case.
No functional change intended.
gcc/analyzer/ChangeLog:
PR other/116613
* bounds-checking.cc
(concrete_buffer_overflow::describe_final_event): Convert return
type from label_text to bool. Add "pp" param and either print to
it and return true, or return false.
(concrete_buffer_overflow::describe_final_event_as_bytes): Convert
to print to a pp rather than returning a label_text.
(concrete_buffer_overflow::describe_final_event_as_bits):
Likewise.
(class concrete_buffer_over_read): Analogous changes to above.
(class concrete_buffer_underwrite): Likewise.
(class concrete_buffer_under_read): Likewise.
(class symbolic_buffer_overflow): Likewise.
(class symbolic_buffer_over_read): Likewise.
* call-details.cc (class overlapping_buffers): Likewise.
* call-info.cc (call_info::print): Reimplement.
(class call_info::add_events_to_path::call_event): Convert
"get_desc" vfunc to "print_desc", dropping return type, adding
"pp" param, and printing to it.
(class succeed_or_fail_call_info): Likewise.
* call-info.h (class call_info): Likewise.
(class succeed_or_fail_call_info): Likewise.
* checker-event.cc (checker_event::dump): Reimplement.
(checker_event::prepare_for_emission): Update for change from
get_desc to print_desc.
(debug_event::get_desc): Convert to...
(debug_event::print_desc): ...this.
(precanned_custom_event::get_desc): Convert to...
(precanned_custom_event::print_desc): ...this.
(statement_event::get_desc): Convert to...
(statement_event::print_desc): ...this.
(region_creation_event_memory_space::get_desc): Convert to...
(region_creation_event_memory_space::print_desc): ...this.
(region_creation_event_capacity::get_desc): Convert to...
(region_creation_event_capacity::print_desc): ...this.
(region_creation_event_allocation_size::get_desc): Convert to...
(region_creation_event_allocation_size::print_desc): ...this.
(region_creation_event_debug::get_desc): Convert to...
(region_creation_event_debug::print_desc): ...this.
(function_entry_event::get_desc): Convert to...
(function_entry_event::print_desc): ...this.
(state_change_event::get_desc): Convert to...
(state_change_event::print_desc): ...this.
(state_change_event::get_meaning): Update for change to
pending_diagnostic::get_meaning_for_state_change.
(superedge_event::should_filter_p): Convert from usage of get_desc
to print_desc.
(start_cfg_edge_event::get_desc): Convert to...
(start_cfg_edge_event::print_desc): ...this.
(call_event::get_desc): Convert to...
(call_event::print_desc): ...this.
(return_event::get_desc): Convert to...
(return_event::print_desc): ...this.
(start_consolidated_cfg_edges_event::get_desc): Convert to...
(start_consolidated_cfg_edges_event::print_desc): ...this.
(inlined_call_event::get_desc): Convert to...
(inlined_call_event::print_desc): ...this.
(setjmp_event::get_desc): Convert to...
(setjmp_event::print_desc): ...this.
(rewind_from_longjmp_event::get_desc): Convert to...
(rewind_from_longjmp_event::print_desc): ...this.
(rewind_to_setjmp_event::get_desc): Convert to...
(rewind_to_setjmp_event::print_desc): ...this.
(warning_event::get_desc): Convert to...
(warning_event::print_desc): ...this.
* checker-event.h: Convert the various "get_desc" vfunc decls to
"print_desc".
* checker-path.cc (checker_path::dump): Convert to usage of
checker_event::print_desc.
(checker_path::debug): Convert to debug form of
checker_event::get_desc.
* diagnostic-manager.cc
(diagnostic_manager::prune_interproc_events): Likewise.
(diagnostic_manager::prune_system_headers): Likewise.
* engine.cc (call_summary_edge_info::get_desc): Convert to...
(call_summary_edge_info::print_desc): ...this.
(stale_jmp_buf::describe_final_event): Update for change to
this vfunc.
(tainted_args_function_custom_event::get_desc): Convert to...
(tainted_args_function_custom_event::print_desc): ...this.
(tainted_args_field_custom_event::get_desc): Convert to...
(tainted_args_field_custom_event::print_desc): ...this.
(tainted_args_callback_custom_event::get_desc): Convert to...
(tainted_args_callback_custom_event::print_desc): ...this.
(jump_through_null::describe_final_event): Update for change to
this vfunc.
* infinite-loop.cc (perpetual_start_cfg_edge_event::get_desc):
Convert to...
(perpetual_start_cfg_edge_event::print_desc): ...this.
(looping_back_event::get_desc): Convert to...
(looping_back_event::print_desc): ...this.
(looping_back_event::describe_final_event): Update for change to
this vfunc.
* infinite-recursion.cc (class infinite_recursion_diagnostic):
Update for changes to pending_diagnostic.
* kf.cc (class putenv_of_auto_var): Likewise.
(kf_realloc::impl_call_post): Update for changes to call_info.
(kf_strchr::impl_call_post): Likewise.
(kf_strncpy::impl_call_post): Likewise.
(kf_strstr::impl_call_post): Likewise.
(class kf_strtok::undefined_behavior): Update for changes to
pending_diagnostic.
(class strtok_call_info): Update for changes to call_info.
* pending-diagnostic.cc (evdesc::event_desc::formatted_print):
Delete.
* pending-diagnostic.h (struct event_desc): Delete.
(struct state_change): Drop event_desc base class.
(struct call_with_state): Likewise.
(struct return_of_state): Likewise.
(struct final_event): Likewise.
(pending_event::describe_state_change): Convert return
type from label_text to bool. Add "pp" param and either print to
it and return true, or return false. Do the latter for the base
class implementation.
(pending_event::describe_call_with_state): Likewise.
(pending_event::describe_return_of_state): Likewise.
(pending_event::describe_final_event): Likewise.
* region-model.cc
(poisoned_value_diagnostic::describe_final_event): Update for
change to this vfunc.
(shift_count_negative_diagnostic::describe_final_event): Likewise.
(shift_count_overflow_diagnostic::describe_final_event): Likewise.
(ptrdiff_region_creation_event::get_desc): Convert to...
(ptrdiff_region_creation_event::print_desc): ...this.
(undefined_ptrdiff_diagnostic::describe_final_event): Update for
change to this vfunc.
(write_to_const_diagnostic::describe_final_event): Likewise.
(write_to_string_literal_diagnostic::describe_final_event):
Likewise.
(dubious_allocation_size::describe_final_event): Likewise.
(null_terminator_check_event::get_desc): Convert to...
(null_terminator_check_event::print_desc): ...this.
(float_as_size_arg::describe_final_event): Update for change to
this vfunc.
(exposure_through_uninit_copy::describe_final_event): Likewise.
* sm-fd.cc: Include "diagnostic-core.h". Update throughout for
changes to pending_diagnostic vfuncs.
* sm-file.cc: Likewise.
* sm-malloc.cc: Likewise.
* sm-sensitive.cc: Likewise.
* sm-signal.cc: Likewise.
* sm-taint.cc: Likewise.
* varargs.cc: Likewise.
gcc/ChangeLog:
PR other/116613
* diagnostic-format-json.cc (make_json_for_path): Add "ref_pp"
param and use when obtaining event descriptions.
(json_output_format::on_report_diagnostic): Pass this format's
printer as the above.
* diagnostic-format-sarif.cc
(sarif_builder::make_location_object): Clone this format's printer
and use it to obtain the text of the message.
* diagnostic-path.cc: Include "pretty-print-markup.h".
(diagnostic_event::get_desc): New.
(path_label::get_text): Update for changes to diagnostic_event.
(event_range::print): Likewise.
(class element_event_desc): New.
(diagnostic_text_output_format::print_path): Update for changes to
diagnostic_event.
* diagnostic-path.h (diagnostic_event::get_desc): Replace with...
(diagnostic_event::print_desc): ...this.
(diagnostic_event::get_desc): Add this back for debugging, without
the bool param.
* pretty-print.cc (pp_printf_n): New.
* pretty-print.h (pp_printf_n): New decl.
* selftest-diagnostic-path.h (test_diagnostic_event::get_desc):
Convert to...
(test_diagnostic_event::print_desc): ...this.
* simple-diagnostic-path.cc (simple_diagnostic_event::print_desc):
New.
(selftest::test_intraprocedural_path): Use debug form of get_desc.
* simple-diagnostic-path.h (simple_diagnostic_event::get_desc):
Convert to...
(simple_diagnostic_event::print_desc): ...this, moving
implementation to test_diagnostic_event.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/analyzer_cpython_plugin.c: Convert call outcomes
from "get_desc" to print_desc".
* gcc.dg/plugin/analyzer_gil_plugin.c: Update for changes to
pending_diagnostic vfuncs.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
My forthcoming patches for PR other/116613 make much more use of
cloning of pretty_printers than before, so it makes sense as a
preliminary patch for the result of pretty_printer::clone to be a
std::unique_ptr, rather than add more manual uses of "delete".
On doing so, I noticed various other places where naked new/delete is
used for run-time configuration of diagnostics:
* the output format (text vs SARIF)
* client data hooks
* the option manager
* the URLifier
Hence this patch also makes use of std::unique_ptr and ::make_unique for
managing such client policy classes, and also for diagnostic_buffer's
per-format implementations.
Unfortunately we can't directly include <memory> in our internal headers
but instead any of our TUs that make use of std::unique_ptr must #define
INCLUDE_MEMORY before including system.h.
Hence the bulk of this patch is taken up with adding a define of
INCLUDE_MEMORY to hundreds of source files: everything that includes
diagnostic.h or pretty-print.h (and thus anything transitively such as
includers of lto-wrapper.h, c-tree.h, cp-tree.h and rtl-ssa.h).
Thanks to Gaius Mulley for the parts of the patch that regenerated the
m2 files.
gcc/ada/ChangeLog:
PR other/116613
* gcc-interface/misc.cc: Add #define INCLUDE_MEMORY
* gcc-interface/trans.cc: Likewise.
* gcc-interface/utils.cc: Likewise.
gcc/analyzer/ChangeLog:
PR other/116613
* analyzer-logging.cc: Add #define INCLUDE_MEMORY
(logger::logger): Update for m_pp becoming a unique_ptr.
(logger::~logger): Likewise.
(logger::log_va_partial): Likewise.
(logger::end_log_line): Likewise.
* analyzer-logging.h (logger::get_printer): Likewise.
(logger::m_pp): Convert to a unique_ptr.
* analyzer.cc (make_label_text): Use
diagnostic_context::clone_printer and use unique_ptr.
(make_label_text_n): Likewise.
* bar-chart.cc: Add #define INCLUDE_MEMORY
* pending-diagnostic.cc (evdesc::event_desc::formatted_print):
Use diagnostic_context::clone_printer and use unique_ptr.
* sm-malloc.cc (sufficiently_similar_p): Likewise.
* supergraph.cc (supergraph::dump_dot_to_file): Likewise.
gcc/c-family/ChangeLog:
PR other/116613
* c-ada-spec.cc: Add #define INCLUDE_MEMORY.
* c-attribs.cc: Likewise.
* c-common.cc: Likewise.
* c-format.cc: Likewise.
* c-gimplify.cc: Likewise.
* c-indentation.cc: Likewise.
* c-opts.cc: Likewise.
* c-pch.cc: Likewise.
* c-pragma.cc: Likewise.
* c-pretty-print.cc: Likewise. Add #include "make-unique.h".
(c_pretty_printer::clone): Use std::unique_ptr and ::make_unique.
* c-pretty-print.h (c_pretty_printer::clone): Use std::unique_ptr.
* c-type-mismatch.cc: Add #define INCLUDE_MEMORY.
* c-warn.cc: Likewise.
gcc/c/ChangeLog:
PR other/116613
* c-aux-info.cc: Add #define INCLUDE_MEMORY.
* c-convert.cc: Likewise.
* c-errors.cc: Likewise.
* c-fold.cc: Likewise.
* c-lang.cc: Likewise.
* c-objc-common.cc: Likewise.
(pp_markup::element_quoted_type::print_type): Use unique_ptr.
* c-typeck.cc: Add #define INCLUDE_MEMORY.
* gimple-parser.cc: Likewise.
gcc/cp/ChangeLog:
PR other/116613
* call.cc: Add #define INCLUDE_MEMORY.
* class.cc: Likewise.
* constexpr.cc: Likewise.
* constraint.cc: Likewise.
* contracts.cc: Likewise.
* coroutines.cc: Likewise.
* cp-gimplify.cc: Likewise.
* cp-lang.cc: Likewise.
* cp-objcp-common.cc: Likewise.
* cp-ubsan.cc: Likewise.
* cvt.cc: Likewise.
* cxx-pretty-print.cc: Likewise. Add #include "cp-tree.h".
(cxx_pretty_printer::clone): Use std::unique_ptr and
::make_unique.
* cxx-pretty-print.h (cxx_pretty_printer::clone): Use
std::unique_ptr.
* decl2.cc: Add #define INCLUDE_MEMORY.
* dump.cc: Likewise.
* except.cc: Likewise.
* expr.cc: Likewise.
* friend.cc: Likewise.
* init.cc: Likewise.
* lambda.cc: Likewise.
* logic.cc: Likewise.
* mangle.cc: Likewise.
* method.cc: Likewise.
* optimize.cc: Likewise.
* pt.cc: Likewise.
* ptree.cc: Likewise.
* rtti.cc: Likewise.
* search.cc: Likewise.
* semantics.cc: Likewise.
* tree.cc: Likewise.
* typeck.cc: Likewise.
* typeck2.cc: Likewise.
* vtable-class-hierarchy.cc: Likewise.
gcc/d/ChangeLog:
PR other/116613
* d-attribs.cc: Add #define INCLUDE_MEMORY.
* d-builtins.cc: Likewise.
* d-codegen.cc: Likewise.
* d-convert.cc: Likewise.
* d-diagnostic.cc: Likewise.
* d-frontend.cc: Likewise.
* d-lang.cc: Likewise.
* d-longdouble.cc: Likewise.
* d-target.cc: Likewise.
* decl.cc: Likewise.
* expr.cc: Likewise.
* intrinsics.cc: Likewise.
* modules.cc: Likewise.
* toir.cc: Likewise.
* typeinfo.cc: Likewise.
* types.cc: Likewise.
gcc/fortran/ChangeLog:
PR other/116613
* arith.cc: Add #define INCLUDE_MEMORY.
* array.cc: Likewise.
* bbt.cc: Likewise.
* check.cc: Likewise.
* class.cc: Likewise.
* constructor.cc: Likewise.
* convert.cc: Likewise.
* cpp.cc: Likewise.
* data.cc: Likewise.
* decl.cc: Likewise.
* dependency.cc: Likewise.
* dump-parse-tree.cc: Likewise.
* error.cc: Likewise.
* expr.cc: Likewise.
* f95-lang.cc: Likewise.
* frontend-passes.cc: Likewise.
* interface.cc: Likewise.
* intrinsic.cc: Likewise.
* io.cc: Likewise.
* iresolve.cc: Likewise.
* match.cc: Likewise.
* matchexp.cc: Likewise.
* misc.cc: Likewise.
* module.cc: Likewise.
* openmp.cc: Likewise.
* options.cc: Likewise.
* parse.cc: Likewise.
* primary.cc: Likewise.
* resolve.cc: Likewise.
* scanner.cc: Likewise.
* simplify.cc: Likewise.
* st.cc: Likewise.
* symbol.cc: Likewise.
* target-memory.cc: Likewise.
* trans-array.cc: Likewise.
* trans-common.cc: Likewise.
* trans-const.cc: Likewise.
* trans-decl.cc: Likewise.
* trans-expr.cc: Likewise.
* trans-intrinsic.cc: Likewise.
* trans-io.cc: Likewise.
* trans-openmp.cc: Likewise.
* trans-stmt.cc: Likewise.
* trans-types.cc: Likewise.
* trans.cc: Likewise.
gcc/go/ChangeLog:
PR other/116613
* go-backend.cc: Add #define INCLUDE_MEMORY.
* go-lang.cc: Likewise.
gcc/jit/ChangeLog:
PR other/116613
* dummy-frontend.cc: Add #define INCLUDE_MEMORY.
* jit-playback.cc: Likewise.
* jit-recording.cc: Likewise.
gcc/lto/ChangeLog:
PR other/116613
* lto-common.cc: Add #define INCLUDE_MEMORY.
* lto-dump.cc: Likewise.
* lto-partition.cc: Likewise.
* lto-symtab.cc: Likewise.
* lto.cc: Likewise.
gcc/m2/ChangeLog:
PR other/116613
* gm2-gcc/gcc-consolidation.h: Add #define INCLUDE_MEMORY.
* gm2-gcc/m2configure.cc: Likewise.
* mc-boot/GASCII.cc: Regenerate.
* mc-boot/GASCII.h: Ditto.
* mc-boot/GArgs.cc: Ditto.
* mc-boot/GArgs.h: Ditto.
* mc-boot/GAssertion.cc: Ditto.
* mc-boot/GAssertion.h: Ditto.
* mc-boot/GBreak.cc: Ditto.
* mc-boot/GBreak.h: Ditto.
* mc-boot/GCOROUTINES.h: Ditto.
* mc-boot/GCmdArgs.cc: Ditto.
* mc-boot/GCmdArgs.h: Ditto.
* mc-boot/GDebug.cc: Ditto.
* mc-boot/GDebug.h: Ditto.
* mc-boot/GDynamicStrings.cc: Ditto.
* mc-boot/GDynamicStrings.h: Ditto.
* mc-boot/GEnvironment.cc: Ditto.
* mc-boot/GEnvironment.h: Ditto.
* mc-boot/GFIO.cc: Ditto.
* mc-boot/GFIO.h: Ditto.
* mc-boot/GFormatStrings.cc: Ditto.
* mc-boot/GFormatStrings.h: Ditto.
* mc-boot/GFpuIO.cc: Ditto.
* mc-boot/GFpuIO.h: Ditto.
* mc-boot/GIO.cc: Ditto.
* mc-boot/GIO.h: Ditto.
* mc-boot/GIndexing.cc: Ditto.
* mc-boot/GIndexing.h: Ditto.
* mc-boot/GM2Dependent.cc: Ditto.
* mc-boot/GM2Dependent.h: Ditto.
* mc-boot/GM2EXCEPTION.cc: Ditto.
* mc-boot/GM2EXCEPTION.h: Ditto.
* mc-boot/GM2RTS.cc: Ditto.
* mc-boot/GM2RTS.h: Ditto.
* mc-boot/GMemUtils.cc: Ditto.
* mc-boot/GMemUtils.h: Ditto.
* mc-boot/GNumberIO.cc: Ditto.
* mc-boot/GNumberIO.h: Ditto.
* mc-boot/GPushBackInput.cc: Ditto.
* mc-boot/GPushBackInput.h: Ditto.
* mc-boot/GRTExceptions.cc: Ditto.
* mc-boot/GRTExceptions.h: Ditto.
* mc-boot/GRTco.h: Ditto.
* mc-boot/GRTentity.h: Ditto.
* mc-boot/GRTint.cc: Ditto.
* mc-boot/GRTint.h: Ditto.
* mc-boot/GSArgs.cc: Ditto.
* mc-boot/GSArgs.h: Ditto.
* mc-boot/GSFIO.cc: Ditto.
* mc-boot/GSFIO.h: Ditto.
* mc-boot/GSYSTEM.h: Ditto.
* mc-boot/GSelective.h: Ditto.
* mc-boot/GStdIO.cc: Ditto.
* mc-boot/GStdIO.h: Ditto.
* mc-boot/GStorage.cc: Ditto.
* mc-boot/GStorage.h: Ditto.
* mc-boot/GStrCase.cc: Ditto.
* mc-boot/GStrCase.h: Ditto.
* mc-boot/GStrIO.cc: Ditto.
* mc-boot/GStrIO.h: Ditto.
* mc-boot/GStrLib.cc: Ditto.
* mc-boot/GStrLib.h: Ditto.
* mc-boot/GStringConvert.cc: Ditto.
* mc-boot/GStringConvert.h: Ditto.
* mc-boot/GSysExceptions.h: Ditto.
* mc-boot/GSysStorage.cc: Ditto.
* mc-boot/GSysStorage.h: Ditto.
* mc-boot/GTimeString.cc: Ditto.
* mc-boot/GTimeString.h: Ditto.
* mc-boot/GUnixArgs.h: Ditto.
* mc-boot/Galists.cc: Ditto.
* mc-boot/Galists.h: Ditto.
* mc-boot/Gdecl.cc: Ditto.
* mc-boot/Gdecl.h: Ditto.
* mc-boot/Gdtoa.h: Ditto.
* mc-boot/Gerrno.h: Ditto.
* mc-boot/Gkeyc.cc: Ditto.
* mc-boot/Gkeyc.h: Ditto.
* mc-boot/Gldtoa.h: Ditto.
* mc-boot/Glibc.h: Ditto.
* mc-boot/Glibm.h: Ditto.
* mc-boot/Glists.cc: Ditto.
* mc-boot/Glists.h: Ditto.
* mc-boot/GmcComment.cc: Ditto.
* mc-boot/GmcComment.h: Ditto.
* mc-boot/GmcComp.cc: Ditto.
* mc-boot/GmcComp.h: Ditto.
* mc-boot/GmcDebug.cc: Ditto.
* mc-boot/GmcDebug.h: Ditto.
* mc-boot/GmcError.cc: Ditto.
* mc-boot/GmcError.h: Ditto.
* mc-boot/GmcFileName.cc: Ditto.
* mc-boot/GmcFileName.h: Ditto.
* mc-boot/GmcLexBuf.cc: Ditto.
* mc-boot/GmcLexBuf.h: Ditto.
* mc-boot/GmcMetaError.cc: Ditto.
* mc-boot/GmcMetaError.h: Ditto.
* mc-boot/GmcOptions.cc: Ditto.
* mc-boot/GmcOptions.h: Ditto.
* mc-boot/GmcPreprocess.cc: Ditto.
* mc-boot/GmcPreprocess.h: Ditto.
* mc-boot/GmcPretty.cc: Ditto.
* mc-boot/GmcPretty.h: Ditto.
* mc-boot/GmcPrintf.cc: Ditto.
* mc-boot/GmcPrintf.h: Ditto.
* mc-boot/GmcQuiet.cc: Ditto.
* mc-boot/GmcQuiet.h: Ditto.
* mc-boot/GmcReserved.cc: Ditto.
* mc-boot/GmcReserved.h: Ditto.
* mc-boot/GmcSearch.cc: Ditto.
* mc-boot/GmcSearch.h: Ditto.
* mc-boot/GmcStack.cc: Ditto.
* mc-boot/GmcStack.h: Ditto.
* mc-boot/GmcStream.cc: Ditto.
* mc-boot/GmcStream.h: Ditto.
* mc-boot/Gmcflex.h: Ditto.
* mc-boot/Gmcp1.cc: Ditto.
* mc-boot/Gmcp1.h: Ditto.
* mc-boot/Gmcp2.cc: Ditto.
* mc-boot/Gmcp2.h: Ditto.
* mc-boot/Gmcp3.cc: Ditto.
* mc-boot/Gmcp3.h: Ditto.
* mc-boot/Gmcp4.cc: Ditto.
* mc-boot/Gmcp4.h: Ditto.
* mc-boot/Gmcp5.cc: Ditto.
* mc-boot/Gmcp5.h: Ditto.
* mc-boot/GnameKey.cc: Ditto.
* mc-boot/GnameKey.h: Ditto.
* mc-boot/GsymbolKey.cc: Ditto.
* mc-boot/GsymbolKey.h: Ditto.
* mc-boot/Gtermios.h: Ditto.
* mc-boot/Gtop.cc: Ditto.
* mc-boot/Gvarargs.cc: Ditto.
* mc-boot/Gvarargs.h: Ditto.
* mc-boot/Gwlists.cc: Ditto.
* mc-boot/Gwlists.h: Ditto.
* mc-boot/Gwrapc.h: Ditto.
* mc/keyc.mod (checkGccConfigSystem): Add
#define INCLUDE_MEMORY.
* pge-boot/GASCII.cc: Regenerate.
* pge-boot/GASCII.h: Ditto.
* pge-boot/GArgs.cc: Ditto.
* pge-boot/GArgs.h: Ditto.
* pge-boot/GAssertion.cc: Ditto.
* pge-boot/GAssertion.h: Ditto.
* pge-boot/GBreak.h: Ditto.
* pge-boot/GCmdArgs.h: Ditto.
* pge-boot/GDebug.cc: Ditto.
* pge-boot/GDebug.h: Ditto.
* pge-boot/GDynamicStrings.cc: Ditto.
* pge-boot/GDynamicStrings.h: Ditto.
* pge-boot/GEnvironment.h: Ditto.
* pge-boot/GFIO.cc: Ditto.
* pge-boot/GFIO.h: Ditto.
* pge-boot/GFormatStrings.h: Ditto.
* pge-boot/GFpuIO.h: Ditto.
* pge-boot/GIO.cc: Ditto.
* pge-boot/GIO.h: Ditto.
* pge-boot/GIndexing.cc: Ditto.
* pge-boot/GIndexing.h: Ditto.
* pge-boot/GLists.cc: Ditto.
* pge-boot/GLists.h: Ditto.
* pge-boot/GM2Dependent.cc: Ditto.
* pge-boot/GM2Dependent.h: Ditto.
* pge-boot/GM2EXCEPTION.cc: Ditto.
* pge-boot/GM2EXCEPTION.h: Ditto.
* pge-boot/GM2RTS.cc: Ditto.
* pge-boot/GM2RTS.h: Ditto.
* pge-boot/GNameKey.cc: Ditto.
* pge-boot/GNameKey.h: Ditto.
* pge-boot/GNumberIO.cc: Ditto.
* pge-boot/GNumberIO.h: Ditto.
* pge-boot/GOutput.cc: Ditto.
* pge-boot/GOutput.h: Ditto.
* pge-boot/GPushBackInput.cc: Ditto.
* pge-boot/GPushBackInput.h: Ditto.
* pge-boot/GRTExceptions.cc: Ditto.
* pge-boot/GRTExceptions.h: Ditto.
* pge-boot/GSArgs.h: Ditto.
* pge-boot/GSEnvironment.h: Ditto.
* pge-boot/GSFIO.cc: Ditto.
* pge-boot/GSFIO.h: Ditto.
* pge-boot/GSYSTEM.h: Ditto.
* pge-boot/GScan.h: Ditto.
* pge-boot/GStdIO.cc: Ditto.
* pge-boot/GStdIO.h: Ditto.
* pge-boot/GStorage.cc: Ditto.
* pge-boot/GStorage.h: Ditto.
* pge-boot/GStrCase.cc: Ditto.
* pge-boot/GStrCase.h: Ditto.
* pge-boot/GStrIO.cc: Ditto.
* pge-boot/GStrIO.h: Ditto.
* pge-boot/GStrLib.cc: Ditto.
* pge-boot/GStrLib.h: Ditto.
* pge-boot/GStringConvert.h: Ditto.
* pge-boot/GSymbolKey.cc: Ditto.
* pge-boot/GSymbolKey.h: Ditto.
* pge-boot/GSysExceptions.h: Ditto.
* pge-boot/GSysStorage.cc: Ditto.
* pge-boot/GSysStorage.h: Ditto.
* pge-boot/GTimeString.h: Ditto.
* pge-boot/GUnixArgs.h: Ditto.
* pge-boot/Gbnflex.cc: Ditto.
* pge-boot/Gbnflex.h: Ditto.
* pge-boot/Gdtoa.h: Ditto.
* pge-boot/Gerrno.h: Ditto.
* pge-boot/Gldtoa.h: Ditto.
* pge-boot/Glibc.h: Ditto.
* pge-boot/Glibm.h: Ditto.
* pge-boot/Gpge.cc: Ditto.
* pge-boot/Gtermios.h: Ditto.
* pge-boot/Gwrapc.h: Ditto.
gcc/objc/ChangeLog:
PR other/116613
* objc-act.cc: Add #define INCLUDE_MEMORY.
* objc-encoding.cc: Likewise.
* objc-gnu-runtime-abi-01.cc: Likewise.
* objc-lang.cc: Likewise.
* objc-next-runtime-abi-01.cc: Likewise.
* objc-next-runtime-abi-02.cc: Likewise.
* objc-runtime-shared-support.cc: Likewise.
gcc/objcp/ChangeLog:: Add #define INCLUDE_MEMORY.
PR other/116613
* objcp-decl.cc
* objcp-lang.cc: Likewise.
gcc/rust/ChangeLog:
PR other/116613
* resolve/rust-ast-resolve-expr.cc: Add #define INCLUDE_MEMORY.
* rust-attribs.cc: Likewise.
* rust-system.h: Likewise.
gcc/ChangeLog:
PR other/116613
* asan.cc: Add #define INCLUDE_MEMORY.
* attribs.cc: Likewise.
(attr_access::array_as_string): Use
diagnostic_context::clone_printer and use unique_ptr.
* auto-profile.cc: Add #define INCLUDE_MEMORY.
* calls.cc: Likewise.
* cfganal.cc: Likewise.
* cfgexpand.cc: Likewise.
* cfghooks.cc: Likewise.
* cfgloop.cc: Likewise.
* cgraph.cc: Likewise.
* cgraphclones.cc: Likewise.
* cgraphunit.cc: Likewise.
* collect-utils.cc: Likewise.
* collect2.cc: Likewise.
* common/config/aarch64/aarch64-common.cc: Likewise.
* common/config/arm/arm-common.cc: Likewise.
* common/config/avr/avr-common.cc: Likewise.
* config/aarch64/aarch64-cc-fusion.cc: Likewise.
* config/aarch64/aarch64-early-ra.cc: Likewise.
* config/aarch64/aarch64-sve-builtins.cc: Likewise.
* config/arc/arc.cc: Likewise.
* config/arm/aarch-common.cc: Likewise.
* config/arm/arm-mve-builtins.cc: Likewise.
* config/avr/avr-devices.cc: Likewise.
* config/avr/driver-avr.cc: Likewise.
* config/bpf/bpf.cc: Likewise.
* config/bpf/btfext-out.cc: Likewise.
* config/bpf/core-builtins.cc: Likewise.
* config/darwin.cc: Likewise.
* config/i386/driver-i386.cc: Likewise.
* config/i386/i386-builtins.cc: Likewise.
* config/i386/i386-expand.cc: Likewise.
* config/i386/i386-features.cc: Likewise.
* config/i386/i386-options.cc: Likewise.
* config/loongarch/loongarch-builtins.cc: Likewise.
* config/mingw/winnt-cxx.cc: Likewise.
* config/mingw/winnt.cc: Likewise.
* config/mips/mips.cc: Likewise.
* config/msp430/driver-msp430.cc: Likewise.
* config/nvptx/mkoffload.cc: Likewise.
* config/nvptx/nvptx.cc: Likewise.
* config/riscv/riscv-avlprop.cc: Likewise.
* config/riscv/riscv-vector-builtins.cc: Likewise.
* config/riscv/riscv-vsetvl.cc: Likewise.
* config/rs6000/driver-rs6000.cc: Likewise.
* config/rs6000/host-darwin.cc: Likewise.
* config/rs6000/rs6000-c.cc: Likewise.
* config/s390/s390-c.cc: Likewise.
* config/s390/s390.cc: Likewise.
* config/sol2-cxx.cc: Likewise.
* config/vms/vms-c.cc: Likewise.
* config/xtensa/xtensa-dynconfig.cc: Likewise.
* coroutine-passes.cc: Likewise.
* coverage.cc: Likewise.
* data-streamer-in.cc: Likewise.
* data-streamer-out.cc: Likewise.
* data-streamer.cc: Likewise.
* diagnostic-buffer.h (diagnostic_buffer::~diagnostic_buffer):
Delete.
(diagnostic_buffer::m_per_format_buffer): Use std::unique_ptr.
* diagnostic-client-data-hooks.h (make_compiler_data_hooks): Use
std::unique_ptr for return type.
* diagnostic-format-json.cc
(json_output_format::make_per_format_buffer): Likewise.
(diagnostic_output_format_init_json): Update for usage of
std::unique_ptr in set_output_format.
* diagnostic-format-sarif.cc
(sarif_output_format::make_per_format_buffer): Use std::unique_ptr
for return type.
(diagnostic_output_format_init_sarif): Update for usage of
std::unique_ptr.
(test_message_with_embedded_link): Likewise for set_urlifier.
* diagnostic-format-text.cc: Add #define INCLUDE_MEMORY. Include
"make-unique.h".
(diagnostic_text_output_format::set_buffer): Use std::unique_ptr.
* diagnostic-format-text.h
(diagnostic_text_output_format::set_buffer): Likewise.
* diagnostic-format.h
(diagnostic_output_format::make_per_format_buffer): Likewise.
* diagnostic-global-context.cc:
* diagnostic-macro-unwinding.cc: Likewise.
* diagnostic-show-locus.cc: Likewise.
* diagnostic-spec.cc: Likewise.
* diagnostic.cc (diagnostic_context::set_output_format): Use
std::unique_ptr for input.
(diagnostic_context::set_client_data_hooks): Likewise.
(diagnostic_context::set_option_manager): Likewise.
(diagnostic_context::set_urlifier): Likewise.
(diagnostic_context::set_diagnostic_buffer): Update for use of
std::unique_ptr.
(diagnostic_buffer::diagnostic_buffer): Likewise.
(diagnostic_buffer::~diagnostic_buffer): Delete.
* diagnostic.h: Complain if INCLUDE_MEMORY was not defined.
(diagnostic_context::set_output_format): Use std::unique_ptr for
input.
(diagnostic_context::set_client_data_hooks): Likewise.
(diagnostic_context::set_option_manager): Likewise.
(diagnostic_context::set_urlifier): Likewise.
(diagnostic_context::clone_printer): New.
(diagnostic_context::m_printer): Update comment.
(diagnostic_context::m_option_mgr): Likewise.
(diagnostic_context::m_urlifier): Likewise.
(diagnostic_context::m_edit_context_ptr): Likewise.
(diagnostic_context::m_output_format): Likewise.
(diagnostic_context::m_client_data_hooks): Likewise.
(diagnostic_context::m_theme): Likewise.
* digraph.cc: Add #define INCLUDE_MEMORY.
* dwarf2out.cc: Likewise.
* edit-context.cc: Likewise.
* except.cc: Likewise.
* expr.cc: Likewise.
* file-prefix-map.cc: Likewise.
* final.cc: Likewise.
* fwprop.cc: Likewise.
* gcc-plugin.h: Likewise.
* gcc-rich-location.cc: Likewise.
* gcc-urlifier.cc: Likewise. Add #include "make-unique.h".
(make_gcc_urlifier): Use std::unique_ptr and ::make_unique.
* gcc-urlifier.h (make_gcc_urlifier): Use std::unique_ptr.
* gcc.cc: Add #define INCLUDE_MEMORY. Include
"pretty-print-urlifier.h".
* gcov-dump.cc: Add #define INCLUDE_MEMORY.
* gcov-tool.cc: Likewise.
* gengtype.cc (open_base_files): Likewise to output.
* genmatch.cc: Likewise.
* gimple-fold.cc: Likewise.
* gimple-harden-conditionals.cc: Likewise.
* gimple-harden-control-flow.cc: Likewise.
* gimple-if-to-switch.cc: Likewise.
* gimple-lower-bitint.cc: Likewise.
* gimple-predicate-analysis.cc: Likewise.
* gimple-pretty-print.cc: Likewise.
* gimple-range-cache.cc: Likewise.
* gimple-range-edge.cc: Likewise.
* gimple-range-fold.cc: Likewise.
* gimple-range-gori.cc: Likewise.
* gimple-range-infer.cc: Likewise.
* gimple-range-op.cc: Likewise.
* gimple-range-path.cc: Likewise.
* gimple-range-phi.cc: Likewise.
* gimple-range-trace.cc: Likewise.
* gimple-range.cc: Likewise.
* gimple-ssa-backprop.cc: Likewise.
* gimple-ssa-sprintf.cc: Likewise.
* gimple-ssa-store-merging.cc: Likewise.
* gimple-ssa-strength-reduction.cc: Likewise.
* gimple-ssa-warn-access.cc: Likewise.
* gimple-ssa-warn-alloca.cc: Likewise.
* gimple-ssa-warn-restrict.cc: Likewise.
* gimple-streamer-in.cc: Likewise.
* gimple-streamer-out.cc: Likewise.
* gimple.cc: Likewise.
* gimplify.cc: Likewise.
* graph.cc: Likewise.
* graphviz.cc: Likewise.
* input.cc: Likewise.
* ipa-cp.cc: Likewise.
* ipa-devirt.cc: Likewise.
* ipa-fnsummary.cc: Likewise.
* ipa-free-lang-data.cc: Likewise.
* ipa-icf-gimple.cc: Likewise.
* ipa-icf.cc: Likewise.
* ipa-inline-analysis.cc: Likewise.
* ipa-inline.cc: Likewise.
* ipa-modref-tree.cc: Likewise.
* ipa-modref.cc: Likewise.
* ipa-param-manipulation.cc: Likewise.
* ipa-polymorphic-call.cc: Likewise.
* ipa-predicate.cc: Likewise.
* ipa-profile.cc: Likewise.
* ipa-prop.cc: Likewise.
* ipa-pure-const.cc: Likewise.
* ipa-reference.cc: Likewise.
* ipa-split.cc: Likewise.
* ipa-sra.cc: Likewise.
* ipa-strub.cc: Likewise.
* ipa-utils.cc: Likewise.
* langhooks.cc: Likewise.
* late-combine.cc: Likewise.
* lto-cgraph.cc: Likewise.
* lto-compress.cc: Likewise.
* lto-opts.cc: Likewise.
* lto-section-in.cc: Likewise.
* lto-section-out.cc: Likewise.
* lto-streamer-in.cc: Likewise.
* lto-streamer-out.cc: Likewise.
* lto-streamer.cc: Likewise.
* lto-wrapper.cc: Likewise. Include "make-unique.h".
(main): Use ::make_unique when creating option manager.
* multiple_target.cc: Likewise.
* omp-expand.cc: Likewise.
* omp-general.cc: Likewise.
* omp-low.cc: Likewise.
* omp-oacc-neuter-broadcast.cc: Likewise.
* omp-offload.cc: Likewise.
* omp-simd-clone.cc: Likewise.
* optc-gen.awk: Likewise in output.
* optc-save-gen.awk: Likewise in output.
* options-urls-cc-gen.awk: Likewise in output.
* opts-common.cc: Likewise.
* opts-global.cc: Likewise.
* opts.cc: Likewise.
* pair-fusion.cc: Likewise.
* passes.cc: Likewise.
* pointer-query.cc: Likewise.
* predict.cc: Likewise.
* pretty-print.cc (pretty_printer::clone): Use std::unique_ptr and
::make_unique.
* pretty-print.h: Complain if INCLUDE_MEMORY is not defined.
(pretty_printer::clone): Use std::unique_ptr.
* print-rtl.cc: Add #define INCLUDE_MEMORY.
* print-tree.cc: Likewise.
* profile-count.cc: Likewise.
* range-op-float.cc: Likewise.
* range-op-ptr.cc: Likewise.
* range-op.cc: Likewise.
* range.cc: Likewise.
* read-rtl-function.cc: Likewise.
* rtl-error.cc: Likewise.
* rtl-ssa/accesses.cc: Likewise.
* rtl-ssa/blocks.cc: Likewise.
* rtl-ssa/changes.cc: Likewise.
* rtl-ssa/functions.cc: Likewise.
* rtl-ssa/insns.cc: Likewise.
* rtl-ssa/movement.cc: Likewise.
* rtl-tests.cc: Likewise.
* sanopt.cc: Likewise.
* sched-rgn.cc: Likewise.
* selftest-diagnostic-path.cc: Likewise.
* selftest-diagnostic.cc: Likewise.
* splay-tree-utils.cc: Likewise.
* sreal.cc: Likewise.
* stmt.cc: Likewise.
* substring-locations.cc: Likewise.
* symtab-clones.cc: Likewise.
* symtab-thunks.cc: Likewise.
* symtab.cc: Likewise.
* text-art/box-drawing.cc: Likewise.
* text-art/canvas.cc: Likewise.
* text-art/ruler.cc: Likewise.
* text-art/selftests.cc: Likewise.
* text-art/theme.cc: Likewise.
* toplev.cc: Likewise. Include "make-unique.h".
(general_init): Use ::make_unique when setting option_manager.
* trans-mem.cc: Add #define INCLUDE_MEMORY.
* tree-affine.cc: Likewise.
* tree-call-cdce.cc: Likewise.
* tree-cfg.cc: Likewise.
* tree-chrec.cc: Likewise.
* tree-dfa.cc: Likewise.
* tree-diagnostic-client-data-hooks.cc: Include "make-unique.h".
(make_compiler_data_hooks): Use std::unique_ptr and ::make_unique.
* tree-diagnostic.cc: Add #define INCLUDE_MEMORY.
* tree-dump.cc: Likewise.
* tree-inline.cc: Likewise.
* tree-into-ssa.cc: Likewise.
* tree-logical-location.cc: Likewise.
* tree-nested.cc: Likewise.
* tree-nrv.cc: Likewise.
* tree-object-size.cc: Likewise.
* tree-outof-ssa.cc: Likewise.
* tree-pretty-print.cc: Likewise.
* tree-profile.cc: Likewise.
* tree-scalar-evolution.cc: Likewise.
* tree-sra.cc: Likewise.
* tree-ssa-address.cc: Likewise.
* tree-ssa-alias.cc: Likewise.
* tree-ssa-ccp.cc: Likewise.
* tree-ssa-coalesce.cc: Likewise.
* tree-ssa-copy.cc: Likewise.
* tree-ssa-dce.cc: Likewise.
* tree-ssa-dom.cc: Likewise.
* tree-ssa-forwprop.cc: Likewise.
* tree-ssa-ifcombine.cc: Likewise.
* tree-ssa-loop-ch.cc: Likewise.
* tree-ssa-loop-im.cc: Likewise.
* tree-ssa-loop-manip.cc: Likewise.
* tree-ssa-loop-niter.cc: Likewise.
* tree-ssa-loop-split.cc: Likewise.
* tree-ssa-math-opts.cc: Likewise.
* tree-ssa-operands.cc: Likewise.
* tree-ssa-phiprop.cc: Likewise.
* tree-ssa-pre.cc: Likewise.
* tree-ssa-propagate.cc: Likewise.
* tree-ssa-reassoc.cc: Likewise.
* tree-ssa-sccvn.cc: Likewise.
* tree-ssa-scopedtables.cc: Likewise.
* tree-ssa-sink.cc: Likewise.
* tree-ssa-strlen.cc: Likewise.
* tree-ssa-structalias.cc: Likewise.
* tree-ssa-ter.cc: Likewise.
* tree-ssa-uninit.cc: Likewise.
* tree-ssa.cc: Likewise.
* tree-ssanames.cc: Likewise.
* tree-stdarg.cc: Likewise.
* tree-streamer-in.cc: Likewise.
* tree-streamer-out.cc: Likewise.
* tree-streamer.cc: Likewise.
* tree-switch-conversion.cc: Likewise.
* tree-tailcall.cc: Likewise.
* tree-vrp.cc: Likewise.
* tree.cc: Likewise.
* ubsan.cc: Likewise.
* value-pointer-equiv.cc: Likewise.
* value-prof.cc: Likewise.
* value-query.cc: Likewise.
* value-range-pretty-print.cc: Likewise.
* value-range-storage.cc: Likewise.
* value-range.cc: Likewise.
* value-relation.cc: Likewise.
* var-tracking.cc: Likewise.
* varpool.cc: Likewise.
* vr-values.cc: Likewise.
* wide-int-print.cc: Likewise.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/diagnostic_group_plugin.c: Update for use of
std::unique_ptr.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Likewise.
* gcc.dg/plugin/ggcplug.c: Likewise.
libgcc/ChangeLog:
PR other/116613
* libgcov-util.c: Add #define INCLUDE_MEMORY.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Co-authored-by: Gaius Mulley <gaiusmod2@gmail.com>
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
PR fortran/105916 reports stray diagnostics appearing in JSON and SARIF
output from gfortran.
In order to handle various awkard parsing issues, the Fortran frontend
implements buffering of diagnostics, so that diagnostics reported to
global_dc can be either:
(a) immediately issued, or
(b) speculatively reported to global_dc, and stored in a buffer, to
either be issued later or discarded.
This buffering code in gcc/fortran/error.cc directly manipulates
implementation details of the diagnostic_context such as the
pretty_printer's buffer, and the counts of how many diagnostics have
been issued. The issue is that this manipulation of pretty_printer's
buffer doesn't work for formats such as JSON and SARIF where diagnostics
are handled in a different way (such as by accumulating json::object
instances in an array).
This patch moves responsibility for such buffering of diagnostics from
fortran's error.cc to the diagnostic subsystem. It introduces a new
class diagnostic_buffer representing a particular buffer of diagnostics
that have been reported but not yet issued. Each diagnostic output
format implements buffering in a different way, and so there is a
new class hierarchy, diagnostic_per_format_buffer, representing the
various format-specific ways that buffering is to be implemented. This
is hidden as an implementation detail of diagnostic_buffer.
The patch also updates how diagnostics of each kind (e.g. warnings vs
errors) are counted, so that if buffering is enabled, the count is
incremented within the buffer, and the counts in the diagnostic_context
are only updated if and when the buffer is flushed; checking for
max_errors is similarly updated to support both buffered and unbuffered
cases.
For ease of debugging, the patch extends the "dump" functions within the
diagnostics subsystem, so that e.g. global_dc->dump () now prints the
buffering status, e.g.:
(gdb) call global_dc->dump()
diagnostic_context:
counts:
(none)
output format:
sarif_output_format
printer:
m_show_color: false
m_url_format: bel
m_buffer:
m_formatted_obstack current object: length 0:
m_chunk_obstack current object: length 0:
diagnostic buffer:
m_per_format_buffer:
counts:
error: 1
diagnostic_sarif_format_buffer:
result[0]:
{"ruleId": "error",
"level": "error",
"message": {"text": "Function ‘program’ requires an argument list at (1)"},
"locations": [{"physicalLocation": {"artifactLocation": {"uri": "../../src/gcc/testsuite/gfortran.dg/pr105954.f90",
"uriBaseId": "PWD"},
"region": {"startLine": 6,
"startColumn": 8,
"endColumn": 9},
"contextRegion": {"startLine": 6,
"snippet": {"text": "program p\n"}}}}]}
which shows that no diagnostics have been issued yet, but the active
diagnostic_buffer has a single error buffered within it, in SARIF form.
Similarly, it's possible to use "dump" on a diagnostic_buffer to directly
query its contents; here's the same example, this time with the text
output format:
(gdb) call error_buffer.buffer.dump()
m_per_format_buffer:
counts:
error: 1
diagnostic_text_format_buffer:
m_formatted_obstack current object: length 232:
00000000: 1b 5b 30 31 6d 1b 5b 4b 2e 2e 2f 2e 2e 2f 73 72 | .[01m.[K../../sr
00000010: 63 2f 67 63 63 2f 74 65 73 74 73 75 69 74 65 2f | c/gcc/testsuite/
00000020: 67 66 6f 72 74 72 61 6e 2e 64 67 2f 70 72 31 30 | gfortran.dg/pr10
00000030: 35 39 35 34 2e 66 39 30 3a 36 3a 38 3a 1b 5b 6d | 5954.f90:6:8:.[m
00000040: 1b 5b 4b 0a 0a 20 20 20 20 36 20 7c 20 70 72 6f | .[K.. 6 | pro
00000050: 67 72 61 6d 20 70 0a 20 20 20 20 20 20 7c 20 20 | gram p. |
00000060: 20 20 20 20 20 20 1b 5b 30 31 3b 33 31 6d 1b 5b | .[01;31m.[
00000070: 4b 31 1b 5b 6d 1b 5b 4b 0a 1b 5b 30 31 3b 33 31 | K1.[m.[K..[01;31
00000080: 6d 1b 5b 4b 45 72 72 6f 72 3a 1b 5b 6d 1b 5b 4b | m.[KError:.[m.[K
00000090: 20 46 75 6e 63 74 69 6f 6e 20 e2 80 98 1b 5b 30 | Function ....[0
000000a0: 31 6d 1b 5b 4b 70 72 6f 67 72 61 6d 1b 5b 6d 1b | 1m.[Kprogram.[m.
000000b0: 5b 4b e2 80 99 20 72 65 71 75 69 72 65 73 20 61 | [K... requires a
000000c0: 6e 20 61 72 67 75 6d 65 6e 74 20 6c 69 73 74 20 | n argument list
000000d0: 61 74 20 1b 5b 30 31 3b 33 31 6d 1b 5b 4b 28 31 | at .[01;31m.[K(1
000000e0: 29 1b 5b 6d 1b 5b 4b 0a | ).[m.[K.
m_chunk_obstack current object: length 0:
showing that we have an error in error_buffer, with colorized text.
gcc/ChangeLog:
PR fortran/105916
* diagnostic-buffer.h: New file.
* diagnostic-format-json.cc: Define INCLUDE_VECTOR. Include
"diagnostic-buffer.h".
(class diagnostic_json_format_buffer): New subclass.
(class json_output_format): Add friend class
diagnostic_json_format_buffer.
(json_output_format::make_per_format_buffer): New vfunc
implementation.
(json_output_format::set_buffer): New vfunc implementation.
(json_output_format::json_output_format): Initialize m_buffer.
(json_output_format::m_buffer): New field.
(diagnostic_json_format_buffer::dump): New.
(diagnostic_json_format_buffer::empty_p): New.
(diagnostic_json_format_buffer::move_to): New.
(diagnostic_json_format_buffer::clear): New.
(diagnostic_json_format_buffer::flush): New.
(json_output_format::on_report_diagnostic): Implement optional
buffering.
* diagnostic-format-sarif.cc: Include "diagnostic-buffer.h".
(class diagnostic_sarif_format_buffer): New subclass.
(class sarif_builder): Add friend
class diagnostic_sarif_format_buffer.
(sarif_builder::num_results): New accessor.
(sarif_builder::get_result): New accessor.
(sarif_builder::on_report_diagnostic): Add param "buffer"; use it
to implement optional buffering.
(diagnostic_sarif_format_buffer::dump): New.
(diagnostic_sarif_format_buffer::empty_p): New.
(diagnostic_sarif_format_buffer::move_to): New.
(diagnostic_sarif_format_buffer::clear): New.
(diagnostic_sarif_format_buffer::flush): New.
(sarif_output_format::make_per_format_buffer): New vfunc
implementation.
(sarif_output_format::set_buffer): New vfunc implementation.
(sarif_output_format::on_report_diagnostic): Pass m_buffer to
sarif_builder::on_report_diagnostic.
(sarif_output_format::num_results): New accessor.
(sarif_output_format::get_result): New accessor.
(diagnostic_output_format::diagnostic_output_format): Initialize
m_buffer.
(diagnostic_output_format::m_buffer): New field.
(diagnostic_output_format::num_results): Get accessor.
(diagnostic_output_format::get_result): Get accessor.
(selftest::get_message_from_result): New.
(selftest::test_buffering): New.
(selftest::diagnostic_format_sarif_cc_tests): Call it.
* diagnostic-format-text.cc: Include
"diagnostic-client-data-hooks.h".
(class diagnostic_text_format_buffer): New subclass.
(diagnostic_text_format_buffer::diagnostic_text_format_buffer):
New.
(diagnostic_text_format_buffer::dump): New.
(diagnostic_text_format_buffer::empty_p): New.
(diagnostic_text_format_buffer::move_to): New.
(diagnostic_text_format_buffer::clear): New.
(diagnostic_text_format_buffer::flush): New.
(diagnostic_text_output_format::dump): Dump m_saved_output_buffer.
(diagnostic_text_output_format::set_buffer): New.
(diagnostic_text_output_format::make_per_format_buffer): New.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Initialize m_saved_output_buffer.
(diagnostic_text_output_format::set_buffer): New decl.
(diagnostic_text_output_format::make_per_format_buffer): New decl.
(diagnostic_text_output_format::m_saved_output_buffer): New field.
* diagnostic-format.h (class diagnostic_per_format_buffer): New
forward decl.
(diagnostic_output_format::make_per_format_buffer): New vfunc.
(diagnostic_output_format::set_buffer): New vfunc.
* diagnostic.cc: Include "diagnostic-buffer.h".
(diagnostic_context::initialize): Replace memset with call to
"clear" on m_diagnostic_counters. Initializer
m_diagnostic_buffer.
(diagnostic_context::finish): Call set_diagnostic_buffer with
nullptr.
(diagnostic_context::dump): Update for encapsulation of counts
into m_diagnostic_counters. Dump m_diagnostic_buffer.
(diagnostic_context::execution_failed_p): Update for encapsulation of
counts into m_diagnostic_counters.
(diagnostic_context::check_max_errors): Likewise.
(diagnostic_context::report_diagnostic): Likewise. Eliminate
diagnostic_check_max_errors in favor of check_max_errors.
Update increment of counter to support buffering. Eliminate
diagnostic_action_after_output in favor of action_after_output.
Only add fixits to m_edit_context_ptr if buffering is disabled.
Only call diagnostic_output_format::after_diagnostic if buffering
is disabled.
(diagnostic_context::error_recursion): Eliminate
diagnostic_action_after_output in favor of action_after_output.
(diagnostic_context::set_diagnostic_buffer): New.
(diagnostic_context::clear_diagnostic_buffer): New.
(diagnostic_context::flush_diagnostic_buffer): New.
(diagnostic_counters::diagnostic_counters): New.
(diagnostic_counters::dump): New.
(diagnostic_counters::move_to): New.
(diagnostic_counters::clear): New.
(diagnostic_buffer::diagnostic_buffer): New.
(diagnostic_buffer::~diagnostic_buffer): New.
(diagnostic_buffer::dump): New.
(diagnostic_buffer::empty_p): New.
(diagnostic_buffer::move_to): New.
(diagnostic_buffer::ensure_per_format_buffer): New.
(c_diagnostic_cc_tests): Remove stray newline.
* diagnostic.h (class diagnostic_buffer): New forward decl.
(struct diagnostic_counters): New.
(diagnostic_context::check_max_errors): Make private.
(diagnostic_context::action_after_output): Make private.
(diagnostic_context::get_output_format): Make non-const.
(diagnostic_context::diagnostic_count): Update for change
to m_diagnostic_counters.
(diagnostic_context::set_diagnostic_buffer): New decl.
(diagnostic_context::get_diagnostic_buffer): New decl.
(diagnostic_context::clear_diagnostic_buffer): New decl.
(diagnostic_context::flush_diagnostic_buffer): New decl.
(diagnostic_context::m_diagnostic_count): Replace array with...
(diagnostic_context::m_diagnostic_counters): ...this.
(diagnostic_context::m_diagnostic_buffer): New field.
(diagnostic_action_after_output): Delete.
(diagnostic_check_max_errors): Delete.
gcc/fortran/ChangeLog:
PR fortran/105916
* error.cc (pp_error_buffer, pp_warning_buffer): Convert from
output_buffer * to diagnostic_buffer *.
(warningcount_buffered, werrorcount_buffered): Eliminate.
(gfc_error_buffer::gfc_error_buffer): Move constructor definition
here, and initialize "buffer" using *global_dc.
(gfc_output_buffer_empty_p): Delete in favor of
diagnostic_buffer::empty_p.
(gfc_clear_pp_buffer): Replace with...
(gfc_clear_diagnostic_buffer): ...this, moving implementation
details to diagnostic_context::clear_diagnostic_buffer.
(gfc_warning): Replace buffering implementation with calls
to global_dc->get_diagnostic_buffer and
global_dc->set_diagnostic_buffer.
(gfc_clear_warning): Update for renaming of gfc_clear_pp_buffer
and elimination of warningcount_buffered and werrorcount_buffered.
(gfc_warning_check): Replace buffering implementation with calls
to pp_warning_buffer->empty_p and
global_dc->flush_diagnostic_buffer.
(gfc_error_opt): Replace buffering implementation with calls to
global_dc->get_diagnostic_buffer and set_diagnostic_buffer.
(gfc_clear_error): Update for renaming of gfc_clear_pp_buffer.
(gfc_error_flag_test): Replace call to gfc_output_buffer_empty_p
with call to diagnostic_buffer::empty_p.
(gfc_error_check): Replace buffering implementation with calls
to pp_error_buffer->empty_p and global_dc->flush_diagnostic_buffer.
(gfc_move_error_buffer_from_to): Replace buffering implementation
with usage of diagnostic_buffer.
(gfc_free_error): Update for renaming of gfc_clear_pp_buffer.
(gfc_diagnostics_init): Use "new" directly when creating
pp_warning_buffer. Remove setting of m_flush_p on the two
buffers, as this is handled by diagnostic_buffer and by
diagnostic_text_format_buffer's constructor.
* gfortran.h: Replace #include "pretty-print.h" for output_buffer
with #include "diagnostic-buffer.h" for diagnostic_buffer.
(struct gfc_error_buffer): Change type of field "buffer" from
output_buffer to diagnostic_buffer. Move definition of constructor
into error.cc so that it can use global_dc.
gcc/testsuite/ChangeLog:
PR fortran/105916
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Include
"diagnostic-buffer.h".
(class diagnostic_xhtml_format_buffer): New subclass.
(class xhtml_builder): Add friend
class diagnostic_xhtml_format_buffer.
(diagnostic_xhtml_format_buffer::dump): New.
(diagnostic_xhtml_format_buffer::empty_p): New.
(diagnostic_xhtml_format_buffer::move_to): New.
(diagnostic_xhtml_format_buffer::clear): New.
(diagnostic_xhtml_format_buffer::flush): New.
(xhtml_builder::on_report_diagnostic): Add "buffer" param, and use
it.
(xhtml_output_format::dump): Fix typo.
(xhtml_output_format::make_per_format_buffer): New.
(xhtml_output_format::set_buffer): New.
(xhtml_output_format::on_report_diagnostic): Fix whitespace. Pass
m_buffer to xhtml_builder::on_report_diagnostic.
(xhtml_output_format::xhtml_output_format): Initialize m_buffer.
(xhtml_output_format::m_buffer): New field.
* gfortran.dg/diagnostic-format-json-pr105916.F90: New test.
* gfortran.dg/diagnostic-format-sarif-1.F90: New test.
* gfortran.dg/diagnostic-format-sarif-1.py: New support script.
* gfortran.dg/diagnostic-format-sarif-pr105916.f90: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This commit expands on r15-3973-g4c7a58ac2617e2, which added
debug "dump" member functiosn to pretty_printer and output_buffer.
This followup adds "dump" member functions to diagnostic_context and
diagnostic_format, extends the existing dump functions and adds
indentation to make it much easier to see the various relationships
between context, format, printer, etc.
Hence you can now do:
(gdb) call global_dc->dump ()
and get a useful summary of what the diagnostic subsystem is doing;
for example:
(gdb) call global_dc->dump()
diagnostic_context:
counts:
output format:
sarif_output_format
printer:
m_show_color: false
m_url_format: bel
m_buffer:
m_formatted_obstack current object: length 0:
m_chunk_obstack current object: length 0:
pp_formatted_chunks: depth 0
0: TEXT("Function ")]
1: BEGIN_QUOTE, TEXT("program"), END_QUOTE]
2: TEXT(" requires an argument list at ")]
3: TEXT("(1)")]
showing the counts of all diagnostic kind that are non-zero (none yet),
that we have a sarif output format, and the printer is part-way through
formatting a string.
gcc/ChangeLog:
* diagnostic-format-json.cc (json_output_format::dump): New.
* diagnostic-format-sarif.cc (sarif_output_format::dump): New.
(sarif_file_output_format::dump): New.
* diagnostic-format-text.cc (diagnostic_text_output_format::dump):
New.
* diagnostic-format-text.h (diagnostic_text_output_format::dump):
New decl.
* diagnostic-format.h (diagnostic_output_format::dump): New decls.
* diagnostic.cc (diagnostic_context::dump): New.
(diagnostic_output_format::dump): New.
* diagnostic.h (diagnostic_context::dump): New decls.
* pretty-print-format-impl.h (pp_formatted_chunks::dump): Add
"indent" param.
* pretty-print.cc (bytes_per_hexdump_line): New constant.
(print_hexdump_line): New.
(print_hexdump): New.
(output_buffer::dump): Add "indent" param and use it. Add
hexdump of current object in m_formatted_obstack and
m_chunk_obstack.
(pp_formatted_chunks::dump): Add "indent" param and use it.
(pretty_printer::dump): Likewise. Add dumping of m_show_color
and m_url_format.
* pretty-print.h (output_buffer::dump): Add "indent" param.
(pretty_printer::dump): Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c
(xhtml_output_format::dump): New.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This patch makes the SARIF output's crash handler attempt to capture
a backtrace in JSON form within the notification's property bag. The
precise format of the property is subject to change, but, for example,
in one of the test cases I got output like this:
"properties": {"gcc/backtrace": {"frames": [{"pc": "0x7f39c610a32d",
"function": "pass_crash_test::execute(function*)",
"filename": "/home/david/gcc-newgit/src/gcc/testsuite/gcc.dg/plugin/crash_test_plugin.c",
"lineno": 98}]}}}],
The backtrace code is based on that in diagnostic.cc.
gcc/ChangeLog:
PR other/116602
* diagnostic-format-sarif.cc: Include "demangle.h" and
"backtrace.h".
(sarif_invocation::add_notification_for_ice): Add "backtrace"
param and pass it to ctor.
(sarif_ice_notification::sarif_ice_notification): Add "backtrace"
param and add it to property bag.
(bt_stop): New, taken from diagnostic.cc.
(struct bt_closure): New.
(bt_callback): New, adapted from diagnostic.cc.
(sarif_builder::make_stack_from_backtrace): New.
(sarif_builder::on_report_diagnostic): Attempt to get backtrace
and pass it to add_notification_for_ice.
gcc/testsuite/ChangeLog:
PR other/116602
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2_1.py: Add check
for backtrace.
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2_2.py: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
No functional change intended.
gcc/ChangeLog:
PR other/116613
* diagnostic-format-sarif.cc
(sarif_builder::on_report_diagnostic): Move the fnotice here from
sarif_ice_handler.
(sarif_ice_handler): Delete.
(diagnostic_output_format_init_sarif): Drop setting of ice handler
callback.
* diagnostic.cc (diagnostic_context::initialize): Likewise.
(diagnostic_context::action_after_output): Rather than call
m_ice_handler_cb, instead call finish on this context.
* diagnostic.h (ice_handler_callback_t): Delete typedef.
(diagnostic_context::set_ice_handler_callback): Delete.
(diagnostic_context::m_ice_handler_cb): Delete.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Update for
removal of ICE callback.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Now that C23 support is essentially feature-complete, I'd like to
switch the default language version for C compilation to -std=gnu23.
This requires updating a large number of testcases that fail with the
new language version if left unchanged. In this patch, update most of
the tests for which there is a safe change that works both before and
after the update to default language version - typically adding the
option -std=gnu17 or -Wno-old-style-definition to the tests. (There
are also a few tests where I'd like to investigate further why they
fail with -std=gnu23, or where I think such failures show an actual
bug to fix before changing the default language version, or where it
seems more appropriate to make a testcase change that would result in
failures in the absence of the language version change rather than
just adding an option that does nothing with the gnu17 default.)
The libffi test fixes have also been submitted upstream:
<https://github.com/libffi/libffi/pull/861>.
Most of the failures requiring such changes are for one of two
reasons:
* Unprototyped function declarations with () (meaning the same as
(void) in C23 mode) for a function then called with arguments.
* Old-style function definitions, which warn by default in C23 mode,
so resulting in test failures for the unexpected warnings.
Other reasons for failures include:
* Tests with their own definitions of bool, true and false.
* Tests of diagnostics (often with -pedantic) in cases where C23 has
changed semantics, such as:
- tag compatibility for structs;
- enum values out of range of int;
- handing of qualified array types;
- decimal floating types formerly needing -pedantic diagnostics, but
being standard in C23.
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
gcc/testsuite/
* c-c++-common/Wcast-function-type.c: Add -std=gnu17 for C.
* c-c++-common/Wformat-pr84258.c: Add -std=gnu17 for C.
* c-c++-common/Wvarargs.c: Add -std=gnu17 for C.
* c-c++-common/analyzer/data-model-12.c: Add -std=gnu17 for C.
* c-c++-common/builtins.c: Add -std=gnu17 for C.
* c-c++-common/pointer-to-fn1.c: Add -std=gnu17 for C.
* c-c++-common/pragma-diag-17.c: Add -std=gnu17 for C.
* c-c++-common/sizeof-array-argument.c: Add
-Wno-old-style-definition for C.
* g++.dg/lto/pr54625-1_0.c: Add -std=gnu17.
* g++.dg/lto/pr54625-2_0.c: Add -std=gnu17.
* gcc.c-torture/compile/20040214-2.c: Add -std=gnu17.
* gcc.c-torture/compile/921011-2.c: Add -std=gnu17.
* gcc.c-torture/compile/931102-1.c: Add -std=gnu17.
* gcc.c-torture/compile/990801-1.c: Add -std=gnu17.
* gcc.c-torture/compile/nested-1.c: Add -std=gnu17.
* gcc.c-torture/compile/pr100241-1.c: Add -std=gnu17.
* gcc.c-torture/compile/pr106101.c: Add -std=gnu17.
* gcc.c-torture/compile/pr113616.c: Add -std=gnu17.
* gcc.c-torture/compile/pr47967.c: Add -std=gnu17.
* gcc.c-torture/compile/pr51694.c: Add -std=gnu17.
* gcc.c-torture/compile/pr71109.c: Add -std=gnu17.
* gcc.c-torture/compile/pr83051-2.c: Add -std=gnu17.
* gcc.c-torture/compile/pr89663-1.c: Add -std=gnu17.
* gcc.c-torture/compile/pr94238.c: Add -std=gnu17.
* gcc.c-torture/compile/pr96796.c: Add -std=gnu17.
* gcc.c-torture/compile/pr97576.c: Add -std=gnu17.
* gcc.c-torture/compile/udivmod4.c: Add -std=gnu17.
* gcc.c-torture/execute/20010605-2.c: Add -std=gnu17.
* gcc.c-torture/execute/20020404-1.c: Add -std=gnu17.
* gcc.c-torture/execute/20030714-1.c: Add -std=gnu17.
* gcc.c-torture/execute/20051012-1.c: Add -std=gnu17.
* gcc.c-torture/execute/20190820-1.c: Add -std=gnu17.
* gcc.c-torture/execute/920612-1.c: Add -Wno-old-style-definition.
* gcc.c-torture/execute/930608-1.c: Add -std=gnu17.
* gcc.c-torture/execute/comp-goto-1.c: Add -std=gnu17.
* gcc.c-torture/execute/ieee/fp-cmp-1.x: Add -std=gnu17.
* gcc.c-torture/execute/ieee/fp-cmp-2.x: Add -std=gnu17.
* gcc.c-torture/execute/ieee/fp-cmp-3.x: Add -std=gnu17.
* gcc.c-torture/execute/ieee/fp-cmp-4.x: New file.
* gcc.c-torture/execute/ieee/fp-cmp-4f.x: New file.
* gcc.c-torture/execute/ieee/fp-cmp-4l.x: New file.
* gcc.c-torture/execute/loop-9.c: Add -std=gnu17.
* gcc.c-torture/execute/pr103209.c: Add -std=gnu17.
* gcc.c-torture/execute/pr28289.c: Add -std=gnu17.
* gcc.c-torture/execute/pr34982.c: Add -std=gnu17.
* gcc.c-torture/execute/pr67037.c: Add -std=gnu17.
* gcc.c-torture/execute/va-arg-2.c: Add -std=gnu17.
* gcc.dg/20010202-1.c: Add -std=gnu17.
* gcc.dg/20020430-1.c: Add -std=gnu17.
* gcc.dg/20031218-3.c: Add -std=gnu17.
* gcc.dg/20040127-1.c: Add -std=gnu17.
* gcc.dg/20041014-1.c: Add -Wno-old-style-definition.
* gcc.dg/20041122-1.c: Add -std=gnu17.
* gcc.dg/20050309-1.c: Add -std=gnu17.
* gcc.dg/20061026.c: Add -std=gnu17.
* gcc.dg/20101010-1.c: Add -std=gnu17.
* gcc.dg/Warray-parameter-10.c: Add -std=gnu17.
* gcc.dg/Wbuiltin-declaration-mismatch-2.c: Add -std=gnu17.
* gcc.dg/Wbuiltin-declaration-mismatch-3.c: Add -std=gnu17.
* gcc.dg/Wbuiltin-declaration-mismatch-4.c: Add -std=gnu17.
* gcc.dg/Wbuiltin-declaration-mismatch-5.c: Add -std=gnu17.
* gcc.dg/Wbuiltin-declaration-mismatch.c: Add -std=gnu17.
* gcc.dg/Wcxx-compat-2.c: Add -std=gnu17.
* gcc.dg/Wdouble-promotion.c: Add -std=gnu17.
* gcc.dg/Wfree-nonheap-object-7.c: Add -std=gnu17.
* gcc.dg/Wimplicit-int-1.c: Add -std=gnu17.
* gcc.dg/Wimplicit-int-1a.c: Add -std=gnu17.
* gcc.dg/Wimplicit-int-2.c: Add -std=gnu17.
* gcc.dg/Wimplicit-int-3.c: Add -std=gnu17.
* gcc.dg/Wimplicit-int-4.c: Add -std=gnu17.
* gcc.dg/Wimplicit-int-4a.c: Add -std=gnu17.
* gcc.dg/Wincompatible-pointer-types-1.c: Add -std=gnu17.
* gcc.dg/Wrestrict-19.c: Add -std=gnu17.
* gcc.dg/Wrestrict-4.c: Add -std=gnu17.
* gcc.dg/Wrestrict-5.c: Add -std=gnu17.
* gcc.dg/Wstrict-overflow-20.c: Add -std=gnu17.
* gcc.dg/Wstringop-overflow-13.c: Add -std=gnu17.
* gcc.dg/analyzer/doom-d_main-IdentifyVersion.c: Add -std=gnu17.
* gcc.dg/analyzer/doom-s_sound-pr108867.c: Add -std=gnu17.
* gcc.dg/analyzer/pr93032-mztools-signed-char.c: Add
-Wno-old-style-definition.
* gcc.dg/analyzer/pr93032-mztools-unsigned-char.c: Add
-Wno-old-style-definition.
* gcc.dg/analyzer/pr93355-localealias.c: Add
-Wno-old-style-definition.
* gcc.dg/analyzer/pr93375.c: Add -std=gnu17.
* gcc.dg/analyzer/pr94688.c: Add -std=gnu17.
* gcc.dg/analyzer/sensitive-1.c: Add -std=gnu17.
* gcc.dg/analyzer/torture/asm-x86-linux-wfx_get_ps_timeout-full.c:
Add -std=gnu17.
* gcc.dg/analyzer/torture/pr104863.c: Add -std=gnu17.
* gcc.dg/analyzer/torture/pr93379.c: Add -std=gnu17.
* gcc.dg/array-quals-2.c: Add -std=gnu17.
* gcc.dg/attr-invalid.c: Add -Wno-old-style-definition.
* gcc.dg/auto-init-uninit-A.c: Add -Wno-old-style-definition.
* gcc.dg/builtin-choose-expr.c: Declare exit with (int) prototype.
* gcc.dg/builtin-tgmath-err-1.c: Add -std=gnu17.
* gcc.dg/builtins-30.c: Add -std=gnu17.
* gcc.dg/cast-function-1.c: Add -std=gnu17.
* gcc.dg/cleanup-1.c: Add -std=gnu17.
* gcc.dg/compat/struct-complex-1_x.c: Add -std=gnu17.
* gcc.dg/compat/struct-complex-2_x.c: Add -std=gnu17.
* gcc.dg/compat/union-m128-1_x.c: Add -std=gnu17.
* gcc.dg/debug/dwarf2/pr66482.c: Add -std=gnu17.
* gcc.dg/dfp/composite-type-2.c: Add -std=gnu17.
* gcc.dg/dfp/composite-type.c: Add -std=gnu17.
* gcc.dg/dfp/keywords-pedantic.c: Add -std=gnu17.
* gcc.dg/dremf-type-compat-1.c: Add -std=gnu17.
* gcc.dg/dremf-type-compat-2.c: Add -std=gnu17.
* gcc.dg/dremf-type-compat-3.c: Add -std=gnu17.
* gcc.dg/dremf-type-compat-4.c: Add -std=gnu17.
* gcc.dg/enum-compat-1.c: Add -std=gnu17.
* gcc.dg/enum-compat-2.c: Add -std=gnu17.
* gcc.dg/floatn-errs.c: Add -std=gnu17.
* gcc.dg/fltconst-pedantic-dfp.c: Add -std=gnu17.
* gcc.dg/format/proto.c: Add -std=gnu17.
* gcc.dg/format/sentinel-1.c: Add -std=gnu17.
* gcc.dg/gomp/declare-simd-1.c: Add -Wno-old-style-definition.
* gcc.dg/ifelse-1.c: Add -Wno-old-style-definition.
* gcc.dg/inline-33.c: Add -std=gnu17.
* gcc.dg/ipa/inline-5.c: Add -std=gnu17.
* gcc.dg/ipa/ipa-sra-21.c: Add -std=gnu17.
* gcc.dg/ipa/pr102714.c: Add -std=gnu17.
* gcc.dg/ipa/pr104813.c: Add -std=gnu17.
* gcc.dg/ipa/pr108679.c: Add -std=gnu17.
* gcc.dg/ipa/pr42706.c: Add -std=gnu17.
* gcc.dg/ipa/pr88214.c: Add -Wno-old-style-definition.
* gcc.dg/ipa/pr91853.c: Add -Wno-old-style-definition.
* gcc.dg/ipa/pr93763.c: Add -std=gnu17.
* gcc.dg/ipa/pr96482-2.c: Add -std=gnu17.
* gcc.dg/lto/20091013-1_2.c: Add -std=gnu17.
* gcc.dg/lto/20091015-1_2.c: Add -std=gnu17.
* gcc.dg/lto/pr113197_1.c: Add -std=gnu17.
* gcc.dg/lto/pr54702_1.c: Add -std=gnu17.
* gcc.dg/lto/pr99849_0.c: Add -std=gnu17.
* gcc.dg/noncompile/920923-1.c: Add -std=gnu17.
* gcc.dg/noncompile/old-style-parm-1.c: Add
-Wno-old-style-definition.
* gcc.dg/noncompile/old-style-parm-3.c: Add
-Wno-old-style-definition.
* gcc.dg/noncompile/pr30552-2.c: Add -Wno-old-style-definition.
* gcc.dg/noncompile/pr30552-3.c: Add -std=gnu17.
* gcc.dg/noncompile/pr71265.c: Add -Wno-old-style-definition.
* gcc.dg/noncompile/pr79758-2.c: Add -Wno-old-style-definition.
* gcc.dg/noncompile/pr79758.c: Add -Wno-old-style-definition.
* gcc.dg/noncompile/va-arg-1.c: Add -std=gnu17.
* gcc.dg/old-style-prom-1.c: Add -std=gnu17.
* gcc.dg/old-style-prom-2.c: Add -std=gnu17.
* gcc.dg/old-style-prom-3.c: Add -std=gnu17.
* gcc.dg/old-style-then-proto-1.c: Add -std=gnu17.
* gcc.dg/parm-incomplete-1.c: Add -std=gnu17.
* gcc.dg/parm-mismatch-1.c: Add -std=gnu17.
* gcc.dg/permerror-default.c: Add -std=gnu17.
* gcc.dg/permerror-fpermissive-nowarning.c: Add -std=gnu17.
* gcc.dg/permerror-fpermissive.c: Add -std=gnu17.
* gcc.dg/permerror-noerror.c: Add -std=gnu17.
* gcc.dg/permerror-nowarning.c: Add -std=gnu17.
* gcc.dg/permerror-pedantic.c: Add -std=gnu17.
* gcc.dg/plugin/infoleak-net-ethtool-ioctl.c: Add -std=gnu17.
* gcc.dg/pointer-array-quals-1.c: Add -std=gnu17.
* gcc.dg/pointer-array-quals-2.c: Add -std=gnu17.
* gcc.dg/pr100791.c: Add -std=gnu17.
* gcc.dg/pr100843.c: Add -std=gnu17.
* gcc.dg/pr102273.c: Add -std=gnu17.
* gcc.dg/pr102385.c: Add -std=gnu17.
* gcc.dg/pr103222.c: Add -std=gnu17.
* gcc.dg/pr105140.c: Add -std=gnu17.
* gcc.dg/pr105150.c: Add -std=gnu17.
* gcc.dg/pr105250.c: Add -std=gnu17.
* gcc.dg/pr105972.c: Add -Wno-old-style-definition.
* gcc.dg/pr111039.c: Add -std=gnu17.
* gcc.dg/pr111407.c: Add -std=gnu17.
* gcc.dg/pr111922.c: Add -Wno-old-style-definition.
* gcc.dg/pr15236.c: Add -std=gnu17.
* gcc.dg/pr17188-1.c: Add -std=gnu17.
* gcc.dg/pr20368-1.c: Add -std=gnu17.
* gcc.dg/pr20368-2.c: Add -std=gnu17.
* gcc.dg/pr20368-3.c: Add -std=gnu17.
* gcc.dg/pr27331.c: Add -Wno-old-style-definition.
* gcc.dg/pr27861-1.c: Add -std=gnu17.
* gcc.dg/pr28121.c: Add -std=gnu17.
* gcc.dg/pr28243.c: Add -std=gnu17.
* gcc.dg/pr28888.c: Add -std=gnu17.
* gcc.dg/pr29254.c: Add -std=gnu17.
* gcc.dg/pr34457-1.c: Add -std=gnu17.
* gcc.dg/pr36015.c: Add -std=gnu17.
* gcc.dg/pr38245-3.c: Add -std=gnu17.
* gcc.dg/pr38245-4.c: Add -std=gnu17.
* gcc.dg/pr41241.c: Add -std=gnu17.
* gcc.dg/pr43058.c: Add -std=gnu17.
* gcc.dg/pr44539.c: Add -std=gnu17.
* gcc.dg/pr45055.c: Add -std=gnu17.
* gcc.dg/pr50908.c: Add -Wno-old-style-definition.
* gcc.dg/pr60647-1.c: Add -Wno-old-style-definition.
* gcc.dg/pr63762.c: Add -std=gnu17.
* gcc.dg/pr63804.c: Add -std=gnu17.
* gcc.dg/pr68306-3.c: Add -std=gnu17.
* gcc.dg/pr68533.c: Add -std=gnu17.
* gcc.dg/pr69156.c: Add -std=gnu17.
* gcc.dg/pr7356-2.c: Add -Wno-old-style-definition.
* gcc.dg/pr79983.c: Add -std=gnu17.
* gcc.dg/pr83463.c: Add -std=gnu17.
* gcc.dg/pr87347.c: Add -std=gnu17.
* gcc.dg/pr89521-1.c: Add -std=gnu17.
* gcc.dg/pr89521-2.c: Add -std=gnu17.
* gcc.dg/pr90648.c: Add -std=gnu17.
* gcc.dg/pr93573-1.c: Add -std=gnu17.
* gcc.dg/pr94167.c: Add -std=gnu17.
* gcc.dg/pr94705.c: Add -std=gnu17.
* gcc.dg/pr95118.c: Add -std=gnu17.
* gcc.dg/pr96335.c: Add -std=gnu17.
* gcc.dg/pr97830.c: Add -std=gnu17.
* gcc.dg/pr97882.c: Add -std=gnu17.
* gcc.dg/pr99122-2.c: Add -std=gnu17.
* gcc.dg/pr99122-3.c: Add -std=gnu17.
* gcc.dg/qual-component-1.c: Add -std=gnu17.
* gcc.dg/sibcall-6.c: Add -Wno-old-style-definition.
* gcc.dg/sms-2.c: Add -Wno-old-style-definition.
* gcc.dg/tm/20091221.c: Add -std=gnu17.
* gcc.dg/torture/bfloat16-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float128-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float128x-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float16-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float32-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float32x-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float64-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float64x-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/pr102762.c: Add -std=gnu17.
* gcc.dg/torture/pr103987.c: Add -std=gnu17.
* gcc.dg/torture/pr104825.c: Add -Wno-old-style-definition.
* gcc.dg/torture/pr105166.c: Add -std=gnu17.
* gcc.dg/torture/pr105185.c: Add -Wno-old-style-definition.
* gcc.dg/torture/pr109652.c: Add -std=gnu17.
* gcc.dg/torture/pr112444.c: Add -std=gnu17.
* gcc.dg/torture/pr113895-3.c: Add -std=gnu17.
* gcc.dg/torture/pr24626-2.c: Add -std=gnu17.
* gcc.dg/torture/pr25183.c: Add -std=gnu17.
* gcc.dg/torture/pr38948.c: Add -std=gnu17.
* gcc.dg/torture/pr44807.c: Add -std=gnu17.
* gcc.dg/torture/pr47281.c: Add -std=gnu17.
* gcc.dg/torture/pr47958-1.c: Add -Wno-old-style-definition.
* gcc.dg/torture/pr48063.c: Add -std=gnu17.
* gcc.dg/torture/pr57036-1.c: Add -std=gnu17.
* gcc.dg/torture/pr57330.c: Add -std=gnu17.
* gcc.dg/torture/pr57584.c: Add -std=gnu17.
* gcc.dg/torture/pr67741.c: Add -std=gnu17.
* gcc.dg/torture/pr68104.c: Add -std=gnu17.
* gcc.dg/torture/pr69242.c: Add -std=gnu17.
* gcc.dg/torture/pr70457.c: Add -std=gnu17.
* gcc.dg/torture/pr70985.c: Add -std=gnu17.
* gcc.dg/torture/pr71606.c: Add -std=gnu17.
* gcc.dg/torture/pr71816.c: Add -std=gnu17.
* gcc.dg/torture/pr77286.c: Add -std=gnu17.
* gcc.dg/torture/pr77646.c: Add -std=gnu17.
* gcc.dg/torture/pr77677-2.c: Add -std=gnu17.
* gcc.dg/torture/pr78365.c: Add -Wno-old-style-definition.
* gcc.dg/torture/pr79732.c: Add -std=gnu17.
* gcc.dg/torture/pr80612.c: Add -std=gnu17.
* gcc.dg/torture/pr80764.c: Add -std=gnu17.
* gcc.dg/torture/pr80842.c: Add -std=gnu17.
* gcc.dg/torture/pr81900.c: Add -std=gnu17.
* gcc.dg/torture/pr82276.c: Add -std=gnu17.
* gcc.dg/torture/pr84803.c: Add -std=gnu17.
* gcc.dg/torture/pr93124.c: Add -std=gnu17.
* gcc.dg/torture/pr97330-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-prof/comp-goto-1.c: Add -std=gnu17.
* gcc.dg/tree-ssa/20030703-2.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030708-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030709-2.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030709-3.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030710-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030711-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030711-2.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030711-3.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030714-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030714-2.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030728-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030807-10.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030807-11.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030807-3.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030807-6.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030807-7.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030814-4.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030814-5.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030814-6.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030918-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20040514-2.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/loadpre7.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/pr111003.c: Add -std=gnu17.
* gcc.dg/tree-ssa/pr115128.c: Add -std=gnu17.
* gcc.dg/tree-ssa/pr115191.c: Add -std=gnu17.
* gcc.dg/tree-ssa/pr24840.c: Add -std=gnu17.
* gcc.dg/tree-ssa/pr69666.c: Add -std=gnu17.
* gcc.dg/tree-ssa/pr70232.c: Add -std=gnu17.
* gcc.dg/ubsan/pr79757-1.c: Add -Wno-old-style-definition.
* gcc.dg/ubsan/pr79757-2.c: Add -Wno-old-style-definition.
* gcc.dg/ubsan/pr79757-3.c: Add -Wno-old-style-definition.
* gcc.dg/ubsan/pr81223.c: Add -std=gnu17.
* gcc.dg/uninit-10-O0.c: Add -Wno-old-style-definition.
* gcc.dg/uninit-10.c: Add -Wno-old-style-definition.
* gcc.dg/uninit-32.c: Add -std=gnu17.
* gcc.dg/uninit-41.c: Add -std=gnu17.
* gcc.dg/uninit-A-O0.c: Add -Wno-old-style-definition.
* gcc.dg/uninit-A.c: Add -Wno-old-style-definition.
* gcc.dg/unused-1.c: Add -Wno-old-style-definition.
* gcc.dg/vect/bb-slp-pr114249.c: Add -std=gnu17.
* gcc.dg/vect/bb-slp-pr97486.c: Add -std=gnu17.
* gcc.dg/vect/bb-slp-subgroups-1.c: Add -std=gnu17.
* gcc.dg/vect/bb-slp-subgroups-2.c: Add -std=gnu17.
* gcc.dg/vect/bb-slp-subgroups-3.c: Add -std=gnu17.
* gcc.dg/vect/vect-early-break_111-pr113731.c: Add -std=gnu17.
* gcc.dg/vect/vect-early-break_122-pr114239.c: Add -std=gnu17.
* gcc.dg/vect/vect-multi-peel-gaps.c: Add -std=gnu17.
* gcc.dg/vla-stexp-2.c: Add -std=gnu17.
* gcc.dg/warn-1.c: Add -Wno-old-style-definition.
* gcc.dg/winline-10.c: Add -Wno-old-style-definition.
* gcc.dg/wtr-label-1.c: Add -Wno-old-style-definition.
* gcc.dg/wtr-switch-1.c: Add -Wno-old-style-definition.
* gcc.target/i386/excess-precision-3.c: Add
-Wno-old-style-definition.
* gcc.target/i386/fma4-256-nmsubXX.c: Add -std=gnu17.
* gcc.target/i386/fma4-nmsubXX.c: Add -std=gnu17.
* gcc.target/i386/nop-mcount.c: Add -Wno-old-style-definition.
* gcc.target/i386/pr102627.c: Add -std=gnu17.
* gcc.target/i386/pr106994.c: Add -std=gnu17.
* gcc.target/i386/pr68349.c: Add -std=gnu17.
* gcc.target/i386/pr97313.c: Add -std=gnu17.
* gcc.target/i386/pr99454.c: Add -std=gnu17.
* gcc.target/i386/record-mcount.c: Add -Wno-old-style-definition.
libffi/
* testsuite/libffi.call/va_struct2.c (test_fn): Cast n to void.
* testsuite/libffi.call/va_struct3.c (test_fn): Likewise.
Backported from <https://github.com/libffi/libffi/pull/861>.
|
|
No functional change intended.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.c: Use success_call_info
in a couple of places to avoid reimplementing get_desc.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
GCC currently supports outputting SARIF v2.1.0
Version 2.2 of the SARIF spec is not yet official, but the draft has
already gained features we might might want to use.
This patch extends the SARIF output code to accept a enum sarif_version
parameter internally, representing 2.1.0 or a prerelease of 2.2
The patch updates the SARIF output selftests so that they are run for
all such versions.
I hope to expose this "properly" via the mechanism described
in comment #13 of PR116613. In the meantime, the patch adds a new
-fdiagnostics-format=sarif-file-2.2-prerelease
for use by the DejaGnu testsuite, deliberately left undocumented for
now.
The copy of the 2.2 draft schema in the testsuite was downloaded from
https://raw.githubusercontent.com/oasis-tcs/sarif-spec/refs/tags/2.2-prerelease-2024-08-08/sarif-2.2/schema/sarif-2-2.schema.json
The patch adds support for capturing related locations within an ICE
notification for SARIF 2.2 onwards, thus capturing "include chain"
information for SARIF-based reports of ICEs that occur within a
header; see https://github.com/oasis-tcs/sarif-spec/issues/540
The patch does *not* add support for the "scannedFile" role, leaving it
to followup work; see https://github.com/oasis-tcs/sarif-spec/issues/459
gcc/ChangeLog:
PR other/116301
* common.opt (sarif-file-2.2-prerelease): New value for
-fdiagnostics-format=.
* diagnostic-format-sarif.cc
(sarif_location_manager::sarif_location_manager): Move
initialization of m_related_locations_arr here from sarif_result's
ctor.
(sarif_location_manager::add_related_location): Implement for
base class, taking sarif_result's implementation. Add "builder"
param.
(sarif_location_manager::m_related_locations_arr): Move here from
class sarif_result.
(class sarif_result): Move m_related_locations_arr field and
add_related_location vfunc to class sarif_location_manager.
(sarif_builder::get_version): New accessor.
(sarif_builder::m_version): New field.
(sarif_invocation::add_notification_for_ice): Call
process_worklist on the notification for SARIF 2.2 and later.
(sarif_location_manager::process_worklist_item): Pass builder to
calls to add_related_location.
(sarif_result::on_nested_diagnostic): Likewise.
(sarif_result::on_diagram): Likewise.
(sarif_ice_notification::add_related_location): Add builder param.
For SARIF 2.2 and later chain up to base class impl so that
notifications get related locations.
(sarif_builder::sarif_builder): Add "version" param.
(SARIF_SCHEMA): Delete in favor of...
(sarif_version_to_url): New function.
(SARIF_VERSION): Delete in favor of...
(sarif_version_to_property): New function.
(make_top_level_object): Update to use m_version for "$schema" and
"version".
(sarif_output_format::sarif_output_format): Add "version" param.
(sarif_stream_output_format::sarif_stream_output_format):
Likewise.
(sarif_file_output_format::sarif_file_output_format): Likewise.
(diagnostic_output_format_init_sarif_stderr): Likewise.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
(selftest::test_sarif_diagnostic_context): Likewise.
(selftest::test_make_location_object): Likewise.
(selftest::test_simple_log): Likewise. Update schema and version
tests accordingly.
(selftest::test_simple_log_2): Add "version" param.
(selftest::test_message_with_embedded_link): Likewise.
(selftest::run_tests_per_version): New, based on the
for_each_line_table_case calls in...
(selftest::diagnostic_format_sarif_cc_tests): Add loop over sarif
versions. Replace for_each_line_table_case calls with one
call to run_tests_per_version.
* diagnostic-format-sarif.h: Include "diagnostic-format.h".
(enum class sarif_version): New.
(diagnostic_output_format_init_sarif_stderr): Move to here from
diagnostic-format.h. Add "version" param.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
* diagnostic-format.h: Include "diagnostic.h".
(diagnostic_output_format_init_sarif_stderr): Move from here to
diagnostic-format-sarif.h.
* diagnostic.cc: Define INCLUDE_MEMORY.
Include "diagnostic-format-sarif.h".
(diagnostic_output_format_init): Pass sarif_version::v2_1_0 to
existing SARIF options.
Add case DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE_2_2_PRERELEASE.
* diagnostic.h (enum diagnostics_output_format): Add
DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE_2_2_PRERELEASE.
gcc/testsuite/ChangeLog:
PR other/116301
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2.1.c: New test.
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2.2.c: New test.
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2_1.py: Support
script for new test.
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2_2.py: Likewise.
* gcc.dg/plugin/crash-test-ice-in-header.h: New header.
* gcc.dg/plugin/plugin.exp: Add the new tests.
* lib/sarif-schema-2.2-prerelease-2024-08-08.json: New schema
file.
* lib/scansarif.exp (verify-sarif-file): Add optional argument for
specifying which version of the schema to validate against,
supporting "2.1" and "2.2", defaulting to the former.
Update the test name to capture the version of the schema tested
against.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
the printer [PR116613]
As work towards supporting multiple diagnostic outputs (where each
output has its own pretty_printer), update diagnostic_show_locus
so that the pretty_printer must always be explicitly passed in.
No functional change intended.
gcc/c-family/ChangeLog:
PR other/116613
* c-format.cc (selftest::test_type_mismatch_range_labels):
Explicitly pass in dc.m_printer to diagnostic_show_locus.
gcc/ChangeLog:
PR other/116613
* diagnostic-show-locus.cc (diagnostic_context::maybe_show_locus):
Convert param "pp" from * to &. Drop logic for using the
context's m_printer when the param is null.
* diagnostic.h (diagnostic_context::maybe_show_locus): Convert
param "pp" from * to &.
(diagnostic_show_locus): Drop default "nullptr" value for pp
param. Assert that it and context are nonnull. Pass pp by
reference to maybe_show_locus.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/expensive_selftests_plugin.c (test_richloc):
Explicitly pass in dc.m_printer to diagnostic_show_locus.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
As work towards supporting multiple diagnostic outputs (where each
output has its own pretty_printer), avoid passing around
diagnostic_context to the various printing routines, so that we
can be more explicit about which pretty_printer is in use.
Introduce a set of "policy" classes that capture the parts of
diagnostic_context that are needed, and use these rather than
diagnostic_context *. Pass around pretty_printer & rather than
taking value from context. Split out the pretty_printer-using code
from class layout into a new class layout_printer, separating the
responsibilities of determining layout when quoting source versus
actually printing the source.
No functional change intended.
gcc/analyzer/ChangeLog:
PR other/116613
* program-point.cc (function_point::print_source_line): Replace
call to diagnostic_show_locus with a call to
diagnostic_source_print_policy::print.
gcc/ChangeLog:
PR other/116613
* diagnostic-format-json.cc (json_from_expanded_location): Replace
call to diagnostic_context::converted_column with call to
diagnostic_column_policy::converted_column.
* diagnostic-format-sarif.cc
(sarif_builder::make_location_object): Replace call to
diagnostic_show_locus with call to
diagnostic_source_print_policy::print.
* diagnostic-format-text.cc (get_location_text): Replace call to
diagnostic_context::get_location_text with call to
diagnostic_column_policy::get_location_text.
(diagnostic_text_output_format::report_current_module): Replace call
to diagnostic_context::converted_column with call to
diagnostic_column_policy::converted_column.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_output_format):
Initialize m_column_policy.
(diagnostic_text_output_format::get_column_policy): New.
(diagnostic_text_output_format::m_column_policy): New.
* diagnostic-path.cc (class path_print_policy): New.
(event_range::maybe_add_event): Replace diagnostic_context param
with path_print_policy.
(event_range::print): Convert "pp" from * to &. Convert first
param of start_span callback from diagnostic_context to
diagnostic_location_print_policy.
(path_summary::path_summary): Convert first param from
diagnostic_text_output_format to path_print_policy. Add
colorize param. Update for changes to
event_range::maybe_add_event.
(thread_event_printer::print_swimlane_for_event_range): Assert
that pp is non-null. Update for change to event_range::print.
(diagnostic_text_output_format::print_path): Pass
path_print_policy to path_summary's ctor.
(selftest::test_empty_path): Likewise.
(selftest::test_intraprocedural_path): Likewise.
(selftest::test_interprocedural_path_1): Likewise.
(selftest::test_interprocedural_path_2): Likewise.
(selftest::test_recursion): Likewise.
(selftest::test_control_flow_1): Likewise.
(selftest::test_control_flow_2): Likewise.
(selftest::test_control_flow_3): Likewise.
(selftest::assert_cfg_edge_path_streq): Likewise.
(selftest::test_control_flow_5): Likewise.
(selftest::test_control_flow_6): Likewise.
* diagnostic-show-locus.cc (colorizer::set_range): Update for
change to m_pp.
(colorizer::m_pp): Convert from * to &.
(class layout): Add friend class layout_printer and move various
decls to it.
(layout::m_pp): Drop field.
(layout::m_policy): Rename to...
(layout::m_char_policy): ...this.
(layout::m_colorizer): Move field to class layout_printer.
(layout::m_diagnostic_path_p): Drop field.
(class layout_printer): New class, by refactoring class layout.
(colorizer::colorizer): Convert "pp" param from * to &.
(colorizer::set_named_color): Update for above change.
(colorizer::begin_state): Likewise.
(colorizer::finish_state): Likewise.
(make_policy): Rename to...
(make_char_policy): ...this, and update param from
diagnostic_context to diagnostic_source_print_policy.
(layout::layout): Update param from diagnostic_context to
diagnostic_source_print_policy. Drop params "diagnostic_kind" and
"pp", moving these and other material to class layout_printer.
(layout::maybe_add_location_range): Update for renamed field.
(layout::print_gap_in_line_numbering): Convert to...
(layout_printer::print_gap_in_line_numbering): ...this.
(layout::calculate_x_offset_display): Update for renamed field.
(layout::print_source_line): Convert to...
(layout_printer::print_source_line): ...this.
(layout::print_leftmost_column): Convert to...
(layout_printer::print_leftmost_column): ...this.
(layout::start_annotation_line): Convert to...
(layout_printer::start_annotation_line): ...this.
(layout::print_annotation_line): Convert to...
(layout_printer::print_annotation_line): ...this.
(layout::print_any_labels): Convert to...
(layout_printer::print_any_labels): ...this.
(layout::print_leading_fixits): Convert to...
(layout_printer::print_leading_fixits): ...this.
(layout::print_trailing_fixits): Convert to...
(layout_printer::print_trailing_fixits): ...this.
(layout::print_newline): Convert to...
(layout_printer::print_newline): ...this.
(layout::get_state_at_point): Make const.
(layout::get_x_bound_for_row): Make const.
(layout::move_to_column): Convert to...
(layout_printer::move_to_column): ...this.
(layout::show_ruler): Convert to...
(layout_printer::show_ruler): ...this.
(layout::print_line): Convert to...
(layout_printer::print_line): ...this.
(layout::print_any_right_to_left_edge_lines): Convert to...
(layout_printer::print_any_right_to_left_edge_lines): ...this.
(layout::print_any_right_to_left_edge_lines): Likewise.
(layout_printer::layout_printer): New.
(layout::update_any_effects): Delete, moving logic to
layout_printer::print.
(gcc_rich_location::add_location_if_nearby): Update param from
diagnostic_context to diagnostic_source_print_policy. Add
overload taking a diagnostic_context.
(diagnostic_context::maybe_show_locus): Move handling of null
pretty_printer here, from layout ctor. Convert call to
diagnostic_context::show_locus to
diagnostic_source_print_policy::print.
(diagnostic_source_print_policy::diagnostic_source_print_policy):
New.
(diagnostic_context::show_locus): Convert to...
(diagnostic_source_print_policy::print): ...this. Convert pp
from * to &.
(layout_printer::print): New, based on material in
diagnostic_context::show_locus.
(selftest::make_char_policy): New.
(selftest::test_display_widths): Update for above changes.
(selftest::test_offset_impl): Likewise.
(selftest::test_layout_x_offset_display_utf8): Likewise.
(selftest::test_layout_x_offset_display_tab): Likewise.
(selftest::test_diagnostic_show_locus_unknown_location): Use
test_diagnostic_context::test_show_locus rather than
diagnostic_show_locus.
(selftest::test_one_liner_no_column): Likewise.
(selftest::test_one_liner_caret_and_range): Likewise.
(selftest::test_one_liner_multiple_carets_and_ranges): Likewise.
(selftest::test_one_liner_fixit_insert_before): Likewise.
(selftest::test_one_liner_fixit_insert_after): Likewise.
(selftest::test_one_liner_fixit_remove): Likewise.
(selftest::test_one_liner_fixit_replace): Likewise.
(selftest::test_one_liner_fixit_replace_non_equal_range):
Likewise.
(selftest::test_one_liner_fixit_replace_equal_secondary_range):
Likewise.
(selftest::test_one_liner_fixit_validation_adhoc_locations):
Likewise.
(selftest::test_one_liner_many_fixits_1): Likewise.
(selftest::test_one_liner_many_fixits_2): Likewise.
(selftest::test_one_liner_labels): Likewise.
(selftest::test_one_liner_simple_caret_utf8): Likewise.
(selftest::test_one_liner_caret_and_range_utf8): Likewise.
(selftest::test_one_liner_multiple_carets_and_ranges_utf8):
Likewise.
(selftest::test_one_liner_fixit_insert_before_utf8): Likewise.
(selftest::test_one_liner_fixit_insert_after_utf8): Likewise.
(selftest::test_one_liner_fixit_remove_utf8): Likewise.
(selftest::test_one_liner_fixit_replace_utf8): Likewise.
(selftest::test_one_liner_fixit_replace_non_equal_range_utf8):
Likewise.
(selftest::test_one_liner_fixit_replace_equal_secondary_range_utf8):
Likewise.
(selftest::test_one_liner_fixit_validation_adhoc_locations_utf8):
Likewise.
(selftest::test_one_liner_many_fixits_1_utf8): Likewise.
(selftest::test_one_liner_many_fixits_2_utf8): Likewise.
(selftest::test_one_liner_labels_utf8): Likewise.
(selftest::test_one_liner_colorized_utf8): Likewise.
(selftest::test_add_location_if_nearby): Likewise.
(selftest::test_diagnostic_show_locus_fixit_lines): Likewise.
(selftest::test_overlapped_fixit_printing): Likewise.
(selftest::test_overlapped_fixit_printing_utf8): Likewise.
(selftest::test_overlapped_fixit_printing_2): Likewise.
(selftest::test_fixit_insert_containing_newline): Likewise.
(selftest::test_fixit_insert_containing_newline_2): Likewise.
(selftest::test_fixit_replace_containing_newline): Likewise.
(selftest::test_fixit_deletion_affecting_newline): Likewise.
(selftest::test_tab_expansion): Likewise.
(selftest::test_escaping_bytes_1): Likewise.
(selftest::test_escaping_bytes_2): Likewise.
(selftest::test_line_numbers_multiline_range): Likewise.
* diagnostic.cc
(diagnostic_column_policy::diagnostic_column_policy): New.
(diagnostic_context::converted_column): Convert to...
(diagnostic_column_policy::converted_column): ...this.
(diagnostic_context::get_location_text): Convert to...
(diagnostic_column_policy::get_location_text): ...this, adding
"show_column" param.
(diagnostic_location_print_policy::diagnostic_location_print_policy):
New ctors.
(default_diagnostic_start_span_fn): Convert param from
diagnostic_context * to const diagnostic_location_print_policy &.
Add "pp" param.
(selftest::assert_location_text): Update for above changes.
(selftest::test_diagnostic_get_location_text): Rename to...
(selftest::test_get_location_text): ...this.
(selftest::c_diagnostic_cc_tests): Update for renaming.
* diagnostic.h (class diagnostic_location_print_policy): New
forward decl.
(class diagnostic_source_print_policy): New forward decl.
(diagnostic_start_span_fn): Convert first param from
diagnostic_context * to const diagnostic_location_print_policy &
and add pretty_printer * param.
(class diagnostic_column_policy): New.
(class diagnostic_location_print_policy): New.
(class diagnostic_source_print_policy): New.
(class diagnostic_context): Add friend class
diagnostic_source_print_policy.
(diagnostic_context::converted_column): Drop decl in favor of
diagnostic_column_policy::converted_column.
(diagnostic_context::get_location_text): Drop decl in favor of
diagnostic_column_policy::get_location_text.
(diagnostic_context::show_locus): Drop decl in favor of
diagnostic_source_print_policy::print.
(default_diagnostic_start_span_fn): Update for change to
diagnostic_start_span_fn.
* gcc-rich-location.h (class diagnostic_source_print_policy): New
forward decl.
(gcc_rich_location::add_location_if_nearby): Convert first param
from diagnostic_context to diagnostic_source_print_policy. Add
overload taking diagnostic_context.
* selftest-diagnostic.cc
(selftest::test_diagnostic_context::test_diagnostic_context): Turn
off colorization.
(selftest::test_diagnostic_context::start_span_cb): Update for
change to callback type.
(test_diagnostic_context::test_show_locus): New.
* selftest-diagnostic.h
(selftest::test_diagnostic_context::start_span_cb): Update for
change to callback type.
(test_diagnostic_context::test_show_locus): New decl.
gcc/fortran/ChangeLog:
PR other/116613
* error.cc (gfc_diagnostic_build_locus_prefix): Convert first
param from diagnostic_context * to
const diagnostic_location_print_policy &. Add colorize param.
Likewise for the "two expanded_locations" overload.
(gfc_diagnostic_text_starter): Update for above changes.
(gfc_diagnostic_start_span): Update for change to callback type.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/diagnostic_group_plugin.c
(test_diagnostic_start_span_fn): Update for change to callback
type.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
As work towards supporting multiple diagnostic outputs (where each
output has its own pretty_printer), avoid using diagnostic_context's
m_printer field. Instead, use the output format's printer. Currently
this *is* the dc's printer, but eventually it might not be.
No functional change intended.
gcc/ChangeLog:
PR other/116613
* diagnostic-format-json.cc (diagnostic_output_format_init_json):
Pass in the format. Use the format's printer when disabling
colorization. Move the call to set_output_format into here.
(diagnostic_output_format_init_json_stderr): Update for above
change.
(diagnostic_output_format_init_json_file): Likewise.
* diagnostic-format-sarif.cc
(diagnostic_output_format_init_sarif): Use the format's printer
when disabling colorization.
* diagnostic-path.cc (selftest::test_empty_path): Use the
text_output's printer.
(selftest::test_intraprocedural_path): Likewise.
(selftest::test_interprocedural_path_1): Likewise.
(selftest::test_interprocedural_path_2): Likewise.
(selftest::test_recursion): Likewise.
(selftest::test_control_flow_1): Likewise.
(selftest::test_control_flow_2): Likewise.
(selftest::test_control_flow_3): Likewise.
(selftest::assert_cfg_edge_path_streq): Likewise.
(selftest::test_control_flow_5): Likewise.
(selftest::test_control_flow_6): Likewise.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/diagnostic_group_plugin.c
(test_output_format::on_begin_group): Use get_printer () rather
than accessing m_context.m_printer.
(test_output_format::on_end_group): Likewise.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c
(xhtml_builder::m_printer): New field.
(xhtml_builder::xhtml_builder): Add "pp" param and use it to
initialize m_printer.
(xhtml_builder::on_report_diagnostic): Drop "context" param.
(xhtml_builder::make_element_for_diagnostic): Likewise. Use
this->m_printer rather than the context's m_printer. Pass
m_printer to call to diagnostic_show_locus.
(xhtml_builder::emit_diagram): Drop "context" param.
(xhtml_output_format::on_report_diagnostic): Drop context param
from call to m_builder.
(xhtml_output_format::on_diagram): Likewise.
(xhtml_output_format::xhtml_output_format): Pass result of
get_printer as printer for builder.
(diagnostic_output_format_init_xhtml): Use the fmt's printer
rather than the context's.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Fix stray
reference to JSON.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This patch adds an experimental diagnostics output format that
writes HTML. It isn't ready yet for end-users, but seems worth
keeping in the tree as I refactor the diagnostics subsystem, to
ensure that this code still builds, and to verify that it's possible to
implement new diagnostic output formats via GCC plugins. Hence
this patch merely adds it to the testsuite as an example of a GCC
plugin, rather than exposing it as a feature for end-users.
gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/plugin/diagnostic-test-xhtml-1.c: New test.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: New test plugin.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
The diagnostic_starter and diagnostic_finalizer callbacks and most of
their support subroutines are only used by the "text" output format.
Emphasize this and reduce the binding with diagnostic_context
by renaming the callbacks to add "_text" in their names, and converting
the first param from diagnostic_context * to
diagnostic_text_output_output &. Update the various subroutines used
by diagnostic starter/finalizer callbacks to also take a
diagnostic_text_output_output & rather than a diagnostic_context *.
Move m_includes and m_last_seen from the context to the text output.
Use the text_output's get_printer () rather than the context's
m_printer, which should ease the transition to multiple output sinks.
No functional change intended.
gcc/c-family/ChangeLog:
PR other/116613
* c-opts.cc: Include "diagnostic-format-text.h".
(c_diagnostic_finalizer): Rename to...
(c_diagnostic_text_finalizer): ...this. Convert first param
from diagnostic_context * to diagnostic_text_output_format & and
update accordingly.
(c_common_diagnostics_set_defaults): Update for renamings.
gcc/ChangeLog:
PR other/116613
* coretypes.h (class diagnostic_text_output_format): Add forward
decl.
* diagnostic-format-json.cc
(json_output_format::after_diagnostic): New.
* diagnostic-format-sarif.cc
(sarif_output_format::after_diagnostic): New.
* diagnostic-format-text.cc: Use pragmas to ignore -Wformat-diag.
(diagnostic_text_output_format::~diagnostic_text_output_format):
Use get_printer. Clean up m_includes_seen here, rather than
in ~diagnostic_context.
(diagnostic_text_output_format::on_report_diagnostic): Use
get_printer. Update for callback renamings and pass *this
to them, rather than &m_context.
(diagnostic_text_output_format::after_diagnostic): New.
(diagnostic_text_output_format::includes_seen_p): Move here
from diagnostic_context/diagnostic.cc.
(diagnostic_text_output_format::get_location_text): New.
(maybe_line_and_column): Move here from diagnostic.cc and make
non-static.
(diagnostic_text_output_format::report_current_module): Move
here from diagnostic_context/diagnostic.cc.
(default_diagnostic_text_starter): Move here from diagnostic.cc,
renaming from default_diagnostic_starter.
(default_diagnostic_text_finalizer): Likewise, renaming from
default_diagnostic_finalizer.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Initialize m_last_module and m_includes_seen.
(diagnostic_text_output_format::after_diagnostic): New decl.
(diagnostic_text_output_format::build_prefix): New decl.
(diagnostic_text_output_format::report_current_module): New decl.
(diagnostic_text_output_format::append_note): New decl.
(diagnostic_text_output_format::file_name_as_prefix): New decl.
(diagnostic_text_output_format::print_path): New decl.
(diagnostic_text_output_format::show_column_p): New decl.
(diagnostic_text_output_format::get_location_text): New decl.
(diagnostic_text_output_format::includes_seen_p): New decl.
(diagnostic_text_output_format::show_any_path): New decl.
(diagnostic_text_output_format::m_last_module): New field.
(diagnostic_text_output_format::m_includes_seen): New field.
* diagnostic-format.h
(diagnostic_output_format::after_diagnostic): New vfunc.
(diagnostic_output_format::get_context): New.
(diagnostic_output_format::get_diagram_theme): New.
* diagnostic-macro-unwinding.cc: Include
"diagnostic-format-text.h".
(maybe_unwind_expanded_macro_loc): Convert first param from
diagnostic_context * to diagnostic_text_output_format & and update
accordingly.
(virt_loc_aware_diagnostic_finalizer): Likewise.
* diagnostic-macro-unwinding.h
(virt_loc_aware_diagnostic_finalizer): Likewise.
(maybe_unwind_expanded_macro_loc): Likewise.
* diagnostic-path.cc: Include "diagnostic-format-text.h".
(path_label::path_label): Drop "ctxt" param and add "colorize"
and "allow_emojis" params. Update initializations.
(path_label::get_text): Use m_colorize rather than querying
m_ctxt.m_printer. Use m_allow_emojis rather than querying
m_ctxt's diagram theme.
(path_label::m_ctxt): Drop field.
(path_label::m_colorize): Drop field.
(path_label::m_allow_emojis): Drop field.
(event_range::event_range): Drop param "ctxt". Add params
"colorize_labels" and "allow_emojis".
(event_range::print): Convert first param from
diagnostic_context & to diagnostic_text_output_format & and update
accordingly.
(path_summary::path_summary): Likewise.
(path_summary::print_swimlane_for_event_range): Likewise.
(print_path_summary_as_text): Likewise for 3rd param.
(diagnostic_context::print_path): Convert to...
(diagnostic_text_output_format::print_path): ...this.
(selftest::test_empty_path): Update to use a
diagnostic_text_output_format.
(selftest::test_intraprocedural_path): Likewise.
(selftest::test_interprocedural_path_1): Likewise.
(selftest::test_interprocedural_path_2): Likewise.
(selftest::test_recursion): Likewise.
(selftest::test_control_flow_1): Likewise.
(selftest::test_control_flow_2): Likewise.
(selftest::test_control_flow_3): Likewise.
(selftest::assert_cfg_edge_path_streq): Likewise.
(selftest::test_control_flow_5): Likewise.
(selftest::test_control_flow_6): Likewise.
* diagnostic.cc (file_name_as_prefix): Convert to...
(diagnostic_text_output_format::file_name_as_prefix): ...this.
(diagnostic_context::initialize): Update for renamings.
Move m_last_module and m_includes_seen into text output.
(diagnostic_context::finish): Likewise.
(diagnostic_context::get_location_text): Add "colorize" param.
(diagnostic_build_prefix): Convert to...
(diagnostic_text_output_format::build_prefix): ...this.
(diagnostic_context::includes_seen_p): Move from here to
diagnostic_text_output_format/diagnostic-format-text.cc.
(diagnostic_context::report_current_module): Likewise.
(diagnostic_context::show_any_path): Convert to...
(diagnostic_text_output_format::show_any_path): ...this.
(default_diagnostic_starter): Rename and move to
diagnostic-format-text.cc.
(default_diagnostic_start_span_fn): Pass colorize bool
to get_location_text.
(default_diagnostic_finalizer): Rename and move to
diagnostic-format-text.cc.
(diagnostic_context::report_diagnostic): Replace call to
show_any_path with call to new output format "after_diagnostic"
vfunc, moving show_any_path call to the text output format.
(diagnostic_append_note): Convert to...
(diagnostic_text_output_format::append_note): ...this.
(selftest::assert_location_text): Pass in false for colorization.
* diagnostic.h (diagnostic_starter_fn): Rename to...
(diagnostic_text_starter_fn): ...this. Convert first param from
diagnostic_context * to diagnostic_text_output_format &.
(diagnostic_finalizer_fn, diagnostic_text_finalizer_fn): Likewise.
(diagnostic_context): Update friends for renamings.
(diagnostic_context::report_current_module): Move to text output
format.
(diagnostic_context::get_location_text): Add "colorize" bool.
(diagnostic_context::includes_seen_p): Move to text output format.
(diagnostic_context::show_any_path): Likewise.
(diagnostic_context::print_path): Likewise.
(diagnostic_context::m_text_callbacks): Update for renamings.
(diagnostic_context::m_last_module): Move to text output format.
(diagnostic_context::m_includes_seen): Likewise.
(diagnostic_starter): Rename to...
(diagnostic_text_starter): ...this and update return type.
(diagnostic_finalizer): Rename to...
(diagnostic_text_finalizer): ...this and update return type.
(diagnostic_report_current_module): Drop decl in favor of a member
function of diagnostic_text_output_format.
(diagnostic_append_note): Likewise.
(default_diagnostic_starter): Rename to...
(default_diagnostic_text_starter): ...this, updating type.
(default_diagnostic_finalizer): Rename to...
(default_diagnostic_text_finalizer): ...this, updating type.
(file_name_as_prefix): Drop decl.
* langhooks-def.h (lhd_print_error_function): Convert first param
from diagnostic_context * to diagnostic_text_output_format &.
* langhooks.cc: Include "diagnostic-format-text.h".
(lhd_print_error_function): Likewise. Update accordingly
* langhooks.h (lang_hooks::print_error_function): Convert first
param from diagnostic_context * to
diagnostic_text_output_format &.
* tree-diagnostic.cc: Include "diagnostic-format-text.h".
(diagnostic_report_current_function): Convert first param from
diagnostic_context * to diagnostic_text_output_format & and update
accordingly.
(default_tree_diagnostic_starter): Rename to...
(default_tree_diagnostic_text_starter): ...this. Convert first
param from diagnostic_context * to diagnostic_text_output_format &
and update accordingly.
(tree_diagnostics_defaults): Update for renamings.
gcc/cp/ChangeLog:
PR other/116613
* cp-tree.h (cxx_print_error_function): Convert first param
from diagnostic_context * to diagnostic_text_output_format &.
* error.cc: Include "diagnostic-format-text.h".
(cxx_initialize_diagnostics): Update for renamings.
(cxx_print_error_function): Convert first param from
diagnostic_context * to diagnostic_text_output_format & and update
accordingly
(cp_diagnostic_starter): Rename to...
(cp_diagnostic_text_starter): ...this. Convert first
param from diagnostic_context * to diagnostic_text_output_format &
and update accordingly.
(cp_print_error_function): Likewise.
(print_instantiation_full_context): Likewise.
(print_instantiation_partial_context_line): Likewise.
(print_instantiation_partial_context): Likewise.
(maybe_print_instantiation_context): Likewise.
(maybe_print_constexpr_context): Likewise.
(print_location): Likewise.
(print_constrained_decl_info): Likewise.
(print_concept_check_info): Likewise.
(print_constraint_context_head): Likewise.
(print_requires_expression_info): Likewise.
(maybe_print_single_constraint_context): Likewise.
gcc/fortran/ChangeLog:
PR other/116613
* error.cc: Include "diagnostic-format-text.h".
(gfc_diagnostic_starter): Rename to...
(gfc_diagnostic_text_starter): ...this. Convert first
param from diagnostic_context * to diagnostic_text_output_format &
and update accordingly.
(gfc_diagnostic_finalizer, gfc_diagnostic_text_finalizer):
Likewise.
(gfc_diagnostics_init): Update for renamings.
(gfc_diagnostics_finish): Likewise.
gcc/jit/ChangeLog:
PR other/116613
* dummy-frontend.cc: Include "diagnostic-format-text.h".
(jit_begin_diagnostic): Convert first param from
diagnostic_context * to diagnostic_text_output_format &
(jit_end_diagnostic): Likewise. Update accordingly.
(jit_langhook_init): Update for renamings.
gcc/rust/ChangeLog:
PR other/116613
* resolve/rust-ast-resolve-expr.cc
(funny_ice_finalizer): : Convert first param from
diagnostic_context * to diagnostic_text_output_format &.
(ResolveExpr::visit): Update for renaming.
gcc/testsuite/ChangeLog:
PR other/116613
* g++.dg/plugin/show_template_tree_color_plugin.c
(noop_starter_fn): Rename to...
(noop_text_starter_fn): ...this. Update first param from dc to
text_output.
(plugin_init): Update for renamings.
* gcc.dg/plugin/diagnostic_group_plugin.c
(test_diagnostic_starter): Rename to...
(test_diagnostic_text_starter): ...this. Update first param from
dc to text_output.
(plugin_init): Update for renaming.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Include
"diagnostic-format-text.h".
(custom_diagnostic_finalizer): Rename to...
(custom_diagnostic_text_finalizer): ...this. Update first param
from dc to text_output.
(test_show_locus): Update for renamings.
* gcc.dg/plugin/location_overflow_plugin.c: Include
"diagnostic-format-text.h".
(original_finalizer): Rename to...
(original_text_finalizer): ...this and update type.
(verify_unpacked_ranges): Update first param from dc to
text_output. Update for this and for renamings.
(verify_no_columns): Likewise.
(plugin_init): Update for renamings.
libcc1/ChangeLog:
PR other/116613
* context.cc: Include "diagnostic-format-text.h".
(plugin_print_error_function): Update first param from
diagnostic_context * to diagnostic_text_output_format &.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Rename diagnostic_context's "printer" field to "m_printer",
for consistency with other fields, and to highlight places
where we currently use this, to help assess feasibility
of supporting multiple output sinks (PR other/116613).
No functional change intended.
gcc/ChangeLog:
PR other/116613
* attribs.cc (decls_mismatched_attributes): Rename
diagnostic_context's "printer" field to "m_printer".
(attr_access::array_as_string): Likewise.
* diagnostic-format-json.cc
(json_output_format::on_report_diagnostic): Likewise.
(diagnostic_output_format_init_json): Likewise.
* diagnostic-format-sarif.cc
(sarif_result::on_nested_diagnostic): Likewise.
(sarif_ice_notification): Likewise.
(sarif_builder::on_report_diagnostic): Likewise.
(sarif_builder::make_result_object): Likewise.
(sarif_builder::make_location_object): Likewise.
(sarif_builder::make_message_object_for_diagram): Likewise.
(diagnostic_output_format_init_sarif): Likewise.
* diagnostic-format-text.cc
(diagnostic_text_output_format::~diagnostic_text_output_format):
Likewise.
(diagnostic_text_output_format::on_report_diagnostic): Likewise.
(diagnostic_text_output_format::on_diagram): Likewise.
(diagnostic_text_output_format::print_any_cwe): Likewise.
(diagnostic_text_output_format::print_any_rules): Likewise.
(diagnostic_text_output_format::print_option_information):
Likewise.
* diagnostic-format.h (diagnostic_output_format::get_printer):
New.
* diagnostic-global-context.cc (verbatim): Rename
diagnostic_context's "printer" field to "m_printer".
* diagnostic-path.cc (path_label::get_text): Likewise.
(print_path_summary_as_text): Likewise.
(diagnostic_context::print_path): Likewise.
(selftest::test_empty_path): Likewise.
(selftest::test_intraprocedural_path): Likewise.
(selftest::test_interprocedural_path_1): Likewise.
(selftest::test_interprocedural_path_2): Likewise.
(selftest::test_recursion): Likewise.
(selftest::test_control_flow_1): Likewise.
(selftest::test_control_flow_2): Likewise.
(selftest::test_control_flow_3): Likewise.
(assert_cfg_edge_path_streq): Likewise.
(selftest::test_control_flow_5): Likewise.
(selftest::test_control_flow_6): Likewise.
* diagnostic-show-locus.cc (layout::layout): Likewise.
(selftest::test_layout_x_offset_display_utf8): Likewise.
(selftest::test_layout_x_offset_display_tab): Likewise.
(selftest::test_diagnostic_show_locus_unknown_location): Likewise.
(selftest::test_one_liner_simple_caret): Likewise.
(selftest::test_one_liner_no_column): Likewise.
(selftest::test_one_liner_caret_and_range): Likewise.
(selftest::test_one_liner_multiple_carets_and_ranges): Likewise.
(selftest::test_one_liner_fixit_insert_before): Likewise.
(selftest::test_one_liner_fixit_insert_after): Likewise.
(selftest::test_one_liner_fixit_remove): Likewise.
(selftest::test_one_liner_fixit_replace): Likewise.
(selftest::test_one_liner_fixit_replace_non_equal_range):
Likewise.
(selftest::test_one_liner_fixit_replace_equal_secondary_range):
Likewise.
(selftest::test_one_liner_fixit_validation_adhoc_locations):
Likewise.
(selftest::test_one_liner_many_fixits_1): Likewise.
(selftest::test_one_liner_many_fixits_2): Likewise.
(selftest::test_one_liner_labels): Likewise.
(selftest::test_one_liner_simple_caret_utf8): Likewise.
(selftest::test_one_liner_caret_and_range_utf8): Likewise.
(selftest::test_one_liner_multiple_carets_and_ranges_utf8):
Likewise.
(selftest::test_one_liner_fixit_insert_before_utf8): Likewise.
(selftest::test_one_liner_fixit_insert_after_utf8): Likewise.
(selftest::test_one_liner_fixit_remove_utf8): Likewise.
(selftest::test_one_liner_fixit_replace_utf8): Likewise.
(selftest::test_one_liner_fixit_replace_non_equal_range_utf8):
Likewise.
(selftest::test_one_liner_fixit_replace_equal_secondary_range_utf8):
Likewise.
(selftest::test_one_liner_fixit_validation_adhoc_locations_utf8):
Likewise.
(selftest::test_one_liner_many_fixits_1_utf8): Likewise.
(selftest::test_one_liner_many_fixits_2_utf8): Likewise.
(selftest::test_one_liner_labels_utf8): Likewise.
(selftest::test_one_liner_colorized_utf8): Likewise.
(selftest::test_add_location_if_nearby): Likewise.
(selftest::test_diagnostic_show_locus_fixit_lines): Likewise.
(selftest::test_overlapped_fixit_printing): Likewise.
(selftest::test_overlapped_fixit_printing_utf8): Likewise.
(selftest::test_overlapped_fixit_printing_2): Likewise.
(selftest::test_fixit_insert_containing_newline): Likewise.
(selftest::test_fixit_insert_containing_newline_2): Likewise.
(selftest::test_fixit_replace_containing_newline): Likewise.
(selftest::test_fixit_deletion_affecting_newline): Likewise.
(selftest::test_tab_expansion): Likewise.
(selftest::test_escaping_bytes_1): Likewise.
(selftest::test_escaping_bytes_2): Likewise.
(selftest::test_line_numbers_multiline_range): Likewise.
* diagnostic.cc (file_name_as_prefix): Likewise.
(diagnostic_set_caret_max_width): Likewise.
(diagnostic_context::initialize): Likewise.
(diagnostic_context::color_init): Likewise.
(diagnostic_context::urls_init): Likewise.
(diagnostic_context::finish): Likewise.
(diagnostic_context::get_location_text): Likewise.
(diagnostic_build_prefix): Likewise.
(diagnostic_context::report_current_module): Likewise.
(default_diagnostic_starter): Likewise.
(default_diagnostic_start_span_fn): Likewise.
(default_diagnostic_finalizer): Likewise.
(diagnostic_context::report_diagnostic): Likewise.
(diagnostic_append_note): Likewise.
(diagnostic_context::error_recursion): Likewise.
(fancy_abort): Likewise.
* diagnostic.h (diagnostic_context::set_show_highlight_colors):
Likewise.
(diagnostic_context::printer): Rename to...
(diagnostic_context::m_printer): ...this.
(diagnostic_format_decoder): Rename diagnostic_context's "printer"
field to "m_printer".
(diagnostic_prefixing_rule): Likewise.
(diagnostic_ready_p): Likewise.
* gimple-ssa-warn-access.cc (pass_waccess::maybe_warn_memmodel):
Likewise.
* langhooks.cc (lhd_print_error_function): Likewise.
* lto-wrapper.cc (print_lto_docs_link): Likewise.
* opts-global.cc (init_options_once): Likewise.
* opts.cc (common_handle_option): Likewise.
* simple-diagnostic-path.cc (simple_diagnostic_path_cc_tests):
Likewise.
* text-art/dump.h (dump_to_file<T>): Likewise.
* toplev.cc (announce_function): Likewise.
(toplev::main): Likewise.
* tree-diagnostic.cc (default_tree_diagnostic_starter): Likewise.
* tree.cc (escaped_string::escape): Likewise.
(selftest::test_escaped_strings): Likewise.
gcc/ada/ChangeLog:
PR other/116613
* gcc-interface/misc.cc (internal_error_function): Rename
diagnostic_context's "printer" field to "m_printer".
gcc/analyzer/ChangeLog:
PR other/116613
* access-diagram.cc (access_range::dump): Rename
diagnostic_context's "printer" field to "m_printer".
* analyzer-language.cc (on_finish_translation_unit): Likewise.
* analyzer.cc (make_label_text): Likewise.
(make_label_text_n): Likewise.
* call-details.cc (call_details::dump): Likewise.
* call-summary.cc (call_summary::dump): Likewise.
(call_summary_replay::dump): Likewise.
* checker-event.cc (checker_event::debug): Likewise.
* constraint-manager.cc (range::dump): Likewise.
(bounded_range::dump): Likewise.
(bounded_ranges::dump): Likewise.
(constraint_manager::dump): Likewise.
* diagnostic-manager.cc
(diagnostic_manager::emit_saved_diagnostic): Likewise.
* engine.cc (exploded_node::dump): Likewise.
(exploded_path::dump): Likewise.
(run_checkers): Likewise.
* kf-analyzer.cc (kf_analyzer_dump_escaped::impl_call_pre):
Likewise.
* pending-diagnostic.cc (evdesc::event_desc::formatted_print):
Likewise.
* program-point.cc (function_point::print_source_line): Likewise.
(program_point::dump): Likewise.
* program-state.cc (extrinsic_state::dump_to_file): Likewise.
(sm_state_map::dump): Likewise.
(program_state::dump_to_file): Likewise.
* ranges.cc (symbolic_byte_offset::dump): Likewise.
(symbolic_byte_range::dump): Likewise.
* region-model-reachability.cc (reachable_regions::dump): Likewise.
* region-model.cc (region_to_value_map::dump): Likewise.
(region_model::dump): Likewise.
(model_merger::dump): Likewise.
* region.cc (region_offset::dump): Likewise.
(region::dump): Likewise.
* sm-malloc.cc (deallocator_set::dump): Likewise.
(sufficiently_similar_p): Likewise.
* store.cc (uncertainty_t::dump): Likewise.
(binding_key::dump): Likewise.
(binding_map::dump): Likewise.
(binding_cluster::dump): Likewise.
(store::dump): Likewise.
* supergraph.cc (supergraph::dump_dot_to_file): Likewise.
(superedge::dump): Likewise.
* svalue.cc (svalue::dump): Likewise.
gcc/c-family/ChangeLog:
PR other/116613
* c-format.cc (selftest::test_type_mismatch_range_labels): Rename
diagnostic_context's "printer" field to "m_printer".
(selftest::test_type_mismatch_range_labels): Likewise.
* c-opts.cc (c_diagnostic_finalizer): Likewise.
gcc/c/ChangeLog:
PR other/116613
* c-objc-common.cc (c_initialize_diagnostics): Rename
diagnostic_context's "printer" field to "m_printer".
gcc/cp/ChangeLog:
PR other/116613
* error.cc (cxx_initialize_diagnostics): Rename
diagnostic_context's "printer" field to "m_printer".
(cxx_print_error_function): Likewise.
(cp_diagnostic_starter): Likewise.
(cp_print_error_function): Likewise.
(print_instantiation_full_context): Likewise.
(print_instantiation_partial_context_line): Likewise.
(maybe_print_constexpr_context): Likewise.
(print_location): Likewise.
(print_constrained_decl_info): Likewise.
(print_concept_check_info): Likewise.
(print_constraint_context_head): Likewise.
(print_requires_expression_info): Likewise.
* module.cc (noisy_p): Likewise.
gcc/d/ChangeLog:
PR other/116613
* d-diagnostic.cc (d_diagnostic_report_diagnostic): Rename
diagnostic_context's "printer" field to "m_printer".
gcc/fortran/ChangeLog:
PR other/116613
* error.cc (gfc_clear_pp_buffer): Rename diagnostic_context's
"printer" field to "m_printer".
(gfc_warning): Likewise.
(gfc_diagnostic_build_kind_prefix): Likewise.
(gfc_diagnostic_build_locus_prefix): Likewise.
(gfc_diagnostic_starter): Likewise.
(gfc_diagnostic_starter): Likewise.
(gfc_diagnostic_start_span): Likewise.
(gfc_diagnostic_finalizer): Likewise.
(gfc_warning_check): Likewise.
(gfc_error_opt): Likewise.
(gfc_error_check): Likewise.
gcc/jit/ChangeLog:
PR other/116613
* jit-playback.cc (add_diagnostic): Rename diagnostic_context's
"printer" field to "m_printer".
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/analyzer_cpython_plugin.c (dump_refcnt_info):
Update for renaming of field "printer" to "m_printer".
* gcc.dg/plugin/diagnostic_group_plugin.c
(test_diagnostic_starter): Likewise.
(test_diagnostic_start_span_fn): Likewise.
(test_output_format::on_begin_group): Likewise.
(test_output_format::on_end_group): Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_paths.c: Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(custom_diagnostic_finalizer): Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
We were using
https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json
as the URL for the SARIF 2.1 schema, but this is now a 404.
Update it to the URL listed in the spec (§3.13.3 "$schema property"),
which is:
https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json
and update the copy in
gcc/testsuite/lib/sarif-schema-2.1.0.json
used by the "verify-sarif-file" DejaGnu directive to the version found at
that latter URL; the sha256 sum changes
from: 2b19d2358baef0251d7d24e208d05ffabf1b2a3ab5e1b3a816066fc57fd4a7e8
to: c3b4bb2d6093897483348925aaa73af03b3e3f4bd4ca38cef26dcb4212a2682e
Doing so added a validation error on
c-c++-common/diagnostic-format-sarif-file-pr111700.c
for which we emit this textual output:
this-file-does-not-exist.c: warning: #warning message [-Wcpp]
with no line number, and these invalid SARIF regions within the
physical location of the warning:
"region": {"startColumn": 2,
"endColumn": 9},
"contextRegion": {}
This is due to this directive:
# 0 "this-file-does-not-exist.c"
with line number 0.
The patch fixes this by not creating regions that have startLine <= 0.
gcc/ChangeLog:
PR other/116603
* diagnostic-format-sarif.cc (SARIF_SCHEMA): Update URL.
(sarif_builder::maybe_make_region_object): Don't create regions
with startLine <= 0.
(sarif_builder::maybe_make_region_object_for_context): Likewise.
gcc/testsuite/ChangeLog:
PR other/116603
* gcc.dg/plugin/diagnostic-test-metadata-sarif.py (test_basics):
Update expected schema URL.
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py:
Likewise.
* gcc.dg/sarif-output/test-include-chain-1.py: Likewise.
* gcc.dg/sarif-output/test-include-chain-2.py: Likewise.
* gcc.dg/sarif-output/test-missing-semicolon.py: Likewise.
* gcc.dg/sarif-output/test-no-diagnostics.py: Likewise.
* gcc.dg/sarif-output/test-werror.py: Likewise.
* lib/sarif-schema-2.1.0.json: Update with copy downloaded from
https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
As preliminary work towards an overhaul of how optinfo_items
interact with dump_pretty_printer, replace uses of optinfo_item * with
std::unique_ptr<optinfo_item> to make ownership clearer.
No functional change intended.
gcc/ChangeLog:
* config/aarch64/aarch64.cc: Define INCLUDE_MEMORY.
* config/arm/arm.cc: Likewise.
* config/i386/i386.cc: Likewise.
* config/loongarch/loongarch.cc: Likewise.
* config/riscv/riscv-vector-costs.cc: Likewise.
* config/riscv/riscv.cc: Likewise.
* config/rs6000/rs6000.cc: Likewise.
* dump-context.h (dump_context::emit_item): Convert "item" param
from * to const &.
(dump_pretty_printer::stash_item): Convert "item" param from
optinfo_ * to std::unique_ptr<optinfo_item>.
(dump_pretty_printer::emit_item): Likewise.
* dumpfile.cc: Include "make-unique.h".
(make_item_for_dump_gimple_stmt): Replace uses of optinfo_item *
with std::unique_ptr<optinfo_item>.
(dump_context::dump_gimple_stmt): Likewise.
(make_item_for_dump_gimple_expr): Likewise.
(dump_context::dump_gimple_expr): Likewise.
(make_item_for_dump_generic_expr): Likewise.
(dump_context::dump_generic_expr): Likewise.
(make_item_for_dump_symtab_node): Likewise.
(dump_pretty_printer::emit_items): Likewise.
(dump_pretty_printer::emit_any_pending_textual_chunks): Likewise.
(dump_pretty_printer::emit_item): Likewise.
(dump_pretty_printer::stash_item): Likewise.
(dump_pretty_printer::decode_format): Likewise.
(dump_context::dump_printf_va): Fix overlong line.
(make_item_for_dump_dec): Replace uses of optinfo_item * with
std::unique_ptr<optinfo_item>.
(dump_context::dump_dec): Likewise.
(dump_context::dump_symtab_node): Likewise.
(dump_context::begin_scope): Likewise.
(dump_context::emit_item): Likewise.
* gimple-loop-interchange.cc: Define INCLUDE_MEMORY.
* gimple-loop-jam.cc: Likewise.
* gimple-loop-versioning.cc: Likewise.
* graphite-dependences.cc: Likewise.
* graphite-isl-ast-to-gimple.cc: Likewise.
* graphite-optimize-isl.cc: Likewise.
* graphite-poly.cc: Likewise.
* graphite-scop-detection.cc: Likewise.
* graphite-sese-to-poly.cc: Likewise.
* graphite.cc: Likewise.
* opt-problem.cc: Likewise.
* optinfo.cc (optinfo::add_item): Convert "item" param from
optinfo_ * to std::unique_ptr<optinfo_item>.
(optinfo::emit_for_opt_problem): Update for change to
dump_context::emit_item.
* optinfo.h: Add #error to fail immediately if INCLUDE_MEMORY
wasn't defined, rather than fail to find std::unique_ptr.
(optinfo::add_item): Convert "item" param from optinfo_ * to
std::unique_ptr<optinfo_item>.
* sese.cc: Define INCLUDE_MEMORY.
* targhooks.cc: Likewise.
* tree-data-ref.cc: Likewise.
* tree-if-conv.cc: Likewise.
* tree-loop-distribution.cc: Likewise.
* tree-parloops.cc: Likewise.
* tree-predcom.cc: Likewise.
* tree-ssa-live.cc: Likewise.
* tree-ssa-loop-ivcanon.cc: Likewise.
* tree-ssa-loop-ivopts.cc: Likewise.
* tree-ssa-loop-prefetch.cc: Likewise.
* tree-ssa-loop-unswitch.cc: Likewise.
* tree-ssa-phiopt.cc: Likewise.
* tree-ssa-threadbackward.cc: Likewise.
* tree-ssa-threadupdate.cc: Likewise.
* tree-vect-data-refs.cc: Likewise.
* tree-vect-generic.cc: Likewise.
* tree-vect-loop-manip.cc: Likewise.
* tree-vect-loop.cc: Likewise.
* tree-vect-patterns.cc: Likewise.
* tree-vect-slp-patterns.cc: Likewise.
* tree-vect-slp.cc: Likewise.
* tree-vect-stmts.cc: Likewise.
* tree-vectorizer.cc: Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/dump_plugin.c: Define INCLUDE_MEMORY.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
In particular, move the classic text output code to a
diagnostic-text.cc (analogous to -json.cc and -sarif.cc).
No functional change intended.
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add diagnostic-format-text.o.
* diagnostic-format-json.cc: Include "diagnostic-format.h".
* diagnostic-format-sarif.cc: Likewise.
* diagnostic-format-text.cc: New file, using material from
diagnostics.cc.
* diagnostic-global-context.cc: Include
"diagnostic-format.h".
* diagnostic-format-text.h: New file, using material from
diagnostics.h.
* diagnostic-format.h: New file, using material from
diagnostics.h.
* diagnostic.cc: Include "diagnostic-format.h" and
"diagnostic-format-text.h".
(diagnostic_text_output_format::~diagnostic_text_output_format):
Move to diagnostic-format-text.cc.
(diagnostic_text_output_format::on_report_diagnostic): Likewise.
(diagnostic_text_output_format::on_diagram): Likewise.
(diagnostic_text_output_format::print_any_cwe): Likewise.
(diagnostic_text_output_format::print_any_rules): Likewise.
(diagnostic_text_output_format::print_option_information):
Likewise.
* diagnostic.h (class diagnostic_output_format): Move to
diagnostic-format.h.
(class diagnostic_text_output_format): Move to
diagnostic-format-text.h.
(diagnostic_output_format_init): Move to
diagnostic-format.h.
(diagnostic_output_format_init_json_stderr): Likewise.
(diagnostic_output_format_init_json_file): Likewise.
(diagnostic_output_format_init_sarif_stderr): Likewise.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
* gcc.cc: Include "diagnostic-format.h".
* opts.cc: Include "diagnostic-format.h".
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic_group_plugin.c: Include
"diagnostic-format-text.h".
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Add test coverage of "%@" in event messages in a multithreaded
execution path.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c:
Update expected output.
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py:
Likewise.
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-separate-events.c:
Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_paths.c
(test_diagnostic_path::add_event_2): Return the id of the added
event.
(test_diagnostic_path::add_event_2_with_event_id): New.
(example_4): Add event IDs to the deadlock messages indicating
where the locks where acquired.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
In r15-2354-g4d1f71d49e396c I added the ability to use Python to write
tests of SARIF output via a new "run-sarif-pytest" based
on "run-gcov-pytest", with a sarif.py support script in
testsuite/gcc.dg/sarif-output.
This followup patch:
(a) removes the limitation of such tests needing to be in
testsuite/gcc.dg/sarif-output by moving sarif.py to testsuite/lib
and adding logic to add that directory to PYTHONPATH when invoking
pytest.
(b) uses this to replace fragile regexp-based tests in
gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.c with
Python logic that verifies the structure within the generated JSON,
and to add test coverage for SARIF output relating to GCC plugins.
gcc/ChangeLog:
* diagnostic-format-sarif.cc: Add comments noting that we don't
yet capture any diagnostic_metadata::rules associated with a
diagnostic.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-metadata-sarif.c: New test,
based on diagnostic-test-metadata.c.
* gcc.dg/plugin/diagnostic-test-metadata-sarif.py: New script.
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.c:
Replace scan-sarif-file directives with run-sarif-pytest, to
run...
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py:
...this new test.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add
diagnostic-test-metadata-sarif.c.
* gcc.dg/sarif-output/sarif.py: Move to...
* lib/sarif.py: ...here.
* lib/scansarif.exp (run-sarif-pytest): Prepend "lib" to
PYTHONPATH before running python scripts.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
(§3.3.4)
This patch adds support to our SARIF output for cases where
rich_loc.escape_on_output_p () is true, such as for -Wbidi-chars.
In such cases, the pertinent SARIF "location" object gains a property
bag with property "gcc/escapeNonAscii": true, and the "artifactContent"
within the location's physical location's snippet" gains a "rendered"
property (§3.3.4) that escapes non-ASCII text in the snippet, such as:
"rendered": {"text":
where "text" has a string value such as (for a "trojan source" attack):
"9 | /*<U+202E> } <U+2066>if (isAdmin)<U+2069> <U+2066> begin admins only */\n"
" | ~~~~~~~~ ~~~~~~~~ ^\n"
" | | | |\n"
" | | | end of bidirectional context\n"
" | U+202E (RIGHT-TO-LEFT OVERRIDE) U+2066 (LEFT-TO-RIGHT ISOLATE)\n"
where the escaping is affected by -fdiagnostics-escape-format=; with
-fdiagnostics-escape-format=bytes, the rendered text of the above is:
"9 | /*<e2><80><ae> } <e2><81><a6>if (isAdmin)<e2><81><a9> <e2><81><a6> begin admins only */\n"
" | ~~~~~~~~~~~~ ~~~~~~~~~~~~ ^\n"
" | | | |\n"
" | U+202E (RIGHT-TO-LEFT OVERRIDE) U+2066 (LEFT-TO-RIGHT ISOLATE) end of bidirectional context\n"
The patch also refactors/adds enough selftest machinery to be able to
test the snippet generation from within the selftest framework, rather
than just within DejaGnu (where the regex-based testing isn't
sophisticated enough to verify such properties as the above).
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add selftest-json.o.
* diagnostic-format-sarif.cc: Include "selftest.h",
"selftest-diagnostic.h", "selftest-diagnostic-show-locus.h",
"selftest-json.h", and "text-range-label.h".
(class content_renderer): New.
(sarif_builder::m_rules_arr): Convert to std::unique_ptr.
(sarif_builder::make_location_object): Add class
escape_nonascii_renderer. If rich_loc.escape_on_output_p (),
pass a nonnull escape_nonascii_renderer to
maybe_make_physical_location_object as its snippet_renderer, and
add a property bag property "gcc/escapeNonAscii" to the SARIF
location object. For other overloads of make_location_object,
pass nullptr for the snippet_renderer.
(sarif_builder::maybe_make_region_object_for_context): Add
"snippet_renderer" param and pass it to
maybe_make_artifact_content_object.
(sarif_builder::make_tool_object): Drop "const".
(sarif_builder::make_driver_tool_component_object): Likewise.
Use typesafe unique_ptr variant of object::set for setting "rules"
property on driver_obj.
(sarif_builder::maybe_make_artifact_content_object): Add param "r"
and use it to potentially set the "rendered" property (§3.3.4).
(selftest::test_make_location_object): New.
(selftest::diagnostic_format_sarif_cc_tests): New.
* diagnostic-show-locus.cc: Include "text-range-label.h" and
"selftest-diagnostic-show-locus.h".
(selftests::diagnostic_show_locus_fixture::diagnostic_show_locus_fixture):
New.
(selftests::test_layout_x_offset_display_utf8): Use
diagnostic_show_locus_fixture to simplify and consolidate setup
code.
(selftests::test_diagnostic_show_locus_one_liner): Likewise.
(selftests::test_one_liner_colorized_utf8): Likewise.
(selftests::test_diagnostic_show_locus_one_liner_utf8): Likewise.
* gcc-rich-location.h (class text_range_label): Move to new file
text-range-label.h.
* selftest-diagnostic-show-locus.h: New file, based on material in
diagnostic-show-locus.cc.
* selftest-json.cc: New file.
* selftest-json.h: New file.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest::diagnostic_format_sarif_cc_tests.
* selftest.h (selftest::diagnostic_format_sarif_cc_tests): New decl.
gcc/testsuite/ChangeLog:
* c-c++-common/diagnostic-format-sarif-file-Wbidi-chars.c: Verify
that we have a property bag with property "gcc/escapeNonAscii": true.
Verify that we have a "rendered" property for a snippet.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Include
"text-range-label.h".
gcc/ChangeLog:
* text-range-label.h: New file, taking class text_range_label from
gcc-rich-location.h.
libcpp/ChangeLog:
* include/rich-location.h
(semi_embedded_vec::semi_embedded_vec): Add copy ctor.
(rich_location::rich_location): Remove "= delete" from decl of
copy ctor. Add deleted decl of move ctor.
(rich_location::operator=): Remove "= delete" from decl of
copy assignment. Add deleted decl of move assignment.
(fixit_hint::fixit_hint): Add copy ctor decl. Add deleted decl of
move.
(fixit_hint::operator=): Add copy assignment decl. Add deleted
decl of move assignment.
* line-map.cc (rich_location::rich_location): New copy ctor.
(fixit_hint::fixit_hint): New copy ctor.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Since r6-4582-g8a64515099e645 (which added class rich_location), ranges
of quoted source code have been colorized using the following rules:
- the primary range used the same color of the kind of the diagnostic
i.e. "error" vs "warning" etc (defaulting to bold red and bold magenta
respectively)
- secondary ranges alternate between "range1" and "range2" (defaulting
to green and blue respectively)
This works for cases with large numbers of highlighted ranges, but is
suboptimal for common cases.
The following patch adds a pair of color names: "highlight-a" and
"highlight-b", and uses them whenever it makes sense to highlight and
contrast two different things in the source code (e.g. a type mismatch).
These are used by diagnostic-show-locus.cc for highlighting quoted
source. In addition the patch adds colorization to fragments within the
corresponding diagnostic messages themselves, using consistent
colorization between the message and the quoted source code for the two
different things being contrasted.
For example, consider:
demo.c: In function ‘test_bad_format_string_args’:
../../src/demo.c:25:18: warning: format ‘%i’ expects argument of
type ‘int’, but argument 2 has type ‘const char *’ [-Wformat=]
25 | printf("hello %i", msg);
| ~^ ~~~
| | |
| int const char *
| %s
Previously, the types within the message in quotes would be in bold but
not colorized, and the labelled ranges of quoted source code would use
bold magenta for the "int" and non-bold green for the "const char *".
With this patch:
- the "%i" and "int" in the message and the "int" in the quoted source
are all colored bold green
- the "const char *" in the message and in the quoted source are both
colored bold blue
so that the consistent use of contrasting color draws the reader's eyes
to the relationships between the diagnostic message and the source.
I've tried this with gnome-terminal with many themes, including a
variety of light versus dark backgrounds, solarized versus non-solarized
themes, etc, and it was readable in all.
My initial version of the patch used the existing %r and %R facilities
within pretty-print.cc for the messages, but this turned out to be very
uncomfortable, leading to error-prone format strings such as:
error_at (richloc,
"invalid operands to binary %s (have %<%r%T%R%> and %<%r%T%R%>)",
opname,
"highlight-a", type0,
"highlight-b", type1);
To avoid requiring monstrosities such as the above, the patch adds a new
"%e" format code to pretty-print.cc, which expects a pp_element *, where
pp_element is a new abstract base class (actually a pp_markup::element),
along with various useful subclasses. This lets the above be written
as:
pp_markup::element_quoted_type element_0 (type0, highlight_colors::lhs);
pp_markup::element_quoted_type element_1 (type1, highlight_colors::rhs);
error_at (richloc,
"invalid operands to binary %s (have %e and %e)",
opname, &element_0, &element_1);
which I feel is maintainable and clear to translators; the use of %e and
pp_element * captures the type-unsafe part of the variadic call, and the
subclasses allow for type-safety (so e.g. an element_quoted_type expects
a type and a highlighting color). This approach allows for some nice
simplifications within c-format.cc.
The patch also extends -Wformat to "teach" it about the new %e and
pp_element *. Doing so requires c-format.cc to be able to determine
if a T * is a pp_element * (i.e. if T is a subclass). To do so I added
a new comp_types callback for comparing types, where the C++ frontend
supplies a suitable implementation (and %e will always be wrong for C).
I've manually tested this on many diagnostics with both C and C++ and it
seems a subtle but significant improvement in readability.
I've added a new option -fno-diagnostics-show-highlight-colors in case
people prefer the old behavior.
gcc/c-family/ChangeLog:
* c-common.cc: Include "tree-pretty-print-markup.h".
(binary_op_error): Use pp_markup::element_quoted_type and %e.
(check_function_arguments): Add "comp_types" param and pass it to
check_function_format.
* c-common.h (check_function_arguments): Add "comp_types" param.
(check_function_format): Likewise.
* c-format.cc: Include "tree-pretty-print-markup.h".
(local_pp_element_ptr_node): New.
(PP_FORMAT_CHAR_TABLE): Add entry for %e.
(struct format_check_context): Add "m_comp_types" field.
(check_function_format): Add "comp_types" param and pass it to
check_format_info.
(check_format_info): Likewise, passing it to format_ctx's ctor.
(check_format_arg): Extract m_comp_types from format_ctx and
pass it to check_format_info_main.
(check_format_info_main): Add "comp_types" param and pass it to
arg_parser's ctor.
(class argument_parser): Add "m_comp_types" field.
(argument_parser::check_argument_type): Pass m_comp_types to
check_format_types.
(handle_subclass_of_pp_element_p): New.
(check_format_types): Add "comp_types" param, and use it to
call handle_subclass_of_pp_element_p.
(class element_format_substring): New.
(class element_expected_type_with_indirection): New.
(format_type_warning): Use element_expected_type_with_indirection
to unify the if (wanted_type_name) branches, reducing from four
emit_warning calls to two. Simplify these further using %e.
Doing so also gives suitable colorization of the text within the
diagnostics.
(init_dynamic_diag_info): Initialize local_pp_element_ptr_node.
(selftest::test_type_mismatch_range_labels): Add nullptr for new
param of gcc_rich_location label overload.
* c-format.h (T_PP_ELEMENT_PTR): New.
* c-type-mismatch.cc: Include "diagnostic-highlight-colors.h".
(binary_op_rich_location::binary_op_rich_location): Use
highlight_colors::lhs and highlight_colors::rhs for the ranges.
* c-type-mismatch.h (class binary_op_rich_location): Add comment
about highlight_colors.
gcc/c/ChangeLog:
* c-objc-common.cc: Include "tree-pretty-print-markup.h".
(print_type): Add optional "highlight_color" param and use it
to show highlight colors in "aka" text.
(pp_markup::element_quoted_type::print_type): New.
* c-typeck.cc: Include "tree-pretty-print-markup.h".
(comp_parm_types): New.
(build_function_call_vec): Pass it to check_function_arguments.
(inform_for_arg): Use %e and highlight colors to contrast actual
versus expected.
(convert_for_assignment): Use highlight_colors::actual for the
rhs_label.
(build_binary_op): Use highlight_colors::lhs and highlight_colors::rhs
for the ranges.
gcc/ChangeLog:
* common.opt (fdiagnostics-show-highlight-colors): New option.
* common.opt.urls: Regenerate.
* coretypes.h (pp_markup::element): New forward decl.
(pp_element): New typedef.
* diagnostic-color.cc (gcc_color_defaults): Add "highlight-a"
and "highlight-b".
* diagnostic-format-json.cc (diagnostic_output_format_init_json):
Disable highlight colors.
* diagnostic-format-sarif.cc (diagnostic_output_format_init_sarif):
Likewise.
* diagnostic-highlight-colors.h: New file.
* diagnostic-path.cc (struct event_range): Pass nullptr for
highlight color of m_rich_loc.
* diagnostic-show-locus.cc (colorizer::set_range): Handle ranges
with m_highlight_color.
(colorizer::STATE_NAMED_COLOR): New.
(colorizer::m_richloc): New field.
(colorizer::colorizer): Add richloc param for initializing
m_richloc.
(colorizer::set_named_color): New.
(colorizer::begin_state): Add case STATE_NAMED_COLOR.
(layout::layout): Pass richloc to m_colorizer's ctor.
(selftest::test_one_liner_labels): Pass nullptr for new param of
gcc_rich_location ctor for labels.
(selftest::test_one_liner_labels_utf8): Likewise.
* diagnostic.h (diagnostic_context::set_show_highlight_colors):
New.
* doc/invoke.texi: Add option -fdiagnostics-show-highlight-colors
and highlight-a and highlight-b color caps.
* doc/ux.texi
(Use color consistently when highlighting mismatches): New
subsection.
* gcc-rich-location.cc (gcc_rich_location::add_expr): Add
"highlight_color" param.
(gcc_rich_location::maybe_add_expr): Likewise.
* gcc-rich-location.h (gcc_rich_location::gcc_rich_location):
Split out into a pair of ctors, where if a range_label is supplied
the caller must also supply a highlight color.
(gcc_rich_location::add_expr): Add "highlight_color" param.
(gcc_rich_location::maybe_add_expr): Likewise.
* gcc.cc (driver_handle_option): Handle
OPT_fdiagnostics_show_highlight_colors.
* lto-wrapper.cc (merge_and_complain): Likewise.
(append_compiler_options): Likewise.
(append_diag_options): Likewise.
(run_gcc): Likewise.
* opts-common.cc (decode_cmdline_options_to_array): Add comment
about -fno-diagnostics-show-highlight-colors.
* opts-global.cc (init_options_once): Preserve
pp_show_highlight_colors in case the global_dc's printer is
recreated.
* opts.cc (common_handle_option): Handle
OPT_fdiagnostics_show_highlight_colors.
(gen_command_line_string): Likewise.
* pretty-print-markup.h: New file.
* pretty-print.cc: Include "pretty-print-markup.h" and
"diagnostic-highlight-colors.h".
(pretty_printer::format): Handle %e.
(pretty_printer::pretty_printer): Handle new field
m_show_highlight_colors.
(pp_string_n): New.
(pp_markup::context::begin_quote): New.
(pp_markup::context::end_quote): New.
(pp_markup::context::begin_color): New.
(pp_markup::context::end_color): New.
(highlight_colors::expected): New.
(highlight_colors::actual): New.
(highlight_colors::lhs): New.
(highlight_colors::rhs): New.
(class selftest::test_element): New.
(selftest::test_pp_format): Add tests of %e.
(selftest::test_urlification): Likewise.
* pretty-print.h (pp_markup::context): New forward decl.
(class chunk_info): Add friend class pp_markup::context.
(class pretty_printer): Add friend pp_show_highlight_colors.
(pretty_printer::m_show_highlight_colors): New field.
(pp_show_highlight_colors): New inline function.
(pp_string_n): New decl.
* substring-locations.cc: Include "diagnostic-highlight-colors.h".
(format_string_diagnostic_t::highlight_color_format_string): New.
(format_string_diagnostic_t::highlight_color_param): New.
(format_string_diagnostic_t::emit_warning_n_va): Use highlight
colors.
* substring-locations.h
(format_string_diagnostic_t::highlight_color_format_string): New.
(format_string_diagnostic_t::highlight_color_param): New.
* toplev.cc (general_init): Initialize global_dc's
show_highlight_colors.
* tree-pretty-print-markup.h: New file.
gcc/cp/ChangeLog:
* call.cc: Include "tree-pretty-print-markup.h".
(implicit_conversion_error): Use highlight_colors::percent_h for
the labelled range.
(op_error_string): Split out into...
(concat_op_error_string): ...this.
(binop_error_string): New.
(op_error): Use %e, binop_error_string, highlight_colors::lhs,
and highlight_colors::rhs.
(maybe_inform_about_fndecl_for_bogus_argument_init): Add
"highlight_color" param; use it for the richloc.
(convert_like_internal): Use highlight_colors::percent_h for the
labelled_range, and highlight_colors::percent_i for the call to
maybe_inform_about_fndecl_for_bogus_argument_init.
(build_over_call): Pass cp_comp_parm_types for new "comp_types"
param of check_function_arguments.
(complain_about_bad_argument): Use highlight_colors::percent_h for
the labelled_range, and highlight_colors::percent_i for the call
to maybe_inform_about_fndecl_for_bogus_argument_init.
* cp-tree.h (maybe_inform_about_fndecl_for_bogus_argument_init):
Add optional highlight_color param.
(cp_comp_parm_types): New decl.
(highlight_colors::const percent_h): New decl.
(highlight_colors::const percent_i): New decl.
* error.cc: Include "tree-pretty-print-markup.h".
(highlight_colors::const percent_h): New defn.
(highlight_colors::const percent_i): New defn.
(type_to_string): Add param "highlight_color" and use it.
(print_nonequal_arg): Likewise.
(print_template_differences): Add params "highlight_color_a" and
"highlight_color_b".
(type_to_string_with_compare): Add params "this_highlight_color"
and "peer_highlight_color".
(print_template_tree_comparison): Add params "highlight_color_a"
and "highlight_color_b".
(cxx_format_postprocessor::handle):
Use highlight_colors::percent_h and highlight_colors::percent_i.
(pp_markup::element_quoted_type::print_type): New.
(range_label_for_type_mismatch::get_text): Pass nullptr for new
params of type_to_string_with_compare.
* typeck.cc (cp_comp_parm_types): New.
(cp_build_function_call_vec): Pass it to check_function_arguments.
(convert_for_assignment): Use highlight_colors::percent_h for the
labelled_range.
gcc/testsuite/ChangeLog:
* g++.dg/diagnostic/bad-binary-ops-highlight-colors.C: New test.
* g++.dg/diagnostic/bad-binary-ops-no-highlight-colors.C: New test.
* g++.dg/plugin/plugin.exp (plugin_test_list): Add
show-template-tree-color-no-highlight-colors.C to
show_template_tree_color_plugin.c.
* g++.dg/plugin/show-template-tree-color-labels.C: Update expected
output to reflect use of highlight-a and highlight-b to contrast
mismatches.
* g++.dg/plugin/show-template-tree-color-no-elide-type.C:
Likewise.
* g++.dg/plugin/show-template-tree-color-no-highlight-colors.C:
New test.
* g++.dg/plugin/show-template-tree-color.C: Update expected output
to reflect use of highlight-a and highlight-b to contrast
mismatches.
* g++.dg/warn/Wformat-gcc_diag-1.C: New test.
* g++.dg/warn/Wformat-gcc_diag-2.C: New test.
* g++.dg/warn/Wformat-gcc_diag-3.C: New test.
* gcc.dg/bad-binary-ops-highlight-colors.c: New test.
* gcc.dg/format/colors.c: New test.
* gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree): Pass
nullptr for new param of gcc_rich_location::add_expr.
libcpp/ChangeLog:
* include/rich-location.h (location_range::m_highlight_color): New
field.
(rich_location::rich_location): Add optional label_highlight_color
param.
(rich_location::set_highlight_color): New decl.
(rich_location::add_range): Add optional label_highlight_color
param.
(rich_location::set_range): Likewise.
* line-map.cc (rich_location::rich_location): Add
"label_highlight_color" param and pass it to add_range.
(rich_location::set_highlight_color): New.
(rich_location::add_range): Add "label_highlight_color" param.
(rich_location::set_range): Add "highlight_color" param.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
These are never nullptr and never change, so use a reference rather
than a pointer.
No functional change intended.
gcc/analyzer/ChangeLog:
* diagnostic-manager.cc
(diagnostic_manager::add_events_for_eedge): Pass sm_ctxt by
reference.
* engine.cc (impl_region_model_context::on_condition): Likewise.
(impl_region_model_context::on_bounded_ranges): Likewise.
(impl_region_model_context::on_phi): Likewise.
(exploded_node::on_stmt): Likewise.
* sm-fd.cc: Update all uses of sm_context * to sm_context &.
* sm-file.cc: Likewise.
* sm-malloc.cc: Likewise.
* sm-pattern-test.cc: Likewise.
* sm-sensitive.cc: Likewise.
* sm-signal.cc: Likewise.
* sm-taint.cc: Likewise.
* sm.h: Likewise.
* varargs.cc: Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_gil_plugin.c: Update all uses of
sm_context * to sm_context &.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
As work towards eliminating the dependency on "tree" from
path-printing, move these classes to a new simple-diagnostic-path.h/cc.
No functional change intended.
gcc/analyzer/ChangeLog:
* checker-path.h: Include "simple-diagnostic-path.h".
gcc/ChangeLog:
* Makefile.in (OBJS): Add simple-diagnostic-path.o.
* diagnostic-path.h (class simple_diagnostic_event): Move to
simple-diagnostic-path.h.
(class simple_diagnostic_thread): Likewise.
(class simple_diagnostic_path): Likewise.
* diagnostic.cc (simple_diagnostic_path::simple_diagnostic_path):
Move to simple-diagnostic-path.cc.
(simple_diagnostic_path::num_events): Likewise.
(simple_diagnostic_path::get_event): Likewise.
(simple_diagnostic_path::num_threads): Likewise.
(simple_diagnostic_path::get_thread): Likewise.
(simple_diagnostic_path::add_thread): Likewise.
(simple_diagnostic_path::add_event): Likewise.
(simple_diagnostic_path::add_thread_event): Likewise.
(simple_diagnostic_path::connect_to_next_event): Likewise.
(simple_diagnostic_event::simple_diagnostic_event): Likewise.
(simple_diagnostic_event::~simple_diagnostic_event): Likewise.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest::simple_diagnostic_path_cc_tests.
* selftest.h (selftest::simple_diagnostic_path_cc_tests): New
decl.
* simple-diagnostic-path.cc: New file, from the above material.
* simple-diagnostic-path.h: New file, from the above material
from diagnostic-path.h.
* tree-diagnostic-path.cc: Include "simple-diagnostic-path.h".
gcc/testsuite/ChangeLog
* gcc.dg/plugin/diagnostic_plugin_test_paths.c: Include
"simple-diagnostic-path.h".
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
No functional change intended.
gcc/analyzer/ChangeLog:
* access-diagram.cc (access_range::dump): Update for fields of
pretty_printer becoming private.
* call-details.cc (call_details::dump): Likewise.
* call-summary.cc (call_summary::dump): Likewise.
(call_summary_replay::dump): Likewise.
* checker-event.cc (checker_event::debug): Likewise.
* constraint-manager.cc (range::dump): Likewise.
(bounded_range::dump): Likewise.
(constraint_manager::dump): Likewise.
* engine.cc (exploded_node::dump): Likewise.
(exploded_path::dump): Likewise.
(exploded_path::dump_to_file): Likewise.
* feasible-graph.cc (feasible_graph::dump_feasible_path): Likewise.
* program-point.cc (program_point::dump): Likewise.
* program-state.cc (extrinsic_state::dump_to_file): Likewise.
(sm_state_map::dump): Likewise.
(program_state::dump_to_file): Likewise.
* ranges.cc (symbolic_byte_offset::dump): Likewise.
(symbolic_byte_range::dump): Likewise.
* record-layout.cc (record_layout::dump): Likewise.
* region-model-reachability.cc (reachable_regions::dump): Likewise.
* region-model.cc (region_to_value_map::dump): Likewise.
(region_model::dump): Likewise.
(model_merger::dump): Likewise.
* region-model.h (one_way_id_map<T>::dump): Likewise.
* region.cc (region_offset::dump): Likewise.
(region::dump): Likewise.
* sm-malloc.cc (deallocator_set::dump): Likewise.
* store.cc (uncertainty_t::dump): Likewise.
(binding_key::dump): Likewise.
(bit_range::dump): Likewise.
(byte_range::dump): Likewise.
(binding_map::dump): Likewise.
(binding_cluster::dump): Likewise.
(store::dump): Likewise.
* supergraph.cc (supergraph::dump_dot_to_file): Likewise.
(superedge::dump): Likewise.
* svalue.cc (svalue::dump): Likewise.
gcc/c-family/ChangeLog:
* c-ada-spec.cc (dump_ads): Update for fields of pretty_printer
becoming private.
* c-pretty-print.cc: Likewise throughout.
gcc/c/ChangeLog:
* c-objc-common.cc (print_type): Update for fields of
pretty_printer becoming private.
(c_tree_printer): Likewise.
gcc/cp/ChangeLog:
* cxx-pretty-print.cc: Update throughout for fields of
pretty_printer becoming private.
* error.cc: Likewise.
gcc/ChangeLog:
* diagnostic.cc (diagnostic_context::urls_init): Update for fields
of pretty_printer becoming private.
(diagnostic_context::print_any_cwe): Likewise.
(diagnostic_context::print_any_rules): Likewise.
(diagnostic_context::print_option_information): Likewise.
* diagnostic.h (diagnostic_format_decoder): Likewise.
(diagnostic_prefixing_rule): Likewise, fixing typo.
* digraph.cc (test_dump_to_dot): Likewise.
* digraph.h (digraph<GraphTraits>::dump_dot_to_file): Likewise.
* dumpfile.cc
(dump_pretty_printer::emit_any_pending_textual_chunks): Likewise.
* gimple-pretty-print.cc (print_gimple_stmt): Likewise.
(print_gimple_expr): Likewise.
(print_gimple_seq): Likewise.
(dump_ssaname_info_to_file): Likewise.
(gimple_dump_bb): Likewise.
* graph.cc (print_graph_cfg): Likewise.
(start_graph_dump): Likewise.
* langhooks.cc (lhd_print_error_function): Likewise.
* lto-wrapper.cc (print_lto_docs_link): Likewise.
* pretty-print.cc (pp_set_real_maximum_length): Convert to...
(pretty_printer::set_real_maximum_length): ...this.
(pp_clear_state): Convert to...
(pretty_printer::clear_state): ...this.
(pp_wrap_text): Update for pp_remaining_character_count_for_line
becoming a member function.
(urlify_quoted_string): Update for fields of pretty_printer becoming
private.
(pp_format): Convert to...
(pretty_printer::format): ...this. Reduce the scope of local
variables "old_line_length" and "old_wrapping_mode" and make
const. Reduce the scope of locals "args", "new_chunk_array",
"curarg", "any_unnumbered", and "any_numbered".
(pp_output_formatted_text): Update for fields of pretty_printer
becoming private.
(pp_flush): Likewise.
(pp_really_flush): Likewise.
(pp_set_line_maximum_length): Likewise.
(pp_set_prefix): Convert to...
(pretty_printer::set_prefix): ...this.
(pp_take_prefix): Update for fields of pretty_printer gaining
"m_" prefixes.
(pp_destroy_prefix): Likewise.
(pp_emit_prefix): Convert to...
(pretty_printer::emit_prefix): ...this.
(pretty_printer::pretty_printer): Update both ctors for fields
gaining "m_" prefixes.
(pretty_printer::~pretty_printer): Likewise for dtor.
(pp_append_text): Update for pp_emit_prefix becoming
pretty_printer::emit_prefix.
(pp_remaining_character_count_for_line): Convert to...
(pretty_printer::remaining_character_count_for_line): ...this.
(pp_character): Update for above change.
(pp_maybe_space): Convert to...
(pretty_printer::maybe_space): ...this.
(pp_begin_url): Convert to...
(pretty_printer::begin_url): ...this.
(get_end_url_string): Update for fields of pretty_printer
becoming private.
(pp_end_url): Convert to...
(pretty_printer::end_url): ...this.
(selftest::test_pretty_printer::test_pretty_printer): Update for
fields of pretty_printer becoming private.
(selftest::test_urls): Likewise.
(selftest::test_null_urls): Likewise.
(selftest::test_urlification): Likewise.
* pretty-print.h (pp_line_cutoff): Convert from macro to inline
function.
(pp_prefixing_rule): Likewise.
(pp_wrapping_mode): Likewise.
(pp_format_decoder): Likewise.
(pp_needs_newline): Likewise.
(pp_indentation): Likewise.
(pp_translate_identifiers): Likewise.
(pp_show_color): Likewise.
(pp_buffer): Likewise.
(pp_get_prefix): Add forward decl to allow friend decl.
(pp_take_prefix): Likewise.
(pp_destroy_prefix): Likewise.
(class pretty_printer): Fix typo in leading comment. Add
"friend" decls for the various new accessor functions that were
formerly macros and for pp_get_prefix, pp_take_prefix, and
pp_destroy_prefix. Make all fields private.
(pretty_printer::set_output_stream): New.
(pretty_printer::set_prefix): New decl.
(pretty_printer::emit_prefix): New decl.
(pretty_printer::format): New decl.
(pretty_printer::maybe_space): New decl.
(pretty_printer::supports_urls_p): New.
(pretty_printer::get_url_format): New.
(pretty_printer::set_url_format): New.
(pretty_printer::begin_url): New decl.
(pretty_printer::end_url): New decl.
(pretty_printer::set_verbatim_wrapping): New.
(pretty_printer::set_padding): New.
(pretty_printer::get_padding): New.
(pretty_printer::clear_state): New decl.
(pretty_printer::set_real_maximum_length): New decl.
(pretty_printer::remaining_character_count_for_line): New decl.
(pretty_printer::buffer): Rename to...
(pretty_printer::m_buffer): ...this.
(pretty_printer::prefix): Rename to...
(pretty_printer::m_prefix): ...this;
(pretty_printer::padding): Rename to...
(pretty_printer::m_padding): ...this;
(pretty_printer::maximum_length): Rename to...
(pretty_printer::m_maximum_length): ...this;
(pretty_printer::indent_skip): Rename to...
(pretty_printer::m_indent_skip): ...this;
(pretty_printer::wrapping): Rename to...
(pretty_printer::m_wrapping): ...this;
(pretty_printer::format_decoder): Rename to...
(pretty_printer::m_format_decoder): ...this;
(pretty_printer::emitted_prefix): Rename to...
(pretty_printer::m_emitted_prefix): ...this;
(pretty_printer::need_newline): Rename to...
(pretty_printer::m_need_newline): ...this;
(pretty_printer::translate_identifiers): Rename to...
(pretty_printer::m_translate_identifiers): ...this;
(pretty_printer::show_color): Rename to...
(pretty_printer::m_show_color): ...this;
(pretty_printer::url_format): Rename to...
(pretty_printer::m_url_format): ...this;
(pp_get_prefix): Reformat.
(pp_format_postprocessor): New inline function.
(pp_take_prefix): Move decl to before class pretty_printer.
(pp_destroy_prefix): Likewise.
(pp_set_prefix): Convert to inline function.
(pp_emit_prefix): Convert to inline function.
(pp_format): Convert to inline function.
(pp_maybe_space): Convert to inline function.
(pp_begin_url): Convert to inline function.
(pp_end_url): Convert to inline function.
(pp_set_verbatim_wrapping): Convert from macro to inline
function, renaming...
(pp_set_verbatim_wrapping_): ...this.
* print-rtl.cc (dump_value_slim): Update for fields of
pretty_printer becoming private.
(dump_insn_slim): Likewise.
(dump_rtl_slim): Likewise.
* print-tree.cc (print_node): Likewise.
* sched-rgn.cc (dump_rgn_dependencies_dot): Likewise.
* text-art/canvas.cc (canvas::print_to_pp): Likewise.
(canvas::debug): Likewise.
(selftest::test_canvas_urls): Likewise.
* text-art/dump.h (dump_to_file): Likewise.
* text-art/selftests.cc (selftest::assert_canvas_streq): Likewise.
* text-art/style.cc (style::print_changes): Likewise.
* text-art/styled-string.cc (styled_string::from_fmt_va):
Likewise.
* tree-diagnostic-path.cc (control_flow_tests): Update for
pp_show_color becoming an inline function.
* tree-loop-distribution.cc (dot_rdg_1): Update for fields of
pretty_printer becoming private.
* tree-pretty-print.cc (maybe_init_pretty_print): Likewise.
* value-range.cc (vrange::dump): Likewise.
(irange_bitmask::dump): Likewise.
gcc/fortran/ChangeLog:
* error.cc (gfc_clear_pp_buffer): Likewise.
(gfc_warning): Likewise.
(gfc_warning_check): Likewise.
(gfc_error_opt): Likewise.
(gfc_error_check): Likewise.
gcc/jit/ChangeLog:
* jit-recording.cc (recording::function::dump_to_dot): Update for
fields of pretty_printer becoming private.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.c (dump_refcnt_info):
Update for fields of pretty_printer becoming private.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
gcc/analyzer/ChangeLog:
PR analyzer/106203
* checker-event.h: Include "analyzer/event-loc-info.h".
(struct event_loc_info): Move to its own header file.
* diagnostic-manager.cc
(diagnostic_manager::emit_saved_diagnostic): Move creation of
event_loc_info here from add_final_event, and if we have a
stmt_finder, call its update_event_loc_info method.
* engine.cc (leak_stmt_finder::update_event_loc_info): New.
(exploded_node::detect_leaks): Likewise.
(exploded_node::detect_leaks): Pass nullptr as call_stmt arg to
region_model::pop_frame.
* event-loc-info.h: New file, with content taken from
checker-event.h.
* exploded-graph.h (stmt_finder::update_event_loc_info): New pure
virtual function.
* infinite-loop.cc (infinite_loop_diagnostic::add_final_event):
Update for change to vfunc signature.
* infinite-recursion.cc
(infinite_recursion_diagnostic::add_final_event): Likewise.
* pending-diagnostic.cc (pending_diagnostic::add_final_event):
Pass in the event_loc_info from the caller, rather than generating
it from a gimple stmt and enode.
* pending-diagnostic.h (pending_diagnostic::add_final_event):
Likewise.
* region-model.cc (region_model::on_longjmp): Pass nullptr as
call_stmt arg to region_model::pop_frame.
(region_model::update_for_return_gcall): Likewise, but pass
call_stmt.
(class caller_context): New.
(region_model::pop_frame): Add "call_stmt" argument. Use it
and the frame_region with a caller_context when setting
result_dst_reg's value so that any diagnostic is reported at the
call stmt in the caller.
(selftest::test_stack_frames): Pass nullptr as call_stmt arg to
region_model::pop_frame.
(selftest::test_alloca): Likewise.
* region-model.h (region_model::pop_frame): Add "call_stmt"
argument.
gcc/testsuite/ChangeLog:
PR analyzer/106203
* c-c++-common/analyzer/allocation-size-1.c (test_9): Remove
xfail.
* c-c++-common/analyzer/allocation-size-2.c (test_8): Likewise.
* gcc.dg/analyzer/allocation-size-multiline-4.c: New test.
* gcc.dg/plugin/analyzer_cpython_plugin.c
(refcnt_stmt_finder::update_event_loc_info): New.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This patch adds a new text_art::tree_widget, which makes it easy
to generate hierarchical visualizations using either ASCII:
+- Child 0
| +- Grandchild 0 0
| +- Grandchild 0 1
| `- Grandchild 0 2
+- Child 1
| +- Grandchild 1 0
| +- Grandchild 1 1
| `- Grandchild 1 2
`- Child 2
+- Grandchild 2 0
+- Grandchild 2 1
`- Grandchild 2 2
or Unicode:
Root
├─ Child 0
│ ├─ Grandchild 0 0
│ ├─ Grandchild 0 1
│ ╰─ Grandchild 0 2
├─ Child 1
│ ├─ Grandchild 1 0
│ ├─ Grandchild 1 1
│ ╰─ Grandchild 1 2
╰─ Child 2
├─ Grandchild 2 0
├─ Grandchild 2 1
╰─ Grandchild 2 2
potentially with colorization of the connecting lines.
It adds a new template for typename T:
void text_art::dump<T> (const T&);
for using this to dump any object to stderr that supports a
make_dump_widget method, with similar templates for dumping to
a pretty_printer * and a FILE *.
It uses this within the analyzer to add two new families of dumping
methods: one for program states, e.g.:
(gdb) call state->dump()
State
├─ Region Model
│ ├─ Current Frame: frame: ‘calls_malloc’@2
│ ├─ Store
│ │ ├─ m_called_unknown_fn: false
│ │ ├─ frame: ‘test’@1
│ │ │ ╰─ _1: (INIT_VAL(n_2(D))*(size_t)4)
│ │ ╰─ frame: ‘calls_malloc’@2
│ │ ├─ result_4: &HEAP_ALLOCATED_REGION(27)
│ │ ╰─ _5: &HEAP_ALLOCATED_REGION(27)
│ ╰─ Dynamic Extents
│ ╰─ HEAP_ALLOCATED_REGION(27): (INIT_VAL(n_2(D))*(size_t)4)
╰─ ‘malloc’ state machine
╰─ 0x468cb40: &HEAP_ALLOCATED_REGION(27): unchecked ({free}) (‘result_4’)
and the other for showing the detail of the recursive makeup of svalues
and regions, e.g. the (INIT_VAL(n_2(D))*(size_t)4) from above:
(gdb) call size_in_bytes->dump()
(17): ‘long unsigned int’: binop_svalue(mult_expr: ‘*’)
├─ (15): ‘size_t’: initial_svalue
│ ╰─ m_reg: (12): ‘size_t’: decl_region(‘n_2(D)’)
│ ╰─ parent: (9): frame_region(‘test’, index: 0, depth: 1)
│ ╰─ parent: (1): stack region
│ ╰─ parent: (0): root region
╰─ (16): ‘size_t’: constant_svalue (‘4’)
I've already found both of these useful when debugging analyzer issues.
The patch uses the former to update the output of
-fdump-analyzer-exploded-nodes-2 and
-fdump-analyzer-exploded-nodes-3.
The older dumping functions within the analyzer are retained in case
they turn out to still be useful for debugging.
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add text-art/tree-widget.o.
* doc/analyzer.texi: Rewrite discussion of dumping state to
cover the text_art::tree_widget-based dumps, with a more
interesting example.
* text-art/dump-widget-info.h: New file.
* text-art/dump.h: New file.
* text-art/selftests.cc (selftest::text_art_tests): Call
text_art_tree_widget_cc_tests.
* text-art/selftests.h (selftest::text_art_tree_widget_cc_tests):
New decl.
* text-art/theme.cc (ascii_theme::get_cppchar): Handle the various
cell_kind::TREE_*.
(unicode_theme::get_cppchar): Likewise.
* text-art/theme.h (enum class theme::cell_kind): Add
TREE_CHILD_NON_FINAL, TREE_CHILD_FINAL, TREE_X_CONNECTOR, and
TREE_Y_CONNECTOR.
* text-art/tree-widget.cc: New file.
gcc/analyzer/ChangeLog:
* call-details.cc: Define INCLUDE_VECTOR.
* call-info.cc: Likewise.
* call-summary.cc: Likewise.
* checker-event.cc: Likewise.
* checker-path.cc: Likewise.
* complexity.cc: Likewise.
* constraint-manager.cc: Likewise.
(bounded_range::make_dump_widget): New.
(bounded_ranges::add_to_dump_widget): New.
(equiv_class::make_dump_widget): New.
(constraint::make_dump_widget): New.
(bounded_ranges_constraint::make_dump_widget): New.
(constraint_manager::make_dump_widget): New.
* constraint-manager.h (bounded_range::make_dump_widget): New
decl.
(bounded_ranges::add_to_dump_widget): New decl.
(equiv_class::make_dump_widget): New decl.
(constraint::make_dump_widget): New decl.
(bounded_ranges_constraint::make_dump_widget): New decl.
(constraint_manager::make_dump_widget): New decl.
* diagnostic-manager.cc: Define INCLUDE_VECTOR.
* engine.cc: Likewise. Include "text-art/dump.h".
(setjmp_svalue::print_dump_widget_label): New.
(setjmp_svalue::add_dump_widget_children): New.
(exploded_graph::dump_exploded_nodes): Use text_art::dump_to_file
for -fdump-analyzer-exploded-nodes-2 and
-fdump-analyzer-exploded-nodes-3. Fix overlong line.
* feasible-graph.cc: Define INCLUDE_VECTOR.
* infinite-recursion.cc: Likewise.
* kf-analyzer.cc: Likewise.
* kf-lang-cp.cc: Likewise.
* kf.cc: Likewise.
* known-function-manager.cc: Likewise.
* pending-diagnostic.cc: Likewise.
* program-point.cc: Likewise.
* program-state.cc: Likewise. Include "text-art/tree-widget" and
"text-art/dump.h".
(sm_state_map::make_dump_widget): New.
(program_state::dump): New.
(program_state::make_dump_widget): New.
* program-state.h: Include "text-art/widget.h".
(sm_state_map::make_dump_widget): New decl.
(program_state::dump): New decl.
(program_state::make_dump_widget): New decl.
* ranges.cc: Define INCLUDE_VECTOR.
* record-layout.cc: Likewise.
* region-model-asm.cc: Likewise.
* region-model-manager.cc: Likewise.
* region-model-reachability.cc: Likewise.
* region-model.cc: Likewise. Include "text-art/tree-widget.h".
(region_to_value_map::make_dump_widget): New.
(region_model::dump): New.
(region_model::make_dump_widget): New.
(selftest::test_dump): Add test of dump_to_pp<region_model>.
* region-model.h: Include "text-art/widget.h" and
"text-art/dump.h".
(region_to_value_map::make_dump_widget): New decl.
(region_model::dump): New decl.
(region_model::make_dump_widget): New decl.
* region.cc: Define INCLUDE_VECTOR and include "text-art/dump.h".
(region::dump): New.
(region::make_dump_widget): New.
(region::add_dump_widget_children): New.
(frame_region::print_dump_widget_label): New.
(globals_region::print_dump_widget_label): New.
(code_region::print_dump_widget_label): New.
(function_region::print_dump_widget_label): New.
(label_region::print_dump_widget_label): New.
(stack_region::print_dump_widget_label): New.
(heap_region::print_dump_widget_label): New.
(root_region::print_dump_widget_label): New.
(thread_local_region::print_dump_widget_label): New.
(symbolic_region::print_dump_widget_label): New.
(symbolic_region::add_dump_widget_children): New.
(decl_region::print_dump_widget_label): New.
(field_region::print_dump_widget_label): New.
(element_region::print_dump_widget_label): New.
(element_region::add_dump_widget_children): New.
(offset_region::print_dump_widget_label): New.
(offset_region::add_dump_widget_children): New.
(sized_region::print_dump_widget_label): New.
(sized_region::add_dump_widget_children): New.
(cast_region::print_dump_widget_label): New.
(cast_region::add_dump_widget_children): New.
(heap_allocated_region::print_dump_widget_label): New.
(alloca_region::print_dump_widget_label): New.
(string_region::print_dump_widget_label): New.
(bit_range_region::print_dump_widget_label): New.
(var_arg_region::print_dump_widget_label): New.
(errno_region::print_dump_widget_label): New.
(private_region::print_dump_widget_label): New.
(unknown_region::print_dump_widget_label): New.
* region.h: Include "text-art/widget.h".
(region::dump): New decl.
(region::make_dump_widget): New decl.
(region::add_dump_widget_children): New decl.
(frame_region::print_dump_widget_label): New decl.
(globals_region::print_dump_widget_label): New decl.
(code_region::print_dump_widget_label): New decl.
(function_region::print_dump_widget_label): New decl.
(label_region::print_dump_widget_label): New decl.
(stack_region::print_dump_widget_label): New decl.
(heap_region::print_dump_widget_label): New decl.
(root_region::print_dump_widget_label): New decl.
(thread_local_region::print_dump_widget_label): New decl.
(symbolic_region::print_dump_widget_label): New decl.
(symbolic_region::add_dump_widget_children): New decl.
(decl_region::print_dump_widget_label): New decl.
(field_region::print_dump_widget_label): New decl.
(element_region::print_dump_widget_label): New decl.
(element_region::add_dump_widget_children): New decl.
(offset_region::print_dump_widget_label): New decl.
(offset_region::add_dump_widget_children): New decl.
(sized_region::print_dump_widget_label): New decl.
(sized_region::add_dump_widget_children): New decl.
(cast_region::print_dump_widget_label): New decl.
(cast_region::add_dump_widget_children): New decl.
(heap_allocated_region::print_dump_widget_label): New decl.
(alloca_region::print_dump_widget_label): New decl.
(string_region::print_dump_widget_label): New decl.
(bit_range_region::print_dump_widget_label): New decl.
(var_arg_region::print_dump_widget_label): New decl.
(errno_region::print_dump_widget_label): New decl.
(private_region::print_dump_widget_label): New decl.
(unknown_region::print_dump_widget_label): New decl.
* sm-fd.cc: Define INCLUDE_VECTOR.
* sm-file.cc: Likewise.
* sm-malloc.cc: Likewise.
* sm-pattern-test.cc: Likewise.
* sm-signal.cc: Likewise.
* sm-taint.cc: Likewise.
* sm.cc: Likewise.
* state-purge.cc: Likewise.
* store.cc: Likewise. Include "text-art/tree-widget.h".
(add_binding_to_tree_widget): New.
(binding_map::add_to_tree_widget): New.
(binding_cluster::make_dump_widget): New.
(store::make_dump_widget): New.
* store.h: Include "text-art/tree-widget.h".
(binding_map::add_to_tree_widget): New decl.
(binding_cluster::make_dump_widget): New decl.
(store::make_dump_widget): New decl.
* svalue.cc: Define INCLUDE_VECTOR. Include "make-unique.h" and
"text-art/dump.h".
(svalue::dump): New.
(svalue::make_dump_widget): New.
(region_svalue::print_dump_widget_label): New.
(region_svalue::add_dump_widget_children): New.
(constant_svalue::print_dump_widget_label): New.
(constant_svalue::add_dump_widget_children): New.
(unknown_svalue::print_dump_widget_label): New.
(unknown_svalue::add_dump_widget_children): New.
(poisoned_svalue::print_dump_widget_label): New.
(poisoned_svalue::add_dump_widget_children): New.
(initial_svalue::print_dump_widget_label): New.
(initial_svalue::add_dump_widget_children): New.
(unaryop_svalue::print_dump_widget_label): New.
(unaryop_svalue::add_dump_widget_children): New.
(binop_svalue::print_dump_widget_label): New.
(binop_svalue::add_dump_widget_children): New.
(sub_svalue::print_dump_widget_label): New.
(sub_svalue::add_dump_widget_children): New.
(repeated_svalue::print_dump_widget_label): New.
(repeated_svalue::add_dump_widget_children): New.
(bits_within_svalue::print_dump_widget_label): New.
(bits_within_svalue::add_dump_widget_children): New.
(widening_svalue::print_dump_widget_label): New.
(widening_svalue::add_dump_widget_children): New.
(placeholder_svalue::print_dump_widget_label): New.
(placeholder_svalue::add_dump_widget_children): New.
(unmergeable_svalue::print_dump_widget_label): New.
(unmergeable_svalue::add_dump_widget_children): New.
(compound_svalue::print_dump_widget_label): New.
(compound_svalue::add_dump_widget_children): New.
(conjured_svalue::print_dump_widget_label): New.
(conjured_svalue::add_dump_widget_children): New.
(asm_output_svalue::print_dump_widget_label): New.
(asm_output_svalue::add_dump_widget_children): New.
(const_fn_result_svalue::print_dump_widget_label): New.
(const_fn_result_svalue::add_dump_widget_children): New.
* svalue.h: Include "text-art/widget.h". Add "using
text_art::dump_widget_info".
(svalue::dump): New decl.
(svalue::make_dump_widget): New decl.
(svalue::print_dump_widget_label): New decl.
(svalue::print_dump_widget_label): New decl.
(svalue::add_dump_widget_children): New decl.
(region_svalue::print_dump_widget_label): New decl.
(region_svalue::add_dump_widget_children): New decl.
(constant_svalue::print_dump_widget_label): New decl.
(constant_svalue::add_dump_widget_children): New decl.
(unknown_svalue::print_dump_widget_label): New decl.
(unknown_svalue::add_dump_widget_children): New decl.
(poisoned_svalue::print_dump_widget_label): New decl.
(poisoned_svalue::add_dump_widget_children): New decl.
(initial_svalue::print_dump_widget_label): New decl.
(initial_svalue::add_dump_widget_children): New decl.
(unaryop_svalue::print_dump_widget_label): New decl.
(unaryop_svalue::add_dump_widget_children): New decl.
(binop_svalue::print_dump_widget_label): New decl.
(binop_svalue::add_dump_widget_children): New decl.
(sub_svalue::print_dump_widget_label): New decl.
(sub_svalue::add_dump_widget_children): New decl.
(repeated_svalue::print_dump_widget_label): New decl.
(repeated_svalue::add_dump_widget_children): New decl.
(bits_within_svalue::print_dump_widget_label): New decl.
(bits_within_svalue::add_dump_widget_children): New decl.
(widening_svalue::print_dump_widget_label): New decl.
(widening_svalue::add_dump_widget_children): New decl.
(placeholder_svalue::print_dump_widget_label): New decl.
(placeholder_svalue::add_dump_widget_children): New decl.
(unmergeable_svalue::print_dump_widget_label): New decl.
(unmergeable_svalue::add_dump_widget_children): New decl.
(compound_svalue::print_dump_widget_label): New decl.
(compound_svalue::add_dump_widget_children): New decl.
(conjured_svalue::print_dump_widget_label): New decl.
(conjured_svalue::add_dump_widget_children): New decl.
(asm_output_svalue::print_dump_widget_label): New decl.
(asm_output_svalue::add_dump_widget_children): New decl.
(const_fn_result_svalue::print_dump_widget_label): New decl.
(const_fn_result_svalue::add_dump_widget_children): New decl.
* trimmed-graph.cc: Define INCLUDE_VECTOR.
* varargs.cc: Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.c: Define INCLUDE_VECTOR.
* gcc.dg/plugin/analyzer_gil_plugin.c: Likewise.
* gcc.dg/plugin/analyzer_kernel_plugin.c: Likewise.
* gcc.dg/plugin/analyzer_known_fns_plugin.c: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Diagnostic path printing was added in r10-5901-g4bc1899b2e883f. As of
that commit, with -fdiagnostics-path-format=inline-events (the default),
we print a vertical line to the left of the source line numbering,
visualizing the stack depth and interprocedural calls and returns as
indentation changes.
For cases where the events on a thread are purely interprocedural, this
line does nothing except take up space and complicate the output.
This patch adds logic to omit it for such cases, simpifying the output,
and, I believe, improving readability.
gcc/ChangeLog:
* diagnostic-path.h: Update leading comment to reflect
intraprocedural cases. Fix typo in comment.
* doc/invoke.texi: Update intraprocedural example.
gcc/testsuite/ChangeLog:
* c-c++-common/analyzer/allocation-size-multiline-1.c: Update
expected results for purely intraprocedural path.
* c-c++-common/analyzer/allocation-size-multiline-2.c: Likewise.
* c-c++-common/analyzer/allocation-size-multiline-3.c: Likewise.
* c-c++-common/analyzer/analyzer-verbosity-0.c: Likewise.
* c-c++-common/analyzer/analyzer-verbosity-1.c: Likewise.
* c-c++-common/analyzer/analyzer-verbosity-2.c: Likewise.
* c-c++-common/analyzer/analyzer-verbosity-3.c: Likewise.
* c-c++-common/analyzer/malloc-macro-inline-events.c: Likewise.
Doing so for this file requires a rewrite since the paths
prefixing the "in expansion of macro" lines become the only thing
on their line and so are no longer pruned by multiline.exp logic
for pruning extra content on non-blank lines.
* c-c++-common/analyzer/malloc-paths-9-noexcept.c: Likewise.
* c-c++-common/analyzer/setjmp-2.c: Likewise.
* gcc.dg/analyzer/malloc-paths-9.c: Likewise.
* gcc.dg/analyzer/out-of-bounds-multiline-2.c: Likewise.
* gcc.dg/plugin/diagnostic-test-paths-2.c: Likewise.
gcc/ChangeLog:
* tree-diagnostic-path.cc (per_thread_summary::interprocedural_p):
New.
(thread_event_printer::print_swimlane_for_event_range): Don't
indent and print the stack depth line if this thread's events are
purely intraprocedural.
(selftest::test_intraprocedural_path): Update expected output.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/copy_from_user-1.c: Add missing directives for an
analyzer test.
* gcc.dg/plugin/taint-CVE-2011-0521-1-fixed.c: Add missing
-fanalyzer to options.
* gcc.dg/plugin/taint-CVE-2011-0521-1.c: Likewise.
* gcc.dg/plugin/taint-CVE-2011-0521-2-fixed.c: Likewise.
(dvb_usercopy): Add default case to avoid complaints about NULL
derefs.
* gcc.dg/plugin/taint-CVE-2011-0521-2.c: Likewise.
* gcc.dg/plugin/taint-CVE-2011-0521-3-fixed.c: Add missing
-fanalyzer to options.
* gcc.dg/plugin/taint-CVE-2011-0521-3.c: Likewise. Drop
xfail.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
PR analyzer/112974 and PR analyzer/112975 record false positives
from the analyzer's taint detection where sanitization of the form
if (VALUE CMP VALUE-OF-WIDER-TYPE)
happens, but wasn't being "noticed" by the taint checker, due to the
test being:
(WIDER_TYPE)VALUE CMP VALUE-OF-WIDER-TYPE
at the gimple level, and thus taint_state_machine recording
sanitization of (WIDER_TYPE)VALUE, but not of VALUE.
Fix by stripping casts in taint_state_machine::on_condition so that
the state machine records sanitization of the underlying value.
gcc/analyzer/ChangeLog:
PR analyzer/112974
PR analyzer/112975
* sm-taint.cc (taint_state_machine::on_condition): Strip away
casts before considering LHS and RHS, to increase the chance of
detecting places where sanitization of a value may have happened.
gcc/testsuite/ChangeLog:
PR analyzer/112974
PR analyzer/112975
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add
taint-pr112974.c and taint-pr112975.c to analyzer_kernel_plugin.c.
* gcc.dg/plugin/taint-pr112974.c: New test.
* gcc.dg/plugin/taint-pr112975.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Solaris
gcc.dg/plugin/crash-test-write-though-null-sarif.c FAILs on Solaris:
FAIL: gcc.dg/plugin/crash-test-write-though-null-sarif.c -fplugin=./crash_test_plugin.so scan-sarif-file "text": "Segmentation fault
Comparing the sarif files between Linux and Solaris reveals
- "message": {"text": "Segmentation fault"},
+ "message": {"text": "Segmentation Fault"},
This patch allows for both forms.
Tested on i386-pc-solaris2.11, sparc-sun-solaris2.11, and
x86_64-pc-linux-gnu.
2024-02-22 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
gcc/testsuite:
* gcc.dg/plugin/crash-test-write-though-null-sarif.c
(scan-sarif-file): Allow for "Segmentation Fault", too.
|
|
Confusion in binding_cluster::maybe_get_compound_binding about whether
offsets are relative to the start of the region or to the start of the
cluster was leading to incorrect handling of default values, leading
to false positives from -Wanalyzer-use-of-uninitialized-value, from
-Wanalyzer-exposure-through-uninit-copy, and other logic errors.
Fixed thusly.
gcc/analyzer/ChangeLog:
PR analyzer/112969
* store.cc (binding_cluster::maybe_get_compound_binding): When
populating default_map, express the bit-range of the default key
for REG relative to REG, rather than to the base region.
gcc/testsuite/ChangeLog:
PR analyzer/112969
* c-c++-common/analyzer/compound-assignment-5.c (test_3): Remove
xfails, reorder tests.
* c-c++-common/analyzer/compound-assignment-pr112969.c: New test.
* gcc.dg/plugin/infoleak-pr112969.c: New test.
* gcc.dg/plugin/plugin.exp: Add infoleak-pr112969.c to
analyzer_kernel_plugin.c tests.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
gcc/analyzer/ChangeLog:
PR analyzer/112977
* engine.cc (impl_region_model_context::on_liveness_change): Pass
m_ext_state to sm_state_map::on_liveness_change.
* program-state.cc (sm_state_map::on_svalue_leak): Guard removal
of map entry based on can_purge_p.
(sm_state_map::on_liveness_change): Add ext_state param. Add
workaround for bad interaction between state purging and
alt-inherited sm-state.
* program-state.h (sm_state_map::on_liveness_change): Add
ext_state param.
* sm-taint.cc
(taint_state_machine::has_alt_get_inherited_state_p): New.
(taint_state_machine::can_purge_p): Return false for "has_lb" and
"has_ub".
* sm.h (state_machine::has_alt_get_inherited_state_p): New vfunc.
gcc/testsuite/ChangeLog:
PR analyzer/112977
* gcc.dg/plugin/plugin.exp: Add taint-pr112977.c.
* gcc.dg/plugin/taint-pr112977.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
PR analyzer/112927 reports a false positive from -Wanalyzer-tainted-size
seen on the Linux kernel's drivers/char/ipmi/ipmi_devintf.c with the
analyzer kernel plugin.
The issue is that in:
(A):
if (msg->data_len > 272) {
return -90;
}
(B):
n = msg->data_len;
__check_object_size(to, n);
n = copy_from_user(to, from, n);
the analyzer is treating __check_object_size as having arbitrary side
effects, and, in particular could modify msg->data_len. Hence the
sanitization that occurs at (A) above is treated as being for a
different value than the size obtained at (B), hence the bogus warning
at the call to copy_from_user.
Fixed by extending the analyzer kernel plugin to "teach" it that
__check_object_size has no side effects.
gcc/testsuite/ChangeLog:
PR analyzer/112927
* gcc.dg/plugin/analyzer_kernel_plugin.c
(class known_function___check_object_size): New.
(kernel_analyzer_init_cb): Register it.
* gcc.dg/plugin/plugin.exp: Add taint-pr112927.c.
* gcc.dg/plugin/taint-pr112927.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
|
|
Add more test coverage for r14-6349-g0bef72539e585d.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/plugin.exp: Add taint-modulus.c to
analyzer_kernel_plugin.c tests.
* gcc.dg/plugin/taint-modulus.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
gcc/analyzer/ChangeLog:
* region-model.cc (contains_uninit_p): Only check for
svalues that the infoleak warning can handle.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/infoleak-uninit-size-1.c: New test.
* gcc.dg/plugin/infoleak-uninit-size-2.c: New test.
* gcc.dg/plugin/plugin.exp: Add the new tests.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
PR analyzer/112850 reports a false positive from
-Wanalyzer-tainted-allocation-size on the Linux kernel [1] where
-fanalyzer complains that an allocation size is attacker-controlled
despite the value being correctly sanitized against upper and lower
limits.
The root cause is that the expression is sufficiently complex
to exceed the -param=analyzer-max-svalue-depth= threshold,
currently at 12, with depth 13, and so it is treated as UNKNOWN.
Hence the sanitizations are seen as comparisons of an UNKNOWN
symbolic value against constants, and these were being ignored
by the taint state machine.
The expression in question is relatively typical for those seen in
Linux kernel ioctl handlers, and I was surprised that it had exceeded
the analyzer's default expression complexity limit.
This patch addresses this problem in three ways:
(a) the default value of the threshold parameter is increased, from 12
to 18, so that such expressions are precisely handled
(b) adding a new -Wanalyzer-symbol-too-complex to warn when the symbol
complexity limit is reached. This is off by default for users, and
on by default in the test suite.
(c) the taint state machine handles comparisons against UNKNOWN svalues
by dropping all taint information on that execution path, so that if
the complexity limit has been exceeded we don't generate false positives
As well as fixing the taint false positive (PR analyzer/112850), the
patch also fixes a couple of leak false positives seen on flex-generated
scanners (PR analyzer/103546).
[1] specifically, in sound/core/rawmidi.c's handler for
SNDRV_RAWMIDI_STREAM_OUTPUT.
gcc/ChangeLog:
PR analyzer/103546
PR analyzer/112850
* doc/invoke.texi: Add -Wanalyzer-symbol-too-complex.
gcc/analyzer/ChangeLog:
PR analyzer/103546
PR analyzer/112850
* analyzer.opt (-param=analyzer-max-svalue-depth=): Increase from
12 to 18.
(Wanalyzer-symbol-too-complex): New.
* diagnostic-manager.cc
(null_assignment_sm_context::clear_all_per_svalue_state): New.
* engine.cc (impl_sm_context::clear_all_per_svalue_state): New.
* program-state.cc (sm_state_map::clear_all_per_svalue_state):
New.
* program-state.h (sm_state_map::clear_all_per_svalue_state): New
decl.
* region-model-manager.cc
(region_model_manager::reject_if_too_complex): Add
-Wanalyzer-symbol-too-complex.
* sm-taint.cc (taint_state_machine::on_condition): Handle
comparisons against UNKNOWN.
* sm.h (sm_context::clear_all_per_svalue_state): New.
gcc/testsuite/ChangeLog:
PR analyzer/103546
PR analyzer/112850
* c-c++-common/analyzer/call-summaries-pr107158-2.c: Add
-Wno-analyzer-symbol-too-complex.
* c-c++-common/analyzer/call-summaries-pr107158.c: Likewise.
* c-c++-common/analyzer/deref-before-check-pr109060-haproxy-cfgparse.c:
Likewise.
* c-c++-common/analyzer/feasibility-3.c: Add
-Wno-analyzer-too-complex and -Wno-analyzer-symbol-too-complex.
* c-c++-common/analyzer/flex-with-call-summaries.c: Add
-Wno-analyzer-symbol-too-complex. Remove fail for
PR analyzer/103546 leak false positive.
* c-c++-common/analyzer/flex-without-call-summaries.c: Remove
xfail for PR analyzer/103546 leak false positive.
* c-c++-common/analyzer/infinite-recursion-3.c: Add
-Wno-analyzer-symbol-too-complex.
* c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c:
Likewise.
* c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c:
Likewise.
* c-c++-common/analyzer/null-deref-pr108400-SoftEtherVPN-WebUi.c:
Likewise.
* c-c++-common/analyzer/null-deref-pr108806-qemu.c: Likewise.
* c-c++-common/analyzer/null-deref-pr108830.c: Likewise.
* c-c++-common/analyzer/pr94596.c: Likewise.
* c-c++-common/analyzer/strtok-2.c: Likewise.
* c-c++-common/analyzer/strtok-4.c: Add -Wno-analyzer-too-complex
and -Wno-analyzer-symbol-too-complex.
* c-c++-common/analyzer/strtok-cppreference.c: Likewise.
* gcc.dg/analyzer/analyzer.exp: Add -Wanalyzer-symbol-too-complex
to DEFAULT_CFLAGS.
* gcc.dg/analyzer/attr-const-3.c: Add
-Wno-analyzer-symbol-too-complex.
* gcc.dg/analyzer/call-summaries-pr107072.c: Likewise.
* gcc.dg/analyzer/doom-s_sound-pr108867.c: Likewise.
* gcc.dg/analyzer/explode-4.c: Likewise.
* gcc.dg/analyzer/null-deref-pr102671-1.c: Likewise.
* gcc.dg/analyzer/null-deref-pr105755.c: Likewise.
* gcc.dg/analyzer/out-of-bounds-curl.c: Likewise.
* gcc.dg/analyzer/pr101503.c: Likewise.
* gcc.dg/analyzer/pr103892.c: Add -Wno-analyzer-too-complex and
-Wno-analyzer-symbol-too-complex.
* gcc.dg/analyzer/pr94851-4.c: Add
-Wno-analyzer-symbol-too-complex.
* gcc.dg/analyzer/pr96860-1.c: Likewise.
* gcc.dg/analyzer/pr96860-2.c: Likewise.
* gcc.dg/analyzer/pr98918.c: Likewise.
* gcc.dg/analyzer/pr99044-2.c: Likewise.
* gcc.dg/analyzer/uninit-pr108806-qemu.c: Likewise.
* gcc.dg/analyzer/use-after-free.c: Add -Wno-analyzer-too-complex
and -Wno-analyzer-symbol-too-complex.
* gcc.dg/plugin/plugin.exp: Add new tests for
analyzer_kernel_plugin.c.
* gcc.dg/plugin/taint-CVE-2011-0521-4.c: Update expected results.
* gcc.dg/plugin/taint-CVE-2011-0521-5.c: Likewise.
* gcc.dg/plugin/taint-CVE-2011-0521-6.c: Likewise.
* gcc.dg/plugin/taint-CVE-2011-0521-5-fixed.c: Remove xfail.
* gcc.dg/plugin/taint-pr112850-precise.c: New test.
* gcc.dg/plugin/taint-pr112850-too-complex.c: New test.
* gcc.dg/plugin/taint-pr112850-unsanitized.c: New test.
* gcc.dg/plugin/taint-pr112850.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Previously our JSON output emitted the JSON all on one line, with
no indentation to show the structure of the values.
Although it's easy to reformat such output (e.g. with
"python -m json.tool"), I've found it's a pain to need to do so
e.g. my text editor sometimes hangs when opening a multimegabyte
json file all on one line. Similarly diff-ing is easier if the
json is already formatted.
This patch add whitespace to json output to show the structure.
It turned out to be fairly easy to implement using pretty_printer's
existing indentation machinery.
The patch uses this formatting for the various JSON-based diagnostic
output formats.
For example, with this patch, the output from
fdiagnostics-format=json-stderr looks like:
[{"kind": "warning",
"message": "stack-based buffer overflow",
"option": "-Wanalyzer-out-of-bounds",
"option_url": "https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html#index-Wanalyzer-out-of-bounds",
"children": [{"kind": "note",
"message": "write of 350 bytes to beyond the end of ‘buf’",
"locations": [{"caret": {"file": "../../src/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-19.c",
"line": 20,
"display-column": 3,
"byte-column": 3,
"column": 3},
"finish": {"file": "../../src/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-19.c",
"line": 20,
"display-column": 27,
"byte-column": 27,
"column": 27}}],
"escape-source": false},
{"kind": "note",
"message": "valid subscripts for ‘buf’ are ‘[0]’ to ‘[99]’",
"locations": [{"caret": {"file": "../../src/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-19.c",
"line": 20,
"display-column": 3,
"byte-column": 3,
"column": 3},
"finish": {"file": "../../src/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-19.c",
"line": 20,
"display-column": 27,
"byte-column": 27,
"column": 27}}],
"escape-source": false}],
"column-origin": 1,
...snip...]
I was able to update almost all of our DejaGnu test cases for JSON to
handle this format tweak, and IMHO it improved the readability of these
test cases, but a couple were more awkward. Hence I added
-fno-diagnostics-json-formatting as an option to disable this
formatting.
The formatting does not affect the output of -fsave-optimization-record
or the JSON output from gcov (but this could be enabled if desirable).
gcc/analyzer/ChangeLog:
* engine.cc (dump_analyzer_json): Use
flag_diagnostics_json_formatting.
gcc/ChangeLog:
* common.opt (fdiagnostics-json-formatting): New.
* diagnostic-format-json.cc: Add "formatted" boolean
to json_output_format and subclasses, and to the
diagnostic_output_format_init_json_* functions. Use it when
printing JSON.
* diagnostic-format-sarif.cc: Likewise for sarif_builder,
sarif_output_format, and the various
diagnostic_output_format_init_sarif_* functions.
* diagnostic.cc (diagnostic_output_format_init): Add
"json_formatting" boolean and pass on to the various cases.
* diagnostic.h (diagnostic_output_format_init): Add
"json_formatted" param.
(diagnostic_output_format_init_json_stderr): Add "formatted" param
(diagnostic_output_format_init_json_file): Likewise.
(diagnostic_output_format_init_sarif_stderr): Likewise.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
* doc/invoke.texi (-fdiagnostics-format=json): Remove discussion
about JSON output needing formatting.
(-fno-diagnostics-json-formatting): Add.
* gcc.cc (driver_handle_option): Use
opts->x_flag_diagnostics_json_formatting.
* gcov.cc (generate_results): Pass "false" for new formatting
option when printing json.
* json.cc (value::dump): Add new "formatted" param.
(object::print): Likewise, using it to add whitespace to format
the JSON output.
(array::print): Likewise.
(float_number::print): Add new "formatted" param.
(integer_number::print): Likewise.
(string::print): Likewise.
(literal::print): Likewise.
(selftest::assert_print_eq): Add "formatted" param.
(ASSERT_PRINT_EQ): Add "FORMATTED" param.
(selftest::test_writing_objects): Test both formatted and
unformatted printing.
(selftest::test_writing_arrays): Likewise.
(selftest::test_writing_float_numbers): Update for new param of
ASSERT_PRINT_EQ.
(selftest::test_writing_integer_numbers): Likewise.
(selftest::test_writing_strings): Likewise.
(selftest::test_writing_literals): Likewise.
(selftest::test_formatting): New.
(selftest::json_cc_tests): Call it.
* json.h (value::print): Add "formatted" param.
(value::dump): Likewise.
(object::print): Likewise.
(array::print): Likewise.
(float_number::print): Likewise.
(integer_number::print): Likewise.
(string::print): Likewise.
(literal::print): Likewise.
* optinfo-emit-json.cc (optrecord_json_writer::write): Pass
"false" for new formatting option when printing json.
(selftest::test_building_json_from_dump_calls): Likewise.
* opts.cc (common_handle_option): Use
opts->x_flag_diagnostics_json_formatting.
gcc/testsuite/ChangeLog:
* c-c++-common/diagnostic-format-json-1.c: Update expected JSON
output to reflect whitespace.
* 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/diagnostic-format-json-stderr-1.c: Likewise.
* g++.dg/pr90462.C: Add -fno-diagnostics-json-formatting.
* gcc.dg/analyzer/malloc-sarif-1.c: Likewise.
* gcc.dg/plugin/diagnostic-test-paths-3.c: Update expected JSON
output to reflect whitespace.
* gfortran.dg/diagnostic-format-json-1.F90: Likewise.
* gfortran.dg/diagnostic-format-json-2.F90: Likewise.
* gfortran.dg/diagnostic-format-json-3.F90: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
No functional change intended.
gcc/c-family/ChangeLog:
* c-opts.cc (c_diagnostic_finalizer): Make "diagnostic" param
const.
gcc/cp/ChangeLog:
* cp-tree.h (cxx_print_error_function): Make diagnostic_info param
const.
* error.cc (cxx_print_error_function): Likewise.
(cp_diagnostic_starter): Likewise.
(cp_print_error_function): Likewise.
gcc/ChangeLog:
* diagnostic-format-json.cc (on_begin_diagnostic): Convert param
to const reference.
(on_end_diagnostic): Likewise.
(json_output_format::on_end_diagnostic): Likewise.
* diagnostic-format-sarif.cc
(sarif_invocation::add_notification_for_ice): Likewise.
(sarif_result::on_nested_diagnostic): Likewise.
(sarif_ice_notification::sarif_ice_notification): Likewise.
(sarif_builder::end_diagnostic): Likewise.
(sarif_builder::make_result_object): Likewise.
(make_reporting_descriptor_object_for_warning): Likewise.
(sarif_builder::make_locations_arr): Likewise.
(sarif_output_format::on_begin_diagnostic): Likewise.
(sarif_output_format::on_end_diagnostic): Likewise.
* diagnostic.cc (default_diagnostic_starter): Make diagnostic_info
param const.
(default_diagnostic_finalizer): Likewise.
(diagnostic_context::report_diagnostic): Pass diagnostic by
reference to on_{begin,end}_diagnostic.
(diagnostic_text_output_format::on_begin_diagnostic): Convert
param to const reference.
(diagnostic_text_output_format::on_end_diagnostic): Likewise.
* diagnostic.h (diagnostic_starter_fn): Make diagnostic_info param
const.
(diagnostic_finalizer_fn): Likeewise.
(diagnostic_output_format::on_begin_diagnostic): Convert param to
const reference.
(diagnostic_output_format::on_end_diagnostic): Likewise.
(diagnostic_text_output_format::on_begin_diagnostic): Likewise.
(diagnostic_text_output_format::on_end_diagnostic): Likewise.
(default_diagnostic_starter): Make diagnostic_info param const.
(default_diagnostic_finalizer): Likewise.
* langhooks-def.h (lhd_print_error_function): Make diagnostic_info
param const.
* langhooks.cc (lhd_print_error_function): Likewise.
* langhooks.h (lang_hooks::print_error_function): Likewise.
* tree-diagnostic.cc (diagnostic_report_current_function):
Likewise.
(default_tree_diagnostic_starter): Likewise.
(virt_loc_aware_diagnostic_finalizer): Likewise.
* tree-diagnostic.h (diagnostic_report_current_function):
Likewise.
(virt_loc_aware_diagnostic_finalizer): Likewise.
gcc/fortran/ChangeLog:
* error.cc (gfc_diagnostic_starter): Make diagnostic_info param
const.
(gfc_diagnostic_finalizer): Likewise.
gcc/jit/ChangeLog:
* dummy-frontend.cc (jit_begin_diagnostic): Make diagnostic_info
param const.
(jit_end_diagnostic): Likewise. Pass to add_diagnostic by
reference.
* jit-playback.cc (jit::playback::context::add_diagnostic):
Convert diagnostic_info to const reference.
* jit-playback.h (jit::playback::context::add_diagnostic):
Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/plugin/show_template_tree_color_plugin.c
(noop_starter_fn): Make diagnostic_info param const.
* gcc.dg/plugin/diagnostic_group_plugin.c
(test_diagnostic_starter): Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(custom_diagnostic_finalizer): Likewise.
* gcc.dg/plugin/location_overflow_plugin.c
(verify_unpacked_ranges): Likewise.
(verify_no_columns): Likewise.
libcc1/ChangeLog:
* context.cc (plugin_print_error_function): Make diagnostic_info
param const.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|