public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file
@ 2023-01-06 11:33 Martin Liška
  2023-01-06 13:21 ` David Malcolm
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Liška @ 2023-01-06 11:33 UTC (permalink / raw)
  To: gcc-patches; +Cc: David Malcolm

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

	PR middle-end/106133

gcc/ChangeLog:

	* diagnostic.cc (diagnostic_output_format_init): If
	-fdiagnostics-format=json-file and -E is used, then
	base_file_name is null and we should not emit anything.
---
 gcc/diagnostic.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index c90c14e993e..fe7d121e340 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -2277,6 +2277,9 @@ diagnostic_output_format_init (diagnostic_context *context,
 			       const char *base_file_name,
 			       enum diagnostics_output_format format)
 {
+  if (base_file_name == NULL)
+    return;
+
   switch (format)
     {
     default:
-- 
2.39.0


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

* Re: [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file
  2023-01-06 11:33 [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file Martin Liška
@ 2023-01-06 13:21 ` David Malcolm
  2023-01-10 15:10   ` Martin Liška
  0 siblings, 1 reply; 9+ messages in thread
From: David Malcolm @ 2023-01-06 13:21 UTC (permalink / raw)
  To: Martin Liška, gcc-patches

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?


Dave



> 
> Ready to be installed?
> Thanks,
> Martin
> 
>         PR middle-end/106133
> 
> gcc/ChangeLog:
> 
>         * diagnostic.cc (diagnostic_output_format_init): If
>         -fdiagnostics-format=json-file and -E is used, then
>         base_file_name is null and we should not emit anything.
> ---
>  gcc/diagnostic.cc | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
> index c90c14e993e..fe7d121e340 100644
> --- a/gcc/diagnostic.cc
> +++ b/gcc/diagnostic.cc
> @@ -2277,6 +2277,9 @@ diagnostic_output_format_init
> (diagnostic_context *context,
>                                const char *base_file_name,
>                                enum diagnostics_output_format format)
>  {
> +  if (base_file_name == NULL)
> +    return;
> +
>    switch (format)
>      {
>      default:


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

* Re: [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file
  2023-01-06 13:21 ` David Malcolm
@ 2023-01-10 15:10   ` Martin Liška
  2023-01-24 13:34     ` Martin Liška
  2023-03-16 14:45     ` David Malcolm
  0 siblings, 2 replies; 9+ messages in thread
From: Martin Liška @ 2023-01-10 15:10 UTC (permalink / raw)
  To: David Malcolm, gcc-patches

[-- 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


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

* Re: [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file
  2023-01-10 15:10   ` Martin Liška
@ 2023-01-24 13:34     ` Martin Liška
  2023-02-01 13:13       ` Martin Liška
  2023-03-16 14:45     ` David Malcolm
  1 sibling, 1 reply; 9+ messages in thread
From: Martin Liška @ 2023-01-24 13:34 UTC (permalink / raw)
  To: David Malcolm, gcc-patches

PING^1

On 1/10/23 16:10, Martin Liška wrote:
> 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


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

* Re: [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file
  2023-01-24 13:34     ` Martin Liška
@ 2023-02-01 13:13       ` Martin Liška
  2023-02-17 14:52         ` Martin Liška
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Liška @ 2023-02-01 13:13 UTC (permalink / raw)
  To: David Malcolm, gcc-patches

PING^2

On 1/24/23 14:34, Martin Liška wrote:
> PING^1
> 
> On 1/10/23 16:10, Martin Liška wrote:
>> 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
> 


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

* Re: [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file
  2023-02-01 13:13       ` Martin Liška
@ 2023-02-17 14:52         ` Martin Liška
  2023-02-27  9:49           ` Martin Liška
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Liška @ 2023-02-17 14:52 UTC (permalink / raw)
  To: David Malcolm, gcc-patches

PING^3

On 2/1/23 14:13, Martin Liška wrote:
> PING^2
> 
> On 1/24/23 14:34, Martin Liška wrote:
>> PING^1
>>
>> On 1/10/23 16:10, Martin Liška wrote:
>>> 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
>>
> 


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

* Re: [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file
  2023-02-17 14:52         ` Martin Liška
@ 2023-02-27  9:49           ` Martin Liška
  2023-03-16 10:05             ` Martin Liška
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Liška @ 2023-02-27  9:49 UTC (permalink / raw)
  To: David Malcolm, gcc-patches

PING^4

On 2/17/23 15:52, Martin Liška wrote:
> PING^3
> 
> On 2/1/23 14:13, Martin Liška wrote:
>> PING^2
>>
>> On 1/24/23 14:34, Martin Liška wrote:
>>> PING^1
>>>
>>> On 1/10/23 16:10, Martin Liška wrote:
>>>> 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
>>>
>>
> 


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

* Re: [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file
  2023-02-27  9:49           ` Martin Liška
@ 2023-03-16 10:05             ` Martin Liška
  0 siblings, 0 replies; 9+ messages in thread
From: Martin Liška @ 2023-03-16 10:05 UTC (permalink / raw)
  To: David Malcolm, gcc-patches

PING^5

On 2/27/23 10:49, Martin Liška wrote:
> PING^4
> 
> On 2/17/23 15:52, Martin Liška wrote:
>> PING^3
>>
>> On 2/1/23 14:13, Martin Liška wrote:
>>> PING^2
>>>
>>> On 1/24/23 14:34, Martin Liška wrote:
>>>> PING^1
>>>>
>>>> On 1/10/23 16:10, Martin Liška wrote:
>>>>> 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
>>>>
>>>
>>
> 


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

* Re: [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file
  2023-01-10 15:10   ` Martin Liška
  2023-01-24 13:34     ` Martin Liška
@ 2023-03-16 14:45     ` David Malcolm
  1 sibling, 0 replies; 9+ messages in thread
From: David Malcolm @ 2023-03-16 14:45 UTC (permalink / raw)
  To: Martin Liška, gcc-patches

On Tue, 2023-01-10 at 16:10 +0100, Martin Liška wrote:
> 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?

Sorry about the long delay; the updated patch is good for trunk.

Thanks
Dave


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

end of thread, other threads:[~2023-03-16 14:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-06 11:33 [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file Martin Liška
2023-01-06 13:21 ` David Malcolm
2023-01-10 15:10   ` Martin Liška
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

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).