Regtested and bootstrapped on x86_64-pc-linux-gnu.

-- >8 --

When -MD, -fdeps-format=p1689r5 and -save-temps are used without
explicit output files, they default to the same stream, which is
invalid. The error message attempted to print fdeps_file, but this is
NULL in this case, causing an ICE.

Use out_fname as a fallback when fdeps_file is NULL to avoid the ICE
and provide a meaningful error message.

Fix suggested by Andrew Pinski.

        PR c++/121864

gcc/c-family/ChangeLog:

        * c-opts.cc (c_common_finish): Use out_fname as fallback when
        fdeps_file is NULL in error message.

Signed-off-by: Egas Ribeiro <[email protected]>
---
 gcc/c-family/c-opts.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index 8da51759dfd..4ad5a0278c9 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -1490,7 +1490,7 @@ c_common_finish (void)
        }
       if (fdeps_stream == deps_stream && fdeps_stream != stdout)
        fatal_error (input_location, "%<-MF%> and %<-fdeps-file=%> cannot share 
an output file %s: %m",
-                    fdeps_file);
+                    fdeps_file ? fdeps_file : out_fname);
     }
 
   /* For performance, avoid tearing down cpplib's internal structures
-- 
2.52.0

Reply via email to