[llvm] r174541 - Canonicalize line endings to Linux style also when the --strict-whitespace flag is in use. This flag is supposed to affect horizontal whitespaces only.

Guy Benyei guy.benyei at intel.com
Wed Feb 6 12:40:38 PST 2013


Author: gbenyei
Date: Wed Feb  6 14:40:38 2013
New Revision: 174541

URL: http://llvm.org/viewvc/llvm-project?rev=174541&view=rev
Log:
Canonicalize line endings to Linux style also when the --strict-whitespace flag is in use. This flag is supposed to affect horizontal whitespaces only.

Added:
    llvm/trunk/test/FileCheck/dos-style-eol.txt
Modified:
    llvm/trunk/docs/CommandGuide/FileCheck.rst
    llvm/trunk/utils/FileCheck/FileCheck.cpp

Modified: llvm/trunk/docs/CommandGuide/FileCheck.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/FileCheck.rst?rev=174541&r1=174540&r2=174541&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/FileCheck.rst (original)
+++ llvm/trunk/docs/CommandGuide/FileCheck.rst Wed Feb  6 14:40:38 2013
@@ -43,7 +43,8 @@ OPTIONS
 
  By default, FileCheck canonicalizes input horizontal whitespace (spaces and
  tabs) which causes it to ignore these differences (a space will match a tab).
- The :option:`--strict-whitespace` argument disables this behavior.
+ The :option:`--strict-whitespace` argument disables this behavior. End-of-line
+ sequences are canonicalized to UNIX-style '\n' in all modes.
 
 .. option:: -version
 

Added: llvm/trunk/test/FileCheck/dos-style-eol.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FileCheck/dos-style-eol.txt?rev=174541&view=auto
==============================================================================
--- llvm/trunk/test/FileCheck/dos-style-eol.txt (added)
+++ llvm/trunk/test/FileCheck/dos-style-eol.txt Wed Feb  6 14:40:38 2013
@@ -0,0 +1,11 @@
+// Test for using FileCheck on DOS style end-of-line
+// This test was deliberately committed with DOS style end of line.
+// Don't change line endings!
+// RUN: FileCheck -input-file %s %s
+// RUN: FileCheck  --strict-whitespace -input-file %s %s
+
+LINE 1
+; CHECK: {{^}}LINE 1{{$}}
+
+LINE 2
+; CHECK: {{^}}LINE 2{{$}}
\ No newline at end of file

Modified: llvm/trunk/utils/FileCheck/FileCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileCheck/FileCheck.cpp?rev=174541&r1=174540&r2=174541&view=diff
==============================================================================
--- llvm/trunk/utils/FileCheck/FileCheck.cpp (original)
+++ llvm/trunk/utils/FileCheck/FileCheck.cpp Wed Feb  6 14:40:38 2013
@@ -587,9 +587,13 @@ struct CheckString {
     : Pat(P), Loc(L), IsCheckNext(isCheckNext) {}
 };
 
-/// CanonicalizeInputFile - Remove duplicate horizontal space from the specified
-/// memory buffer, free it, and return a new one.
-static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB) {
+/// Canonicalize whitespaces in the input file. Line endings are replaced
+/// with UNIX-style '\n'.
+///
+/// \param PreserveHorizontal Don't squash consecutive horizontal whitespace
+/// characters to a single space.
+static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB,
+                                           bool PreserveHorizontal) {
   SmallString<128> NewFile;
   NewFile.reserve(MB->getBufferSize());
 
@@ -600,8 +604,9 @@ static MemoryBuffer *CanonicalizeInputFi
       continue;
     }
 
-    // If current char is not a horizontal whitespace, dump it to output as is.
-    if (*Ptr != ' ' && *Ptr != '\t') {
+    // If current char is not a horizontal whitespace or if horizontal 
+    // whitespace canonicalization is disabled, dump it to output as is.
+    if (PreserveHorizontal || (*Ptr != ' ' && *Ptr != '\t')) {
       NewFile.push_back(*Ptr);
       continue;
     }
@@ -637,9 +642,8 @@ static bool ReadCheckFile(SourceMgr &SM,
   MemoryBuffer *F = File.take();
 
   // If we want to canonicalize whitespace, strip excess whitespace from the
-  // buffer containing the CHECK lines.
-  if (!NoCanonicalizeWhiteSpace)
-    F = CanonicalizeInputFile(F);
+  // buffer containing the CHECK lines. Remove DOS style line endings.
+  F = CanonicalizeInputFile(F, NoCanonicalizeWhiteSpace);
 
   SM.AddNewSourceBuffer(F, SMLoc());
 
@@ -807,8 +811,8 @@ int main(int argc, char **argv) {
   }
   
   // Remove duplicate spaces in the input file if requested.
-  if (!NoCanonicalizeWhiteSpace)
-    F = CanonicalizeInputFile(F);
+  // Remove DOS style line endings.
+  F = CanonicalizeInputFile(F, NoCanonicalizeWhiteSpace);
 
   SM.AddNewSourceBuffer(F, SMLoc());
 





More information about the llvm-commits mailing list