From: Richard Smith Date: Tue, 27 Aug 2019 01:06:23 +0000 (+0000) Subject: Revert "[clang-scan-deps] Minimizer: Correctly handle multi-line content with CR... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=82826b06c65faa794af55367e9d51a46e8284c11;p=clang Revert "[clang-scan-deps] Minimizer: Correctly handle multi-line content with CR+LF line endings" This reverts commit r369986. This change added a dependency on the 'dos2unix' tool, which is not one of our accepted test dependencies and may not exist on all machines that build Clang. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370000 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/DependencyDirectivesSourceMinimizer.cpp b/lib/Lex/DependencyDirectivesSourceMinimizer.cpp index a350481df9..11dca07361 100644 --- a/lib/Lex/DependencyDirectivesSourceMinimizer.cpp +++ b/lib/Lex/DependencyDirectivesSourceMinimizer.cpp @@ -196,29 +196,15 @@ static void skipString(const char *&First, const char *const End) { ++First; // Finish off the string. } -// Returns the length of EOL, either 0 (no end-of-line), 1 (\n) or 2 (\r\n) -static unsigned isEOL(const char *First, const char *const End) { - if (First == End) - return 0; - if (End - First > 1 && isVerticalWhitespace(First[0]) && - isVerticalWhitespace(First[1]) && First[0] != First[1]) - return 2; - return !!isVerticalWhitespace(First[0]); -} - -// Returns the length of the skipped newline -static unsigned skipNewline(const char *&First, const char *End) { - if (First == End) - return 0; +static void skipNewline(const char *&First, const char *End) { assert(isVerticalWhitespace(*First)); - unsigned Len = isEOL(First, End); - assert(Len && "expected newline"); - First += Len; - return Len; -} + ++First; + if (First == End) + return; -static bool wasLineContinuation(const char *First, unsigned EOLLen) { - return *(First - (int)EOLLen - 1) == '\\'; + // Check for "\n\r" and "\r\n". + if (LLVM_UNLIKELY(isVerticalWhitespace(*First) && First[-1] != First[0])) + ++First; } static void skipToNewlineRaw(const char *&First, const char *const End) { @@ -226,21 +212,17 @@ static void skipToNewlineRaw(const char *&First, const char *const End) { if (First == End) return; - unsigned Len = isEOL(First, End); - if (Len) + if (isVerticalWhitespace(*First)) return; - do { + while (!isVerticalWhitespace(*First)) if (++First == End) return; - Len = isEOL(First, End); - } while (!Len); if (First[-1] != '\\') return; - First += Len; - // Keep skipping lines... + ++First; // Keep going... } } @@ -295,7 +277,7 @@ static bool isQuoteCppDigitSeparator(const char *const Start, } static void skipLine(const char *&First, const char *const End) { - for (;;) { + do { assert(First <= End); if (First == End) return; @@ -340,10 +322,9 @@ static void skipLine(const char *&First, const char *const End) { return; // Skip over the newline. - unsigned Len = skipNewline(First, End); - if (!wasLineContinuation(First, Len)) // Continue past line-continuations. - break; - } + assert(isVerticalWhitespace(*First)); + skipNewline(First, End); + } while (First[-2] == '\\'); // Continue past line-continuations. } static void skipDirective(StringRef Name, const char *&First, @@ -399,8 +380,6 @@ void Minimizer::printToNewline(const char *&First, const char *const End) { // Print out the string. if (Last == End || Last == First || Last[-1] != '\\') { append(First, reverseOverSpaces(First, Last)); - First = Last; - skipNewline(First, End); return; } diff --git a/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c b/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c deleted file mode 100644 index 91005e566f..0000000000 --- a/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c +++ /dev/null @@ -1,16 +0,0 @@ -// Test CF+LF are properly handled along with quoted, multi-line #error -// RUN: cat %s | unix2dos | %clang_cc1 -DOTHER -print-dependency-directives-minimized-source 2>&1 | FileCheck %s - -#ifndef TEST -#error "message \ - more message \ - even more" -#endif - -#ifdef OTHER -#include -#endif - -// CHECK: #ifdef OTHER -// CHECK-NEXT: #include -// CHECK-NEXT: #endif