https://gcc.gnu.org/g:0e7296540be35831e791ffe9f419cd6107831fc9
commit r16-1715-g0e7296540be35831e791ffe9f419cd6107831fc9 Author: David Malcolm <dmalc...@redhat.com> Date: Thu Jun 26 13:28:50 2025 -0400 diagnostics, testsuite: don't assume host has "dot" [PR120809] gcc/ChangeLog: PR analyzer/120809 * diagnostic-format-html.cc (html_builder::maybe_make_state_diagram): Bulletproof against the SVG generation failing. * xml.cc (xml::printer::push_element): Assert that the ptr is nonnull. (xml::printer::append): Likewise. gcc/testsuite/ChangeLog: PR analyzer/120809 * gcc.dg/analyzer/state-diagram-5.c: Split out into... * gcc.dg/analyzer/state-diagram-5-html.c: ...this, adding dg-require-dot... * gcc.dg/analyzer/state-diagram-5-sarif.c: ...and this. Signed-off-by: David Malcolm <dmalc...@redhat.com> Diff: --- gcc/diagnostic-format-html.cc | 3 +- .../{state-diagram-5.c => state-diagram-5-html.c} | 11 ++----- .../gcc.dg/analyzer/state-diagram-5-sarif.c | 35 ++++++++++++++++++++++ gcc/xml.cc | 2 ++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/gcc/diagnostic-format-html.cc b/gcc/diagnostic-format-html.cc index 1f5c138bcd08..473880fce245 100644 --- a/gcc/diagnostic-format-html.cc +++ b/gcc/diagnostic-format-html.cc @@ -632,7 +632,8 @@ html_builder::maybe_make_state_diagram (const diagnostic_event &event) // Turn the .dot into SVG and splice into place auto svg = dot::make_svg_from_graph (*graph); - xp.append (std::move (svg)); + if (svg) + xp.append (std::move (svg)); return wrapper; } diff --git a/gcc/testsuite/gcc.dg/analyzer/state-diagram-5.c b/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-html.c similarity index 64% rename from gcc/testsuite/gcc.dg/analyzer/state-diagram-5.c rename to gcc/testsuite/gcc.dg/analyzer/state-diagram-5-html.c index 8e00cac06863..274a951769e9 100644 --- a/gcc/testsuite/gcc.dg/analyzer/state-diagram-5.c +++ b/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-html.c @@ -1,4 +1,4 @@ -/* { dg-additional-options "-fdiagnostics-add-output=sarif:xml-state=yes" } */ +/* { dg-require-dot "" } */ /* { dg-additional-options "-fdiagnostics-add-output=experimental-html:javascript=no,show-state-diagrams=yes" } */ /* { dg-additional-options "-fdiagnostics-show-caret" } */ @@ -36,13 +36,6 @@ void test (void) __analyzer_dump_path (); { dg-end-multiline-output "" } */ -/* Verify that some JSON was written to a file with the expected name. */ -/* { dg-final { verify-sarif-file } } */ - -/* Use a Python script to verify various properties about the generated - .sarif file: - { dg-final { run-sarif-pytest state-diagram-5.c "state-diagram-5-sarif.py" } } */ - /* Use a Python script to verify various properties about the generated .html file: - { dg-final { run-html-pytest state-diagram-5.c "state-diagram-5-html.py" } } */ + { dg-final { run-html-pytest state-diagram-5-html.c "state-diagram-5-html.py" } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.c b/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.c new file mode 100644 index 000000000000..28cf58042306 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.c @@ -0,0 +1,35 @@ +/* { dg-additional-options "-fdiagnostics-add-output=sarif:xml-state=yes" } */ + +#include "analyzer-decls.h" + +struct foo +{ + int m_ints[4]; +}; + +struct bar +{ + struct foo m_foos[3]; + int m_int; + char m_ch; +}; + +struct baz +{ + struct bar m_bars[2]; + struct foo m_foos[5]; +}; + +void test (void) +{ + struct baz baz_arr[2]; + baz_arr[1].m_bars[1].m_foos[2].m_ints[1] = 42; + __analyzer_dump_path (); /* { dg-message "path" } */ +} + +/* Verify that some JSON was written to a file with the expected name. */ +/* { dg-final { verify-sarif-file } } */ + +/* Use a Python script to verify various properties about the generated + .sarif file: + { dg-final { run-sarif-pytest state-diagram-5-sarif.c "state-diagram-5-sarif.py" } } */ diff --git a/gcc/xml.cc b/gcc/xml.cc index 6bb269a2a19e..8e11c6783425 100644 --- a/gcc/xml.cc +++ b/gcc/xml.cc @@ -317,6 +317,7 @@ printer::add_raw (std::string text) void printer::push_element (std::unique_ptr<element> new_element) { + gcc_assert (new_element.get ()); element *parent = m_open_tags.back (); m_open_tags.push_back (new_element.get ()); parent->add_child (std::move (new_element)); @@ -325,6 +326,7 @@ printer::push_element (std::unique_ptr<element> new_element) void printer::append (std::unique_ptr<node> new_node) { + gcc_assert (new_node.get ()); element *parent = m_open_tags.back (); parent->add_child (std::move (new_node)); }