Author: srhines
Date: Tue Apr 19 19:33:06 2016
New Revision: 266840

URL: http://llvm.org/viewvc/llvm-project?rev=266840&view=rev
Log:
MarkEOLs should only be true for clang-cl.exe.

Summary:
https://llvm.org/bugs/show_bug.cgi?id=27396

This fixes an issue in response files where "\r\n" was being interpreted
as two EOL markers (i.e. we consumed the '\r' as terminating the
previous token, and then parsed the '\n' as a significant EOL). This
breaks response files where joined arguments get split across multiple
lines (like "-x\r\nc"). I also fixed an accidental issue in the
response-file.c test, where the response file is appended to, instead of
being overwritten.

Reviewers: rnk

Subscribers: danalbert, llvm-commits

Differential Revision: http://reviews.llvm.org/D19289

Added:
    cfe/trunk/test/Driver/response-file-extra-whitespace.c
Modified:
    cfe/trunk/test/Driver/response-file.c
    cfe/trunk/tools/driver/driver.cpp

Added: cfe/trunk/test/Driver/response-file-extra-whitespace.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/response-file-extra-whitespace.c?rev=266840&view=auto
==============================================================================
--- cfe/trunk/test/Driver/response-file-extra-whitespace.c (added)
+++ cfe/trunk/test/Driver/response-file-extra-whitespace.c Tue Apr 19 19:33:06 
2016
@@ -0,0 +1,12 @@
+// Check that clang is able to process response files with extra whitespace.
+// We generate a dos-style file with \r\n for line endings, and then split
+// some joined arguments (like "-x c") across lines to ensure that regular
+// clang (not clang-cl) can process it correctly.
+//
+// RUN: echo -en "-x\r\nc\r\n-DTEST\r\n" > %t.0.txt
+// RUN: %clang -E @%t.0.txt %s -v 2>&1 | FileCheck %s -check-prefix=SHORT
+// SHORT: extern int it_works;
+
+#ifdef TEST
+extern int it_works;
+#endif

Modified: cfe/trunk/test/Driver/response-file.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/response-file.c?rev=266840&r1=266839&r2=266840&view=diff
==============================================================================
--- cfe/trunk/test/Driver/response-file.c (original)
+++ cfe/trunk/test/Driver/response-file.c Tue Apr 19 19:33:06 2016
@@ -4,7 +4,7 @@
 // Since this is a short response file, clang must not use a response file
 // to pass its parameters to other tools. This is only necessary for a large
 // number of parameters.
-// RUN: echo "-DTEST" >> %t.0.txt
+// RUN: echo "-DTEST" > %t.0.txt
 // RUN: %clang -E @%t.0.txt %s -v 2>&1 | FileCheck %s -check-prefix=SHORT
 // SHORT-NOT: Arguments passed via response file
 // SHORT: extern int it_works;

Modified: cfe/trunk/tools/driver/driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=266840&r1=266839&r2=266840&view=diff
==============================================================================
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Tue Apr 19 19:33:06 2016
@@ -338,18 +338,26 @@ int main(int argc_, const char **argv_)
   // have to manually search for a --driver-mode=cl argument the hard way.
   // Finally, our -cc1 tools don't care which tokenization mode we use because
   // response files written by clang will tokenize the same way in either mode.
-  llvm::cl::TokenizerCallback Tokenizer = &llvm::cl::TokenizeGNUCommandLine;
+  bool ClangCLMode = false;
   if (TargetAndMode.second == "--driver-mode=cl" ||
       std::find_if(argv.begin(), argv.end(), [](const char *F) {
         return F && strcmp(F, "--driver-mode=cl") == 0;
       }) != argv.end()) {
-    Tokenizer = &llvm::cl::TokenizeWindowsCommandLine;
+    ClangCLMode = true;
   }
 
   // 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"))
+  // files end-of-lines. We only use this for the /LINK driver argument with
+  // clang-cl.exe on Windows.
+  bool MarkEOLs = false;
+
+  llvm::cl::TokenizerCallback Tokenizer = &llvm::cl::TokenizeGNUCommandLine;
+  if (ClangCLMode) {
+    Tokenizer = &llvm::cl::TokenizeWindowsCommandLine;
+    MarkEOLs = true;
+  }
+
+  if (MarkEOLs && argv.size() > 1 && StringRef(argv[1]).startswith("-cc1"))
     MarkEOLs = false;
   llvm::cl::ExpandResponseFiles(Saver, Tokenizer, argv, MarkEOLs);
 


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to