From: "Martin Liška" <mliska@suse.cz>
To: David Malcolm <dmalcolm@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file
Date: Tue, 10 Jan 2023 16:10:31 +0100 [thread overview]
Message-ID: <3cf31374-0496-3119-7775-0c22bc03cb38@suse.cz> (raw)
In-Reply-To: <d8949e7d59ffdac81a0d3bf38fdce379486579cb.camel@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 802 bytes --]
On 1/6/23 14:21, David Malcolm wrote:
> On Fri, 2023-01-06 at 12:33 +0100, Martin Liška wrote:
>> Patch can bootstrap on x86_64-linux-gnu and survives regression
>> tests.
>
> Thanks for the patch.
>
> I noticed that you marked PR 108307 as a dup of this, which covers
> -fdiagnostics-format=sarif-file (and a .S file as input).
>
> The patch doesn't add any test coverage (for either of the diagnostic
> formats).
>
> If we try to emit a diagnostic and base_file_name is NULL, and the user
> requested one of -fdiagnostics-format={json,sarif}-file, where do the
> diagnostics go? Where should they go?
Hey.
I've done a new version of the patch where I utilize x_main_input_basename.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
[-- Attachment #2: 0001-middle-end-always-find-a-basename-for-fdiagnostics-f.patch --]
[-- Type: text/x-patch, Size: 2506 bytes --]
From 078233b4f84ae6d81a7327589723b2be518d29ca Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Tue, 10 Jan 2023 15:14:05 +0100
Subject: [PATCH] middle-end: always find a basename for -fdiagnostics-format=*
In some situations, x_dump_base_name is NULL and thus we can
and should use x_main_input_basename which should never be NULL.
PR middle-end/106133
gcc/ChangeLog:
* gcc.cc (driver_handle_option): Use x_main_input_basename
if x_dump_base_name is null.
* opts.cc (common_handle_option): Likewise.
gcc/testsuite/ChangeLog:
* c-c++-common/pr106133.c: New test.
---
gcc/gcc.cc | 10 +++++++---
gcc/opts.cc | 10 +++++++---
gcc/testsuite/c-c++-common/pr106133.c | 3 +++
3 files changed, 17 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/c-c++-common/pr106133.c
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index d629ca5e424..382ca817a09 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -4290,9 +4290,13 @@ driver_handle_option (struct gcc_options *opts,
break;
case OPT_fdiagnostics_format_:
- diagnostic_output_format_init (dc, opts->x_dump_base_name,
- (enum diagnostics_output_format)value);
- break;
+ {
+ const char *basename = (opts->x_dump_base_name ? opts->x_dump_base_name
+ : opts->x_main_input_basename);
+ diagnostic_output_format_init (dc, basename,
+ (enum diagnostics_output_format)value);
+ break;
+ }
case OPT_Wa_:
{
diff --git a/gcc/opts.cc b/gcc/opts.cc
index 9ba47d7deaa..4809c18a529 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -2863,9 +2863,13 @@ common_handle_option (struct gcc_options *opts,
break;
case OPT_fdiagnostics_format_:
- diagnostic_output_format_init (dc, opts->x_dump_base_name,
- (enum diagnostics_output_format)value);
- break;
+ {
+ const char *basename = (opts->x_dump_base_name ? opts->x_dump_base_name
+ : opts->x_main_input_basename);
+ diagnostic_output_format_init (dc, basename,
+ (enum diagnostics_output_format)value);
+ break;
+ }
case OPT_fdiagnostics_parseable_fixits:
dc->extra_output_kind = (value
diff --git a/gcc/testsuite/c-c++-common/pr106133.c b/gcc/testsuite/c-c++-common/pr106133.c
new file mode 100644
index 00000000000..7d2c5afe417
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr106133.c
@@ -0,0 +1,3 @@
+/* PR middle-end/106133 */
+/* { dg-do compile } */
+/* { dg-options "-fdiagnostics-format=json-file -E" } */
--
2.39.0
next prev parent reply other threads:[~2023-01-10 15:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-06 11:33 Martin Liška
2023-01-06 13:21 ` David Malcolm
2023-01-10 15:10 ` Martin Liška [this message]
2023-01-24 13:34 ` Martin Liška
2023-02-01 13:13 ` Martin Liška
2023-02-17 14:52 ` Martin Liška
2023-02-27 9:49 ` Martin Liška
2023-03-16 10:05 ` Martin Liška
2023-03-16 14:45 ` David Malcolm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3cf31374-0496-3119-7775-0c22bc03cb38@suse.cz \
--to=mliska@suse.cz \
--cc=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).