diagnostics: fix crash with -fdiagnostics-format=json-file

Message ID 60f9fd2b-211e-c1d5-e17a-1fab1ee51338@suse.cz
State Accepted
Headers
Series diagnostics: fix crash with -fdiagnostics-format=json-file |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Martin Liška Jan. 6, 2023, 11:33 a.m. UTC
  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(+)
  

Comments

David Malcolm Jan. 6, 2023, 1:21 p.m. UTC | #1
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:
  
Martin Liška Jan. 10, 2023, 3:10 p.m. UTC | #2
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
  
Martin Liška Jan. 24, 2023, 1:34 p.m. UTC | #3
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
  
Martin Liška Feb. 1, 2023, 1:13 p.m. UTC | #4
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
>
  
Martin Liška Feb. 17, 2023, 2:52 p.m. UTC | #5
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
>>
>
  
Martin Liška Feb. 27, 2023, 9:49 a.m. UTC | #6
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
>>>
>>
>
  
Martin Liška March 16, 2023, 10:05 a.m. UTC | #7
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
>>>>
>>>
>>
>
  
David Malcolm March 16, 2023, 2:45 p.m. UTC | #8
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
  

Patch

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: