Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk/15?
I tested this behaves correctly locally but I'm not sure how to add such
a testcase to DejaGNU.
-- >8 --
The driver uses the 'join' function to calculate the default output for
the -fdeps-file and -fdeps-target parameters from the parameter given to
-o (or the basename of the input file). But if the path given to -o has
any whitespace in it this causes cc1plus to see arguments like
"-o some file.o" "-fdeps-file=some" "file.ddi"
which breaks. Fixed by adjusting the 'join' function to escape any
special characters in the result.
PR c++/120974
gcc/ChangeLog:
* gcc.cc (join_spec_func): Escape special characters.
Signed-off-by: Nathaniel Shead <[email protected]>
---
gcc/gcc.cc | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 065f69c9d8b..f3e0004cdb8 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -11230,7 +11230,8 @@ find_fortran_preinclude_file (int argc, const char
**argv)
return result;
}
-/* The function takes any number of arguments and joins them together.
+/* The function takes any number of arguments and joins them together,
+ escaping any special characters.
This seems to be necessary to build "-fjoined=foo.b" from "-fseparate foo.a"
with a %{fseparate*:-fjoined=%.b$*} rule without adding undesired spaces:
@@ -11243,12 +11244,15 @@ find_fortran_preinclude_file (int argc, const char
**argv)
static const char *
join_spec_func (int argc, const char **argv)
{
- if (argc == 1)
- return argv[0];
- for (int i = 0; i < argc; ++i)
- obstack_grow (&obstack, argv[i], strlen (argv[i]));
- obstack_1grow (&obstack, '\0');
- return XOBFINISH (&obstack, const char *);
+ const char *result = argv[0];
+ if (argc != 1)
+ {
+ for (int i = 0; i < argc; ++i)
+ obstack_grow (&obstack, argv[i], strlen (argv[i]));
+ obstack_1grow (&obstack, '\0');
+ result = XOBFINISH (&obstack, const char *);
+ }
+ return quote_spec (xstrdup (result));
}
/* If any character in ORIG fits QUOTE_P (_, P), reallocate the string
--
2.51.0