Canonicalize line endings to Linux style also when the --strict-whitespace flag is...
authorGuy Benyei <guy.benyei@intel.com>
Wed, 6 Feb 2013 20:40:38 +0000 (20:40 +0000)
committerGuy Benyei <guy.benyei@intel.com>
Wed, 6 Feb 2013 20:40:38 +0000 (20:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174541 91177308-0d34-0410-b5e6-96231b3b80d8

docs/CommandGuide/FileCheck.rst
test/FileCheck/dos-style-eol.txt [new file with mode: 0644]
utils/FileCheck/FileCheck.cpp

index 256970b36240634eafb3b6eadfadaa4b6d6cf300..fce63ba688cc3bc82e29e7165ddfcce4e65c7366 100644 (file)
@@ -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
 
diff --git a/test/FileCheck/dos-style-eol.txt b/test/FileCheck/dos-style-eol.txt
new file mode 100644 (file)
index 0000000..4252aad
--- /dev/null
@@ -0,0 +1,11 @@
+// Test for using FileCheck on DOS style end-of-line\r
+// This test was deliberately committed with DOS style end of line.\r
+// Don't change line endings!\r
+// RUN: FileCheck -input-file %s %s\r
+// RUN: FileCheck  --strict-whitespace -input-file %s %s\r
+\r
+LINE 1\r
+; CHECK: {{^}}LINE 1{{$}}\r
+\r
+LINE 2\r
+; CHECK: {{^}}LINE 2{{$}}
\ No newline at end of file
index a0eeb0edff286914b5aa9a9bb58e9962672b0847..74442ec14487025bc272a01da709db404e998b38 100644 (file)
@@ -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 *CanonicalizeInputFile(MemoryBuffer *MB) {
       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());