public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/PR106133-json-diagnostics-fix-v2)] middle-end: always find a basename for -fdiagnostics-format=*
@ 2023-01-10 14:15 Martin Liska
  0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2023-01-10 14:15 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:078233b4f84ae6d81a7327589723b2be518d29ca

commit 078233b4f84ae6d81a7327589723b2be518d29ca
Author: Martin Liska <mliska@suse.cz>
Date:   Tue Jan 10 15:14:05 2023 +0100

    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.

Diff:
---
 gcc/gcc.cc                            | 10 +++++++---
 gcc/opts.cc                           | 10 +++++++---
 gcc/testsuite/c-c++-common/pr106133.c |  3 +++
 3 files changed, 17 insertions(+), 6 deletions(-)

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" } */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-10 14:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-10 14:15 [gcc(refs/users/marxin/heads/PR106133-json-diagnostics-fix-v2)] middle-end: always find a basename for -fdiagnostics-format=* Martin Liska

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