summaryrefslogtreecommitdiffstats
path: root/llvm/utils/FileCheck/FileCheck.cpp
diff options
context:
space:
mode:
authorGuy Benyei <guy.benyei@intel.com>2013-02-06 20:40:38 +0000
committerGuy Benyei <guy.benyei@intel.com>2013-02-06 20:40:38 +0000
commit5ea04c385fc5b6aeb6404ec9a992ea8e2d149f1e (patch)
treeed51416042babd97ff8230458c51ee6578f3a029 /llvm/utils/FileCheck/FileCheck.cpp
parent4feac28e0e4bbbcd7d503171b3867cb33fc4cca7 (diff)
downloadbcm5719-llvm-5ea04c385fc5b6aeb6404ec9a992ea8e2d149f1e.tar.gz
bcm5719-llvm-5ea04c385fc5b6aeb6404ec9a992ea8e2d149f1e.zip
Canonicalize line endings to Linux style also when the --strict-whitespace flag is in use. This flag is supposed to affect horizontal whitespaces only.
llvm-svn: 174541
Diffstat (limited to 'llvm/utils/FileCheck/FileCheck.cpp')
-rw-r--r--llvm/utils/FileCheck/FileCheck.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp
index a0eeb0edff2..74442ec1448 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -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());
OpenPOWER on IntegriCloud