-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[MC] Fix accidentally eating the newline when handling a comment char at the end of the line. #165129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… at the end of the line. If we have a target where both # and ## are valid comment strings, a line ending in # would trigger the lexer to eat 2 characters and therefore lex the *next* line as a comment. Oops. This was introduced in 4946db1
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
@llvm/pr-subscribers-llvm-mc Author: Amara Emerson (aemerson) ChangesIf we have a target where both # and ## are valid comment strings, Full diff: https://github.com/llvm/llvm-project/pull/165129.diff 2 Files Affected:
diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp
index 968ccf776440b..8062ce88a154b 100644
--- a/llvm/lib/MC/MCParser/AsmLexer.cpp
+++ b/llvm/lib/MC/MCParser/AsmLexer.cpp
@@ -835,7 +835,14 @@ AsmToken AsmLexer::LexToken() {
}
if (isAtStartOfComment(TokStart)) {
- CurPtr += MAI.getCommentString().size() - 1;
+ StringRef CommentString = MAI.getCommentString();
+ // For multi-char comment strings, advance CurPtr only if we matched the full
+ // string. This stops us from accidentally eating the newline if the current
+ // line ends in a single comment char.
+ if (CommentString.size() > 1 &&
+ StringRef(TokStart, CommentString.size()) == CommentString) {
+ CurPtr += CommentString.size() - 1;
+ }
return LexLineComment();
}
diff --git a/llvm/test/MC/AsmParser/comments-x86-darwin-eol-dropped.s b/llvm/test/MC/AsmParser/comments-x86-darwin-eol-dropped.s
new file mode 100644
index 0000000000000..662e5987db6e2
--- /dev/null
+++ b/llvm/test/MC/AsmParser/comments-x86-darwin-eol-dropped.s
@@ -0,0 +1,10 @@
+// RUN: llvm-mc -triple i386-apple-darwin %s 2>&1 | FileCheck %s
+.p2align 3
+// CHECK: .p2align 3
+test:
+// CHECK-LABEL: test:
+// CHECK: pushl %ebp
+// CHECK: movl %esp, %ebp
+# Check that the following line's comment # doesn't drop the movl after
+ pushl %ebp #
+ movl %esp, %ebp
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
… at the end of the line. (llvm#165129) If we have a target where both # and ## are valid comment strings, a line ending in # would trigger the lexer to eat 2 characters and therefore lex the _next_ line as a comment. Oops. This was introduced in 4946db1 rdar://162635338
… at the end of the line. (llvm#165129) If we have a target where both # and ## are valid comment strings, a line ending in # would trigger the lexer to eat 2 characters and therefore lex the _next_ line as a comment. Oops. This was introduced in 4946db1 rdar://162635338
… at the end of the line. (llvm#165129) If we have a target where both # and ## are valid comment strings, a line ending in # would trigger the lexer to eat 2 characters and therefore lex the _next_ line as a comment. Oops. This was introduced in 4946db1 rdar://162635338
… at the end of the line. (llvm#165129) If we have a target where both # and ## are valid comment strings, a line ending in # would trigger the lexer to eat 2 characters and therefore lex the _next_ line as a comment. Oops. This was introduced in 4946db1 rdar://162635338
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/157/builds/41925 Here is the relevant piece of the build log for the reference |

If we have a target where both # and ## are valid comment strings,
a line ending in # would trigger the lexer to eat 2 characters
and therefore lex the next line as a comment. Oops. This was introduced
in 4946db1
rdar://162635338