Skip to content

Conversation

@aemerson
Copy link
Contributor

@aemerson aemerson commented Oct 26, 2025

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.

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
@aemerson aemerson marked this pull request as ready for review October 26, 2025 03:28
Copy link
Contributor Author

@llvmbot llvmbot added the llvm:mc Machine (object) code label Oct 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 26, 2025

@llvm/pr-subscribers-llvm-mc

Author: Amara Emerson (aemerson)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/165129.diff

2 Files Affected:

  • (modified) llvm/lib/MC/MCParser/AsmLexer.cpp (+8-1)
  • (added) llvm/test/MC/AsmParser/comments-x86-darwin-eol-dropped.s (+10)
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

@github-actions
Copy link

github-actions bot commented Oct 26, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor Author

aemerson commented Oct 26, 2025

Merge activity

  • Oct 26, 5:49 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Oct 26, 5:51 AM UTC: @aemerson merged this pull request with Graphite.

@aemerson aemerson merged commit 792c65c into main Oct 26, 2025
10 checks passed
@aemerson aemerson deleted the users/amara/asmlexer-comment branch October 26, 2025 05:51
varun-r-mallya pushed a commit to varun-r-mallya/llvm-project that referenced this pull request Oct 27, 2025
… 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
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
… 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
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
… 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
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
… 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-ci
Copy link
Collaborator

llvm-ci commented Nov 4, 2025

LLVM Buildbot has detected a new failure on builder ppc64le-flang-rhel-clang running on ppc64le-flang-rhel-test while building llvm at step 7 "test-build-unified-tree-check-flang-rt".

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
Step 7 (test-build-unified-tree-check-flang-rt) failure: 1200 seconds without output running [b'ninja', b'check-flang-rt'], attempting to kill
...
21.605 [2/8/33] Building CXX object flang-rt/unittests/Runtime/CMakeFiles/RuntimeTests.dir/TemporaryStack.cpp.o
21.680 [2/7/34] Building CXX object flang-rt/unittests/Runtime/CMakeFiles/RuntimeTests.dir/NumericalFormatTest.cpp.o
22.556 [2/6/35] Linking CXX executable flang-rt/unittests/Evaluate/reshape.test
23.345 [2/5/36] Building CXX object flang-rt/unittests/Runtime/CMakeFiles/RuntimeTests.dir/Format.cpp.o
23.949 [2/4/37] Building CXX object flang-rt/unittests/Runtime/CMakeFiles/RuntimeTests.dir/Transformational.cpp.o
24.668 [2/3/38] Building CXX object flang-rt/unittests/Runtime/CMakeFiles/RuntimeTests.dir/CommandTest.cpp.o
32.435 [2/2/39] Building CXX object flang-rt/unittests/Runtime/CMakeFiles/RuntimeTests.dir/CharacterTest.cpp.o
49.628 [2/1/40] Building CXX object flang-rt/unittests/Runtime/CMakeFiles/RuntimeTests.dir/Reduction.cpp.o
53.064 [1/1/41] Linking CXX executable flang-rt/unittests/Runtime/RuntimeTests
53.064 [0/1/41] Running the Flang-RT regression tests
command timed out: 1200 seconds without output running [b'ninja', b'check-flang-rt'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1262.145622

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:mc Machine (object) code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants