public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/109097] New: No SARIF output happens on an ICE
@ 2023-03-11  0:16 dmalcolm at gcc dot gnu.org
  2023-03-15 22:18 ` [Bug analyzer/109097] " cvs-commit at gcc dot gnu.org
  2023-03-15 22:22 ` dmalcolm at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2023-03-11  0:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109097

            Bug ID: 109097
           Summary: No SARIF output happens on an ICE
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: dmalcolm at gcc dot gnu.org
  Target Milestone: ---

If an ICE occurs inside cc1 with -fdiagnostics-format=sarif-file, then no
.sarif file is written out.

This is a nuisance e.g. for my integration testing of -fanalyzer, which I'm
gathering the results via the .sarif output; if it crashes on a particular
source file, then no output is generated, and it's effectively silent about the
crash.

I've been experimenting with adding SARIF output to the crash-handling code
(which I used to detect PR analyzer/109094); filing this bug to track this
work.

It's not clear how such crashes should be encoded in SARIF form; my prototype
emits them within the results array with with:
  ruleId": "internal compiler error"
but arguably as it's a failure of the analyzer rather than the
software-under-test such crashses should be captured as a SARIF 3.58
"notification" object.

Note to self: in one version of my prototypes there was an infinite loop where
a crash could happen in the crash-handling code, so need to be careful about
this.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug analyzer/109097] No SARIF output happens on an ICE
  2023-03-11  0:16 [Bug analyzer/109097] New: No SARIF output happens on an ICE dmalcolm at gcc dot gnu.org
@ 2023-03-15 22:18 ` cvs-commit at gcc dot gnu.org
  2023-03-15 22:22 ` dmalcolm at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-15 22:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109097

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <dmalcolm@gcc.gnu.org>:

https://gcc.gnu.org/g:79aaba0a71f34ac1ac2c4cec907ff74740a6cf1a

commit r13-6701-g79aaba0a71f34ac1ac2c4cec907ff74740a6cf1a
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Wed Mar 15 18:16:17 2023 -0400

    diagnostics: attempt to capture crash info in SARIF output [PR109097]

    As noted in PR analyzer/109097, if an internal compiler error occurs
    when -fdiagnostics-format=sarif-file is specified, we currently fail
    to write out a .sarif file, and the output to stderr doesn't contain
    "internal compiler error" or "Internal compiler error"; just the
    backtrace if we're lucky, and the "Please submit a full bug report"
    messages.

    This is a nuisance e.g. for my integration testing of -fanalyzer, where
    I'm gathering the results of builds via the .sarif output: if it crashes
    on a particular source file, then no output is generated, and it's
    effectively silent about the crash.

    This patch fixes things by adding a callback to diagnostic_context so
    that the SARIF output code can make one final attempt to write its
    output if an ICE occurs.  It also special-cases the output, so that an
    ICE is treated as an "error"-level "notification" relating to the
    operation of the tool (SARIF v2.1.0 section 3.58), rather than a
    "result" about the code being analyzed by the tool.

    The patch adds test coverage for this via a plugin that can inject:
    * calls to internal_compiler_error, and
    * writes through a NULL pointer
    and verifying that a  .sarif file is written out capturing the crash
    (and also that an ICE occurs via dg-ice, which seems to treat the ICE as
    an XFAIL, which is reasonable).

    I've added support for this to my integration-testing scripts: testing
    shows that with this patch we capture analyzer crashes in .sarif files
    (specifically, the analyzer crash on qemu: PR analyzer/109094), and I've
    updated my scripts to work with and report such output.

    I manually verified that the resulting .sarif files validate against the
    schema.

    gcc/ChangeLog:
            PR analyzer/109097
            * diagnostic-format-sarif.cc (class sarif_invocation): New.
            (class sarif_ice_notification): New.
            (sarif_builder::m_invocation_obj): New field.
            (sarif_invocation::add_notification_for_ice): New.
            (sarif_invocation::prepare_to_flush): New.
            (sarif_ice_notification::sarif_ice_notification): New.
            (sarif_builder::sarif_builder): Add m_invocation_obj.
            (sarif_builder::end_diagnostic): Special-case DK_ICE and
            DK_ICE_NOBT.
            (sarif_builder::flush_to_file): Call prepare_to_flush on
            m_invocation_obj.  Pass the latter to make_top_level_object.
            (sarif_builder::make_result_object): Move creation of "locations"
            array to...
            (sarif_builder::make_locations_arr): ...this new function.
            (sarif_builder::make_top_level_object): Add "invocation_obj" param
            and pass it to make_run_object.
            (sarif_builder::make_run_object): Add "invocation_obj" param and
            use it.
            (sarif_ice_handler): New callback.
            (diagnostic_output_format_init_sarif): Wire up sarif_ice_handler.
            * diagnostic.cc (diagnostic_initialize): Initialize new field
            "ice_handler_cb".
            (diagnostic_action_after_output): If it is set, make one attempt
            to call ice_handler_cb.
            * diagnostic.h (diagnostic_context::ice_handler_cb): New field.

    gcc/testsuite/ChangeLog:
            PR analyzer/109097
            * c-c++-common/diagnostic-format-sarif-file-1.c: Verify that we
            have an invocation object marked as succeeding, with no
            notifications.
            * gcc.dg/plugin/crash-test-ice-sarif.c: New test.
            * gcc.dg/plugin/crash-test-ice-stderr.c: New test.
            * gcc.dg/plugin/crash-test-write-though-null-sarif.c: New test.
            * gcc.dg/plugin/crash-test-write-though-null-stderr.c: New test.
            * gcc.dg/plugin/crash_test_plugin.c: New plugin.
            * gcc.dg/plugin/plugin.exp (plugin_test_list): Add the new plugin
            and test cases.

    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug analyzer/109097] No SARIF output happens on an ICE
  2023-03-11  0:16 [Bug analyzer/109097] New: No SARIF output happens on an ICE dmalcolm at gcc dot gnu.org
  2023-03-15 22:18 ` [Bug analyzer/109097] " cvs-commit at gcc dot gnu.org
@ 2023-03-15 22:22 ` dmalcolm at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2023-03-15 22:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109097

David Malcolm <dmalcolm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Should be fixed by the above commit; marking as resolved.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-15 22:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-11  0:16 [Bug analyzer/109097] New: No SARIF output happens on an ICE dmalcolm at gcc dot gnu.org
2023-03-15 22:18 ` [Bug analyzer/109097] " cvs-commit at gcc dot gnu.org
2023-03-15 22:22 ` dmalcolm at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).