Escape # and $ in dependency files.

Fixes PR15642.

llvm-svn: 178540
This commit is contained in:
Benjamin Kramer 2013-04-02 13:38:48 +00:00
parent 5d7447f4ed
commit ae61151254
2 changed files with 22 additions and 3 deletions

View File

@ -151,12 +151,14 @@ void DependencyFileCallback::AddFilename(StringRef Filename) {
Files.push_back(Filename);
}
/// PrintFilename - GCC escapes spaces, but apparently not ' or " or other
/// scary characters.
/// PrintFilename - GCC escapes spaces, # and $, but apparently not ' or " or
/// other scary characters.
static void PrintFilename(raw_ostream &OS, StringRef Filename) {
for (unsigned i = 0, e = Filename.size(); i != e; ++i) {
if (Filename[i] == ' ')
if (Filename[i] == ' ' || Filename[i] == '#')
OS << '\\';
else if (Filename[i] == '$') // $ is escaped by $$.
OS << '$';
OS << Filename[i];
}
}

View File

@ -0,0 +1,17 @@
// REQUIRES: shell
// PR15642
// RUN: rm -rf %t.dir
// RUN: mkdir -p %t.dir
// RUN: echo > '%t.dir/ .h'
// RUN: echo > '%t.dir/$$.h'
// RUN: echo > '%t.dir/##.h'
// RUN: cd %t.dir
// RUN: %clang -MD -MF - %s -fsyntax-only -I. | FileCheck -strict-whitespace %s
// CHECK: \ \ \ \ .h
// CHECK: $$$$.h
// CHECK: \#\#.h
#include " .h"
#include "$$.h"
#include "##.h"