]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
diagnostics, testsuite: don't assume host has "dot" [PR120809]
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 26 Jun 2025 17:28:50 +0000 (13:28 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 26 Jun 2025 17:28:50 +0000 (13:28 -0400)
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 <dmalcolm@redhat.com>
gcc/diagnostic-format-html.cc
gcc/testsuite/gcc.dg/analyzer/state-diagram-5-html.c [moved from gcc/testsuite/gcc.dg/analyzer/state-diagram-5.c with 64% similarity]
gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.c [new file with mode: 0644]
gcc/xml.cc

index 1f5c138bcd08558e6d4c0bce48df54bdf6a636eb..473880fce245cdb423a1654320a9b2cd0939f5e2 100644 (file)
@@ -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;
 }
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 8e00cac06863df1c5dc9f720906c951216c08df2..274a951769e9d82784ff4c87625ed5b2cc20d43a 100644 (file)
@@ -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 (file)
index 0000000..28cf580
--- /dev/null
@@ -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" } } */
index 6bb269a2a19e06f4ae3013876fc0165b42ccdd81..8e11c6783425b6d9022d2458b011cc030603ca89 100644 (file)
@@ -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));
 }