https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121864
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #4)
> Which means out_stream is also deps_stream .
Because deps_stream has a similar logic above:
if (cpp_opts->deps.style != DEPS_NONE)
{
/* If -M or -MM was seen without -MF, default output to the
output stream. */
if (!deps_file)
deps_stream = out_stream;
else if (deps_file[0] == '-' && deps_file[1] == '\0')
deps_stream = stdout;
else
{
deps_stream = fopen (deps_file, deps_append ? "a" : "w");
if (!deps_stream)
fatal_error (input_location, "opening dependency file %s: %m",
deps_file);
}
}
So this patch should fix it:
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index 0ec30e85215..9faa8755cb0 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -1476,7 +1476,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