diff options
author | Reid Kleckner <reid@kleckner.net> | 2014-08-22 19:29:30 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2014-08-22 19:29:30 +0000 |
commit | af5fd6a4d5db63a2b064ffa0e82e541c1cff2e7c (patch) | |
tree | e6b69b5281da7b55345409e7a49712201c2a008d /clang/tools | |
parent | e3f146d941f11c97e2561778d640e6dab721463c (diff) | |
download | bcm5719-llvm-af5fd6a4d5db63a2b064ffa0e82e541c1cff2e7c.tar.gz bcm5719-llvm-af5fd6a4d5db63a2b064ffa0e82e541c1cff2e7c.zip |
Fix PR17239 by changing the semantics of the RemainingArgsClass Option kind
This patch aims at fixing PR17239.
This bug happens because the /link (clang-cl.exe argument) is marked as
"consume all remaining arguments". However, when inside a response file,
/link should only consume all remaining arguments inside the response
file where it is located, not the entire command line after expansion.
The LLVM side of the patch will change the semantics of the
RemainingArgsClass kind to always consume only until the end of the
response file when the option originally came from a response file.
There are only two options in this class: dash dash (--) and /link.
This is the Clang side of the patch in http://reviews.llvm.org/D4899
Reviewered By: rafael, rnk
Differential Revision: http://reviews.llvm.org/D4900
Patch by Rafael Auler!
llvm-svn: 216281
Diffstat (limited to 'clang/tools')
-rw-r--r-- | clang/tools/driver/driver.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp index 2533401082a..524ead29a7f 100644 --- a/clang/tools/driver/driver.cpp +++ b/clang/tools/driver/driver.cpp @@ -116,6 +116,9 @@ static void ApplyOneQAOverride(raw_ostream &OS, ReplPattern = ReplPattern.slice(0, ReplPattern.size()-1); for (unsigned i = 1, e = Args.size(); i != e; ++i) { + // Ignore end-of-line response file markers + if (Args[i] == nullptr) + continue; std::string Repl = llvm::Regex(MatchPattern).sub(ReplPattern, Args[i]); if (Repl != Args[i]) { @@ -142,6 +145,9 @@ static void ApplyOneQAOverride(raw_ostream &OS, } else if (Edit[0] == 'O') { for (unsigned i = 1; i < Args.size();) { const char *A = Args[i]; + // Ignore end-of-line response file markers + if (A == nullptr) + continue; if (A[0] == '-' && A[1] == 'O' && (A[2] == '\0' || (A[3] == '\0' && (A[2] == 's' || A[2] == 'z' || @@ -384,14 +390,33 @@ int main(int argc_, const char **argv_) { std::set<std::string> SavedStrings; StringSetSaver Saver(SavedStrings); - llvm::cl::ExpandResponseFiles(Saver, llvm::cl::TokenizeGNUCommandLine, argv); - // Handle -cc1 integrated tools. + // Determines whether we want nullptr markers in argv to indicate response + // files end-of-lines. We only use this for the /LINK driver argument. + bool MarkEOLs = true; if (argv.size() > 1 && StringRef(argv[1]).startswith("-cc1")) + MarkEOLs = false; + llvm::cl::ExpandResponseFiles(Saver, llvm::cl::TokenizeGNUCommandLine, argv, + MarkEOLs); + + // Handle -cc1 integrated tools, even if -cc1 was expanded from a response + // file. + auto FirstArg = std::find_if(argv.begin() + 1, argv.end(), + [](const char *A) { return A != nullptr; }); + if (FirstArg != argv.end() && StringRef(*FirstArg).startswith("-cc1")) { + // If -cc1 came from a response file, remove the EOL sentinels. + if (MarkEOLs) { + auto newEnd = std::remove(argv.begin(), argv.end(), nullptr); + argv.resize(newEnd - argv.begin()); + } return ExecuteCC1Tool(argv, argv[1] + 4); + } bool CanonicalPrefixes = true; for (int i = 1, size = argv.size(); i < size; ++i) { + // Skip end-of-line response file markers + if (argv[i] == nullptr) + continue; if (StringRef(argv[i]) == "-no-canonical-prefixes") { CanonicalPrefixes = false; break; |