summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Support/CommandLine.cpp11
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp11
2 files changed, 10 insertions, 12 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 73792ef729c..5513ba604dc 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -515,8 +515,6 @@ static bool isWhitespace(char C) { return strchr(" \t\n\r\f\v", C); }
static bool isQuote(char C) { return C == '\"' || C == '\''; }
-static bool isGNUSpecial(char C) { return strchr("\\\"\' ", C); }
-
void cl::TokenizeGNUCommandLine(StringRef Src, StringSaver &Saver,
SmallVectorImpl<const char *> &NewArgv,
bool MarkEOLs) {
@@ -534,9 +532,8 @@ void cl::TokenizeGNUCommandLine(StringRef Src, StringSaver &Saver,
break;
}
- // Backslashes can escape backslashes, spaces, and other quotes. Otherwise
- // they are literal. This makes it much easier to read Windows file paths.
- if (I + 1 < E && Src[I] == '\\' && isGNUSpecial(Src[I + 1])) {
+ // Backslash escapes the next character.
+ if (I + 1 < E && Src[I] == '\\') {
++I; // Skip the escape.
Token.push_back(Src[I]);
continue;
@@ -546,8 +543,8 @@ void cl::TokenizeGNUCommandLine(StringRef Src, StringSaver &Saver,
if (isQuote(Src[I])) {
char Quote = Src[I++];
while (I != E && Src[I] != Quote) {
- // Backslashes are literal, unless they escape a special character.
- if (Src[I] == '\\' && I + 1 != E && isGNUSpecial(Src[I + 1]))
+ // Backslash escapes the next character.
+ if (Src[I] == '\\' && I + 1 != E)
++I;
Token.push_back(Src[I]);
++I;
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index eac669f467b..760df3c0182 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -165,11 +165,12 @@ void testCommandLineTokenizer(ParserFunction *parse, const char *Input,
}
TEST(CommandLineTest, TokenizeGNUCommandLine) {
- const char *Input = "foo\\ bar \"foo bar\" \'foo bar\' 'foo\\\\bar' "
- "foo\"bar\"baz C:\\src\\foo.cpp \"C:\\src\\foo.cpp\"";
- const char *const Output[] = { "foo bar", "foo bar", "foo bar", "foo\\bar",
- "foobarbaz", "C:\\src\\foo.cpp",
- "C:\\src\\foo.cpp" };
+ const char *Input =
+ "foo\\ bar \"foo bar\" \'foo bar\' 'foo\\\\bar' -DFOO=bar\\(\\) "
+ "foo\"bar\"baz C:\\\\src\\\\foo.cpp \"C:\\src\\foo.cpp\"";
+ const char *const Output[] = {
+ "foo bar", "foo bar", "foo bar", "foo\\bar",
+ "-DFOO=bar()", "foobarbaz", "C:\\src\\foo.cpp", "C:srcfoo.cpp"};
testCommandLineTokenizer(cl::TokenizeGNUCommandLine, Input, Output,
array_lengthof(Output));
}
OpenPOWER on IntegriCloud