diff options
author | Martin Storsjo <martin@martin.st> | 2018-09-14 06:08:01 +0000 |
---|---|---|
committer | Martin Storsjo <martin@martin.st> | 2018-09-14 06:08:01 +0000 |
commit | f08a9c700bcf1f7096a471ba521b030318582e4b (patch) | |
tree | 5b2b6a9b6a24d75128b8dcfbeb0d72210545ec87 /llvm/lib/Support/CommandLine.cpp | |
parent | e385365c40fc6aa57341e804f7722ca41ca4df2b (diff) | |
download | llvm-f08a9c700bcf1f7096a471ba521b030318582e4b.zip llvm-f08a9c700bcf1f7096a471ba521b030318582e4b.tar.gz llvm-f08a9c700bcf1f7096a471ba521b030318582e4b.tar.bz2 |
[Support] Treat null bytes as separator in windows command line strings
When reading directives from a .drectve section, the directives are
tokenized as a normal windows command line. However in these cases,
link.exe allows the directives to be separated by null bytes, not only by
spaces.
A test case for this change will be added in the lld repo.
Differential Revision: https://reviews.llvm.org/D52014
llvm-svn: 342204
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index a1e659a..b169bb6 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -693,6 +693,10 @@ static bool isWhitespace(char C) { return C == ' ' || C == '\t' || C == '\r' || C == '\n'; } +static bool isWhitespaceOrNull(char C) { + return isWhitespace(C) || C == '\0'; +} + static bool isQuote(char C) { return C == '\"' || C == '\''; } void cl::TokenizeGNUCommandLine(StringRef Src, StringSaver &Saver, @@ -808,7 +812,7 @@ void cl::TokenizeWindowsCommandLine(StringRef Src, StringSaver &Saver, // INIT state indicates that the current input index is at the start of // the string or between tokens. if (State == INIT) { - if (isWhitespace(C)) { + if (isWhitespaceOrNull(C)) { // Mark the end of lines in response files if (MarkEOLs && C == '\n') NewArgv.push_back(nullptr); @@ -832,7 +836,7 @@ void cl::TokenizeWindowsCommandLine(StringRef Src, StringSaver &Saver, // quotes. if (State == UNQUOTED) { // Whitespace means the end of the token. - if (isWhitespace(C)) { + if (isWhitespaceOrNull(C)) { NewArgv.push_back(Saver.save(StringRef(Token)).data()); Token.clear(); State = INIT; |