[llvm-bugs] [Bug 47983] New: Windows newlines cause error in parsing llvm-mca regions

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 26 11:37:08 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47983

            Bug ID: 47983
           Summary: Windows newlines cause error in parsing llvm-mca
                    regions
           Product: tools
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: llvm-mca
          Assignee: unassignedbugs at nondot.org
          Reporter: stephen.tozer at sony.com
                CC: andrea.dibiagio at gmail.com, llvm-bugs at lists.llvm.org,
                    matthew.davis at sony.com

Created attachment 24102
  --> https://bugs.llvm.org/attachment.cgi?id=24102&action=edit
C++ source code that reproduces issue (taken from llvm-mca docs)

llvm-mca has an error that occurs when using windows line endings, in which
LLVM-MCA-END directives with no label cannot be used with LLVM-MCA-BEGIN
directives that do have a label, such as in the following example from the
llvm-mca docs: 

  # LLVM-MCA-BEGIN A simple example
    add %eax, %eax
  # LLVM-MCA-END

A brief investigation reveals that the issue appears to exist in
AsmLexer::LexLineComment, where we have the following code:

  while (CurChar != '\n' && CurChar != '\r' && CurChar != EOF)
    CurChar = getNextChar();
  if (CurChar == '\r' && CurPtr != CurBuf.end() && *CurPtr == '\n')
    ++CurPtr;

  // If we have a CommentConsumer, notify it about the comment.
  if (CommentConsumer) {
    CommentConsumer->HandleComment(
        SMLoc::getFromPointer(CommentTextStart),
        StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
  }

This code shows some awareness of windows line endings, but does not handle
them correctly when calling CommentConsumer->HandleComment(); the comment
string passed in contains every character of the line but the last. This is
correct when using Unix-style line endings (\n), but not Windows-style line
endings (\r\n) for which the carriage return will be included as part of the
comment. This causes llvm-mca to see non-label directives as having the label
"\r", resulting in the following error:

$ cat reproducer.cpp
int foo(int a, int b) {
  __asm volatile("# LLVM-MCA-BEGIN foo");
  a += 42;
  __asm volatile("# LLVM-MCA-END");
  a *= b;
  return a;
}

$ clang reproducer.cpp -S -o - | llvm-mca
<stdin>:30:3: error: found an invalid region end directive                     
                                                # LLVM-MCA-END                 
                                                                               
         ^                                                                     
                                        <stdin>:30:3: note: unable to find an
active region named                                                            
          # LLVM-MCA-END

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201026/468db55f/attachment.html>


More information about the llvm-bugs mailing list