diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-03-20 08:01:53 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-03-20 08:01:53 +0000 |
commit | b86c5fc7393f61221686fc56e992ca409dee2a50 (patch) | |
tree | 27c4e4df560e3107d282e0d86e782c812f15e64d | |
parent | db59bc867af39cf09053fa49f3c20bd7a6319f3f (diff) |
Driver: Fix -### to quote shell special characters, following gcc.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99053 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Driver/Compilation.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index b819cda89c..98c6374425 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -61,10 +61,21 @@ void Compilation::PrintJob(llvm::raw_ostream &OS, const Job &J, OS << " \"" << C->getExecutable() << '"'; for (ArgStringList::const_iterator it = C->getArguments().begin(), ie = C->getArguments().end(); it != ie; ++it) { - if (Quote) - OS << " \"" << *it << '"'; - else - OS << ' ' << *it; + OS << ' '; + if (!Quote) { + OS << *it; + continue; + } + + // Quote the argument and escape shell special characters; this isn't + // really complete but is good enough. + OS << '"'; + for (const char *s = *it; *s; ++s) { + if (*s == '"' || *s == '\\' || *s == '$') + OS << '\\'; + OS << *s; + } + OS << '"'; } OS << Terminator; } else if (const PipedJob *PJ = dyn_cast<PipedJob>(&J)) { |