r370129 - Re-land [clang-scan-deps] Minimizer: Correctly handle multi-line content with CR+LF line endings
Alexandre Ganea via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 27 17:04:06 PDT 2019
Author: aganea
Date: Tue Aug 27 17:04:06 2019
New Revision: 370129
URL: http://llvm.org/viewvc/llvm-project?rev=370129&view=rev
Log:
Re-land [clang-scan-deps] Minimizer: Correctly handle multi-line content with CR+LF line endings
Previously, an #error directive with quoted, multi-line content, along with CR+LF line endings wasn't handled correctly.
Differential Revision: https://reviews.llvm.org/D66556
Added:
cfe/trunk/.gitattributes
cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c (contents, props changed)
- copied, changed from r369999, cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c
Modified:
cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
Added: cfe/trunk/.gitattributes
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/.gitattributes?rev=370129&view=auto
==============================================================================
--- cfe/trunk/.gitattributes (added)
+++ cfe/trunk/.gitattributes Tue Aug 27 17:04:06 2019
@@ -0,0 +1,4 @@
+# Windows line ending tests
+test/Lexer/minimize_source_to_dependency_directives_invalid_error.c text eol=crlf
+test/FixIt/fixit-newline-style.c text eol=crlf
+test/Frontend/system-header-line-directive-ms-lineendings.c text eol=crlf
Modified: cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp?rev=370129&r1=370128&r2=370129&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp (original)
+++ cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp Tue Aug 27 17:04:06 2019
@@ -196,15 +196,29 @@ static void skipString(const char *&Firs
++First; // Finish off the string.
}
-static void skipNewline(const char *&First, const char *End) {
- assert(isVerticalWhitespace(*First));
- ++First;
+// 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;
+ 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;
+ assert(isVerticalWhitespace(*First));
+ unsigned Len = isEOL(First, End);
+ assert(Len && "expected newline");
+ First += Len;
+ return Len;
+}
- // Check for "\n\r" and "\r\n".
- if (LLVM_UNLIKELY(isVerticalWhitespace(*First) && First[-1] != First[0]))
- ++First;
+static bool wasLineContinuation(const char *First, unsigned EOLLen) {
+ return *(First - (int)EOLLen - 1) == '\\';
}
static void skipToNewlineRaw(const char *&First, const char *const End) {
@@ -212,17 +226,21 @@ static void skipToNewlineRaw(const char
if (First == End)
return;
- if (isVerticalWhitespace(*First))
+ unsigned Len = isEOL(First, End);
+ if (Len)
return;
- while (!isVerticalWhitespace(*First))
+ do {
if (++First == End)
return;
+ Len = isEOL(First, End);
+ } while (!Len);
if (First[-1] != '\\')
return;
- ++First; // Keep going...
+ First += Len;
+ // Keep skipping lines...
}
}
@@ -277,7 +295,7 @@ static bool isQuoteCppDigitSeparator(con
}
static void skipLine(const char *&First, const char *const End) {
- do {
+ for (;;) {
assert(First <= End);
if (First == End)
return;
@@ -322,9 +340,10 @@ static void skipLine(const char *&First,
return;
// Skip over the newline.
- assert(isVerticalWhitespace(*First));
- skipNewline(First, End);
- } while (First[-2] == '\\'); // Continue past line-continuations.
+ unsigned Len = skipNewline(First, End);
+ if (!wasLineContinuation(First, Len)) // Continue past line-continuations.
+ break;
+ }
}
static void skipDirective(StringRef Name, const char *&First,
@@ -380,6 +399,8 @@ void Minimizer::printToNewline(const cha
// Print out the string.
if (Last == End || Last == First || Last[-1] != '\\') {
append(First, reverseOverSpaces(First, Last));
+ First = Last;
+ skipNewline(First, End);
return;
}
Copied: cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c (from r369999, cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c?p2=cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c&p1=cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c&r1=369999&r2=370129&rev=370129&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c (original)
+++ cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c Tue Aug 27 17:04:06 2019
@@ -1,5 +1,5 @@
// 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
+// RUN: %clang_cc1 -DOTHER -print-dependency-directives-minimized-source %s 2>&1 | FileCheck %s
#ifndef TEST
#error "message \
Propchange: cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c
------------------------------------------------------------------------------
svn:eol-style = CRLF
More information about the cfe-commits
mailing list