Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r16-3828-g259347de43e965.
gcc/ChangeLog:
PR diagnostics/120063
* diagnostics/context.cc (context::execution_failed_p): Also treat
any kind::fatal errors as leading to failed execution.
* diagnostics/sarif-sink.cc (maybe_get_sarif_level): Handle
kind::fatal as SARIF level "error".
gcc/testsuite/ChangeLog:
PR diagnostics/120063
* gcc.dg/fatal-error.c: New test.
* gcc.dg/fatal-error-html.py: New test.
* gcc.dg/fatal-error-sarif.py: New test.
---
gcc/diagnostics/context.cc | 5 ++--
gcc/diagnostics/sarif-sink.cc | 1 +
gcc/testsuite/gcc.dg/fatal-error-html.py | 28 ++++++++++++++++++++++
gcc/testsuite/gcc.dg/fatal-error-sarif.py | 29 +++++++++++++++++++++++
gcc/testsuite/gcc.dg/fatal-error.c | 11 +++++++++
5 files changed, 71 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/fatal-error-html.py
create mode 100644 gcc/testsuite/gcc.dg/fatal-error-sarif.py
create mode 100644 gcc/testsuite/gcc.dg/fatal-error.c
diff --git a/gcc/diagnostics/context.cc b/gcc/diagnostics/context.cc
index 0f8670ba806e..139c022a6027 100644
--- a/gcc/diagnostics/context.cc
+++ b/gcc/diagnostics/context.cc
@@ -463,9 +463,8 @@ context::dump (FILE *outfile, int indent) const
bool
context::execution_failed_p () const
{
- /* Equivalent to (seen_error () || werrorcount), but on
- this context, rather than global_dc. */
- return (diagnostic_count (kind::error)
+ return (diagnostic_count (kind::fatal)
+ || diagnostic_count (kind::error)
|| diagnostic_count (kind::sorry)
|| diagnostic_count (kind::werror));
}
diff --git a/gcc/diagnostics/sarif-sink.cc b/gcc/diagnostics/sarif-sink.cc
index c85a35e4f631..bc121388bb87 100644
--- a/gcc/diagnostics/sarif-sink.cc
+++ b/gcc/diagnostics/sarif-sink.cc
@@ -1980,6 +1980,7 @@ maybe_get_sarif_level (enum kind diag_kind)
{
case kind::warning:
return "warning";
+ case kind::fatal:
case kind::error:
return "error";
case kind::note:
diff --git a/gcc/testsuite/gcc.dg/fatal-error-html.py
b/gcc/testsuite/gcc.dg/fatal-error-html.py
new file mode 100644
index 000000000000..b7e7a680ce86
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fatal-error-html.py
@@ -0,0 +1,28 @@
+from htmltest import *
+
+import pytest
+
[email protected](scope='function', autouse=True)
+def html_tree():
+ return html_tree_from_env()
+
+def test_results(html_tree):
+ root = html_tree.getroot ()
+ assert root.tag == make_tag('html')
+
+ head = root.find('xhtml:head', ns)
+ assert head is not None
+
+ body = root.find('xhtml:body', ns)
+ assert body is not None
+
+ diag_list = body.find("./xhtml:div[@class='gcc-diagnostic-list']", ns)
+ assert len(diag_list)
+
+ diag = diag_list.find('xhtml:div[@id="gcc-diag-0"]', ns)
+ assert diag is not None
+ message = diag.find("./xhtml:div[@class='gcc-message']", ns)
+ assert message is not None
+ assert message[0].tag == make_tag('strong')
+ assert message[0].text == 'fatal error: '
+ assert message[0].tail.startswith(' this-does-not-exist.h:')
diff --git a/gcc/testsuite/gcc.dg/fatal-error-sarif.py
b/gcc/testsuite/gcc.dg/fatal-error-sarif.py
new file mode 100644
index 000000000000..4c434ed8dcf1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fatal-error-sarif.py
@@ -0,0 +1,29 @@
+from sarif import *
+
+import pytest
+
[email protected](scope='function', autouse=True)
+def sarif():
+ return sarif_from_env()
+
+def test_execution_unsuccessful(sarif):
+ runs = sarif['runs']
+ run = runs[0]
+
+ invocations = run['invocations']
+ assert len(invocations) == 1
+ invocation = invocations[0]
+
+ # We expect the fatal error to make executionSuccessful be false
+ assert invocation['executionSuccessful'] == False
+
+def test_fatal_error(sarif):
+ runs = sarif['runs']
+ run = runs[0]
+ results = run['results']
+
+ assert len(results) == 1
+
+ result = results[0]
+ assert result['level'] == 'error'
+ assert result['message']['text'] == "this-does-not-exist.h: No such file
or directory"
diff --git a/gcc/testsuite/gcc.dg/fatal-error.c
b/gcc/testsuite/gcc.dg/fatal-error.c
new file mode 100644
index 000000000000..54f90079d9f3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fatal-error.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fdiagnostics-add-output=sarif" } */
+/* { dg-additional-options
"-fdiagnostics-add-output=experimental-html:javascript=no" } */
+
+#include "this-does-not-exist.h"
+
+/* { dg-prune-output "fatal error:" }
+ { dg-prune-output "compilation terminated" }
+ { dg-final { verify-sarif-file } }
+ { dg-final { run-sarif-pytest fatal-error.c "fatal-error-sarif.py" } }
+ { dg-final { run-html-pytest fatal-error.c "fatal-error-html.py" } } */
--
2.26.3