[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
Tue Aug 17 07:54:01 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5c6f748cbc17: [MCParser] Correctly handle CRLF line ends when consuming line comments (authored by StephenTozer).

Changed prior to commit:
  https://reviews.llvm.org/D90234?vs=366882&id=366898#toc

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/test/tools/llvm-mca/directives-handle-crlf.s
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-mca/directives-handle-crlf.s
@@ -0,0 +1,4 @@
+# RUN: llvm-mca -mtriple=x86_64-unknown-unknown %s
+# LLVM-MCA-BEGIN foo
+addl	$42, %eax
+# LLVM-MCA-END
Index: llvm/lib/MC/MCParser/AsmLexer.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmLexer.cpp
+++ llvm/lib/MC/MCParser/AsmLexer.cpp
@@ -228,6 +228,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;
 
@@ -235,7 +236,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.366898.patch
Type: text/x-patch
Size: 1669 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210817/194e4597/attachment.bin>


More information about the llvm-commits mailing list