<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Windows newlines cause error in parsing llvm-mca regions"
href="https://bugs.llvm.org/show_bug.cgi?id=47983">47983</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Windows newlines cause error in parsing llvm-mca regions
</td>
</tr>
<tr>
<th>Product</th>
<td>tools
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>llvm-mca
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>stephen.tozer@sony.com
</td>
</tr>
<tr>
<th>CC</th>
<td>andrea.dibiagio@gmail.com, llvm-bugs@lists.llvm.org, matthew.davis@sony.com
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=24102" name="attach_24102" title="C++ source code that reproduces issue (taken from llvm-mca docs)">attachment 24102</a> <a href="attachment.cgi?id=24102&action=edit" title="C++ source code that reproduces issue (taken from llvm-mca docs)">[details]</a></span>
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</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>