llvm.org GIT mirror llvm / 4cc74fc
Canonicalize line endings to Linux style also when the --strict-whitespace flag is in use. This flag is supposed to affect horizontal whitespaces only. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174541 91177308-0d34-0410-b5e6-96231b3b80d8 Guy Benyei 6 years ago
3 changed file(s) with 27 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
4242
4343 By default, FileCheck canonicalizes input horizontal whitespace (spaces and
4444 tabs) which causes it to ignore these differences (a space will match a tab).
45 The :option:`--strict-whitespace` argument disables this behavior.
45 The :option:`--strict-whitespace` argument disables this behavior. End-of-line
46 sequences are canonicalized to UNIX-style '\n' in all modes.
4647
4748 .. option:: -version
4849
0 // Test for using FileCheck on DOS style end-of-line
1 // This test was deliberately committed with DOS style end of line.
2 // Don't change line endings!
3 // RUN: FileCheck -input-file %s %s
4 // RUN: FileCheck --strict-whitespace -input-file %s %s
5
6 LINE 1
7 ; CHECK: {{^}}LINE 1{{$}}
8
9 LINE 2
10 ; CHECK: {{^}}LINE 2{{$}}
586586 : Pat(P), Loc(L), IsCheckNext(isCheckNext) {}
587587 };
588588
589 /// CanonicalizeInputFile - Remove duplicate horizontal space from the specified
590 /// memory buffer, free it, and return a new one.
591 static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB) {
589 /// Canonicalize whitespaces in the input file. Line endings are replaced
590 /// with UNIX-style '\n'.
591 ///
592 /// \param PreserveHorizontal Don't squash consecutive horizontal whitespace
593 /// characters to a single space.
594 static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB,
595 bool PreserveHorizontal) {
592596 SmallString<128> NewFile;
593597 NewFile.reserve(MB->getBufferSize());
594598
599603 continue;
600604 }
601605
602 // If current char is not a horizontal whitespace, dump it to output as is.
603 if (*Ptr != ' ' && *Ptr != '\t') {
606 // If current char is not a horizontal whitespace or if horizontal
607 // whitespace canonicalization is disabled, dump it to output as is.
608 if (PreserveHorizontal || (*Ptr != ' ' && *Ptr != '\t')) {
604609 NewFile.push_back(*Ptr);
605610 continue;
606611 }
636641 MemoryBuffer *F = File.take();
637642
638643 // If we want to canonicalize whitespace, strip excess whitespace from the
639 // buffer containing the CHECK lines.
640 if (!NoCanonicalizeWhiteSpace)
641 F = CanonicalizeInputFile(F);
644 // buffer containing the CHECK lines. Remove DOS style line endings.
645 F = CanonicalizeInputFile(F, NoCanonicalizeWhiteSpace);
642646
643647 SM.AddNewSourceBuffer(F, SMLoc());
644648
806810 }
807811
808812 // Remove duplicate spaces in the input file if requested.
809 if (!NoCanonicalizeWhiteSpace)
810 F = CanonicalizeInputFile(F);
813 // Remove DOS style line endings.
814 F = CanonicalizeInputFile(F, NoCanonicalizeWhiteSpace);
811815
812816 SM.AddNewSourceBuffer(F, SMLoc());
813817