<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="FR-CA" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-CA" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">I’ve changed to using svn:eol-style instead. Could you please let me know if that sounds better? See:
</span><a href="https://reviews.llvm.org/D66556">https://reviews.llvm.org/D66556</a><span lang="EN-CA" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span lang="FR" style="font-size:11.0pt;font-family:"Calibri",sans-serif">De :</span></b><span lang="FR" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Richard Smith <richard@metafoo.co.uk>
<br>
<b>Envoyé :</b> August 26, 2019 9:03 PM<br>
<b>À :</b> Alexandre Ganea <alexandre.ganea@ubisoft.com><br>
<b>Cc :</b> cfe-commits <cfe-commits@lists.llvm.org><br>
<b>Objet :</b> Re: r369986 - [clang-scan-deps] Minimizer: Correctly handle multi-line content with CR+LF line endings<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Mon, 26 Aug 2019 at 16:17, Alexandre Ganea via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal">Author: aganea<br>
Date: Mon Aug 26 16:19:21 2019<br>
New Revision: 369986<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=369986&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=369986&view=rev</a><br>
Log:<br>
[clang-scan-deps] Minimizer: Correctly handle multi-line content with CR+LF line endings<br>
<br>
Previously, an #error directive with quoted, multi-line content, along with CR+LF line endings wasn't handled correctly.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D66556" target="_blank">
https://reviews.llvm.org/D66556</a><br>
<br>
Added:<br>
    cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c<br>
Modified:<br>
    cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp<br>
<br>
Modified: cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp?rev=369986&r1=369985&r2=369986&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp?rev=369986&r1=369985&r2=369986&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp (original)<br>
+++ cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp Mon Aug 26 16:19:21 2019<br>
@@ -196,15 +196,29 @@ static void skipString(const char *&Firs<br>
     ++First; // Finish off the string.<br>
 }<br>
<br>
-static void skipNewline(const char *&First, const char *End) {<br>
-  assert(isVerticalWhitespace(*First));<br>
-  ++First;<br>
+// Returns the length of EOL, either 0 (no end-of-line), 1 (\n) or 2 (\r\n)<br>
+static unsigned isEOL(const char *First, const char *const End) {<br>
   if (First == End)<br>
-    return;<br>
+    return 0;<br>
+  if (End - First > 1 && isVerticalWhitespace(First[0]) &&<br>
+      isVerticalWhitespace(First[1]) && First[0] != First[1])<br>
+    return 2;<br>
+  return !!isVerticalWhitespace(First[0]);<br>
+}<br>
+<br>
+// Returns the length of the skipped newline<br>
+static unsigned skipNewline(const char *&First, const char *End) {<br>
+  if (First == End)<br>
+    return 0;<br>
+  assert(isVerticalWhitespace(*First));<br>
+  unsigned Len = isEOL(First, End);<br>
+  assert(Len && "expected newline");<br>
+  First += Len;<br>
+  return Len;<br>
+}<br>
<br>
-  // Check for "\n\r" and "\r\n".<br>
-  if (LLVM_UNLIKELY(isVerticalWhitespace(*First) && First[-1] != First[0]))<br>
-    ++First;<br>
+static bool wasLineContinuation(const char *First, unsigned EOLLen) {<br>
+  return *(First - (int)EOLLen - 1) == '\\';<br>
 }<br>
<br>
 static void skipToNewlineRaw(const char *&First, const char *const End) {<br>
@@ -212,17 +226,21 @@ static void skipToNewlineRaw(const char<br>
     if (First == End)<br>
       return;<br>
<br>
-    if (isVerticalWhitespace(*First))<br>
+    unsigned Len = isEOL(First, End);<br>
+    if (Len)<br>
       return;<br>
<br>
-    while (!isVerticalWhitespace(*First))<br>
+    do {<br>
       if (++First == End)<br>
         return;<br>
+      Len = isEOL(First, End);<br>
+    } while (!Len);<br>
<br>
     if (First[-1] != '\\')<br>
       return;<br>
<br>
-    ++First; // Keep going...<br>
+    First += Len;<br>
+    // Keep skipping lines...<br>
   }<br>
 }<br>
<br>
@@ -277,7 +295,7 @@ static bool isQuoteCppDigitSeparator(con<br>
 }<br>
<br>
 static void skipLine(const char *&First, const char *const End) {<br>
-  do {<br>
+  for (;;) {<br>
     assert(First <= End);<br>
     if (First == End)<br>
       return;<br>
@@ -322,9 +340,10 @@ static void skipLine(const char *&First,<br>
       return;<br>
<br>
     // Skip over the newline.<br>
-    assert(isVerticalWhitespace(*First));<br>
-    skipNewline(First, End);<br>
-  } while (First[-2] == '\\'); // Continue past line-continuations.<br>
+    unsigned Len = skipNewline(First, End);<br>
+    if (!wasLineContinuation(First, Len)) // Continue past line-continuations.<br>
+      break;<br>
+  }<br>
 }<br>
<br>
 static void skipDirective(StringRef Name, const char *&First,<br>
@@ -379,6 +398,8 @@ void Minimizer::printToNewline(const cha<br>
     // Print out the string.<br>
     if (Last == End || Last == First || Last[-1] != '\\') {<br>
       append(First, reverseOverSpaces(First, Last));<br>
+      First = Last;<br>
+      skipNewline(First, End);<br>
       return;<br>
     }<br>
<br>
<br>
Added: cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c?rev=369986&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c?rev=369986&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c (added)<br>
+++ cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_invalid_error.c Mon Aug 26 16:19:21 2019<br>
@@ -0,0 +1,16 @@<br>
+// Test CF+LF are properly handled along with quoted, multi-line #error<br>
+// RUN: cat %s | unix2dos | %clang_cc1 -DOTHER -print-dependency-directives-minimized-source 2>&1 | FileCheck %s<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">You can't rely on 'unix2dos' existing across all our supported build environments; this is causing a test failure for me.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I'm reverting for now. Maybe you could just check in a file with CRLF line endings for this test (marked as binary rather than text so that clients don't "fix" it)?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal">+<br>
+#ifndef TEST<br>
+#error "message \<br>
+   more message \<br>
+   even more"<br>
+#endif<br>
+<br>
+#ifdef OTHER<br>
+#include <string><br>
+#endif<br>
+<br>
+// CHECK:      #ifdef OTHER<br>
+// CHECK-NEXT: #include <string><br>
+// CHECK-NEXT: #endif<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</body>
</html>