]> git.ipfire.org Git - thirdparty/gcc.git/commit
diagnostics: fix crash-handling inside nested diagnostics [PR121876]
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 12 Sep 2025 14:24:36 +0000 (10:24 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Fri, 12 Sep 2025 14:24:36 +0000 (10:24 -0400)
commit38cb4289180d13a71c2e1005223f442747bcf56e
tree7a906fc5f18ecf0f97777194af47c43145e5d571
parent85a97e1a8ee934f46b89958b8374dd880dd489a4
diagnostics: fix crash-handling inside nested diagnostics [PR121876]

PR diagnostics/121876 tracks an issue inside our crash-handling, where
if an ICE happens when we're within a nested diagnostic, an assertion
fails inside diagnostic::context::set_diagnostic_buffer, leading to
a 2nd ICE.  Happily, this does not infinitely recurse, but it obscures
the original ICE and the useful part of the backtrace, and any SARIF or
HTML sinks we were writing to are left as empty files.

This patch tweaks the above so that the assertion doesn't fail, and adds
test coverage (via a plugin) to ensure that such ICEs/crashes are
gracefully handled and e.g. captured in SARIF/HTML output.

gcc/ChangeLog:
PR diagnostics/121876
* diagnostics/buffering.cc (context::set_diagnostic_buffer): Add
early reject of the no-op case.

gcc/testsuite/ChangeLog:
PR diagnostics/121876
* gcc.dg/plugin/crash-test-nested-ice-html.py: New test.
* gcc.dg/plugin/crash-test-nested-ice-sarif.py: New test.
* gcc.dg/plugin/crash-test-nested-ice.c: New test.
* gcc.dg/plugin/crash-test-nested-write-through-null-html.py: New test.
* gcc.dg/plugin/crash-test-nested-write-through-null-sarif.py: New test.
* gcc.dg/plugin/crash-test-nested-write-through-null.c: New test.
* gcc.dg/plugin/crash_test_plugin.cc: Add "nested" argument, and when
set, inject the problem within a nested diagnostic.
* gcc.dg/plugin/plugin.exp: Add crash-test-nested-ice.c and
crash-test-nested-write-through-null.c.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/diagnostics/buffering.cc
gcc/testsuite/gcc.dg/plugin/crash-test-nested-ice-html.py [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugin/crash-test-nested-ice-sarif.py [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugin/crash-test-nested-ice.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugin/crash-test-nested-write-through-null-html.py [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugin/crash-test-nested-write-through-null-sarif.py [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugin/crash-test-nested-write-through-null.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugin/crash_test_plugin.cc
gcc/testsuite/gcc.dg/plugin/plugin.exp