]> granicus.if.org Git - clang/commitdiff
Driver: Fix -### to quote shell special characters, following gcc.
authorDaniel Dunbar <daniel@zuster.org>
Sat, 20 Mar 2010 08:01:53 +0000 (08:01 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 20 Mar 2010 08:01:53 +0000 (08:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99053 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Compilation.cpp

index b819cda89c09bcd62227764a760063e85b32da51..98c637442589e95201b72c3f39029f138eeb84fd 100644 (file)
@@ -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)) {