[PATCH] D90234: [MCParser] Correctly handle Windows line-endings when consuming lexed line comments

Stephen Tozer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 28 09:26:15 PDT 2020


StephenTozer updated this revision to Diff 301305.
StephenTozer added a comment.
Herald added subscribers: jdoerfert, gbedwell.
Herald added a reviewer: andreadb.

I've added a test for the symptom that revealed this bug in llvm-mca. I'm also writing a unit test for AsmLexer that tests the underlying behaviour by verifying that CommentConsumers will not be sent characters that are not part of the line comment, since the problem is not specific to llvm-mca (although it's the only place that has seen an error so far, as far as I can tell).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90234/new/

https://reviews.llvm.org/D90234

Files:
  llvm/.gitattributes
  llvm/lib/MC/MCParser/AsmLexer.cpp
  llvm/test/tools/llvm-mca/directives-handle-crlf.s


Index: llvm/lib/MC/MCParser/AsmLexer.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmLexer.cpp
+++ llvm/lib/MC/MCParser/AsmLexer.cpp
@@ -214,6 +214,7 @@
   int CurChar = getNextChar();
   while (CurChar != '\n' && CurChar != '\r' && CurChar != EOF)
     CurChar = getNextChar();
+  const char *NewlinePtr = CurPtr;
   if (CurChar == '\r' && CurPtr != CurBuf.end() && *CurPtr == '\n')
     ++CurPtr;
 
@@ -221,7 +222,7 @@
   if (CommentConsumer) {
     CommentConsumer->HandleComment(
         SMLoc::getFromPointer(CommentTextStart),
-        StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
+        StringRef(CommentTextStart, NewlinePtr - 1 - CommentTextStart));
   }
 
   IsAtStartOfLine = true;
Index: llvm/.gitattributes
===================================================================
--- llvm/.gitattributes
+++ llvm/.gitattributes
@@ -13,7 +13,8 @@
 test/MC/AsmParser/incbin_abcd binary
 test/YAMLParser/spec-09-02.test binary
 
-# This file must have CRLF line endings, therefore git should treat it as
+# These files must have CRLF line endings, therefore git should treat them as
 # binary and not autoconvert line endings (for example, when core.autocrlf is
 # on).
 test/MC/AsmParser/preserve-comments-crlf.s binary
+test/tools/llvm-mca/directives-handle-crlf.s binary


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90234.301305.patch
Type: text/x-patch
Size: 1374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201028/59405089/attachment.bin>


More information about the llvm-commits mailing list