StringRef AsmLexer::LexUntilEndOfStatement() {
TokStart = CurPtr;
- while (!isAtStartOfComment(*CurPtr) && // Start of line comment.
+ while (!isAtStartOfComment(CurPtr) && // Start of line comment.
!isAtStatementSeparator(CurPtr) && // End of statement marker.
*CurPtr != '\n' && *CurPtr != '\r' &&
(*CurPtr != 0 || CurPtr != CurBuf.end())) {
return Token;
}
-bool AsmLexer::isAtStartOfComment(char Char) {
- // FIXME: This won't work for multi-character comment indicators like "//".
- return Char == *MAI.getCommentString();
+bool AsmLexer::isAtStartOfComment(const char *Ptr) {
+ const char *CommentString = MAI.getCommentString();
+
+ if (CommentString[1] == '\0')
+ return CommentString[0] == Ptr[0];
+
+ // FIXME: special case for the bogus "##" comment string in X86MCAsmInfoDarwin
+ if (CommentString[1] == '#')
+ return CommentString[0] == Ptr[0];
+
+ return strncmp(Ptr, CommentString, strlen(CommentString)) == 0;
}
bool AsmLexer::isAtStatementSeparator(const char *Ptr) {
// This always consumes at least one character.
int CurChar = getNextChar();
- if (isAtStartOfComment(CurChar)) {
+ if (isAtStartOfComment(TokStart)) {
// If this comment starts with a '#', then return the Hash token and let
// the assembler parser see if it can be parsed as a cpp line filename
// comment. We do this only if we are at the start of a line.
--- /dev/null
+// RUN: llvm-mc -triple x86_64-apple-darwin %s 2>&1 | FileCheck %s
+# ensure that single '#' comments are worink as expected on x86 darwin
+.align 3 # test single hash after align
+// CHECK: .align 3
+foo: # single hash should be ignored as comment
+// CHECK-LABEL: foo:
+ movl %esp, %ebp # same after an instruction
+// CHECK: movl %esp, %ebp
+# movl %esp, %ebp ## start of the line
+// CHECK-NOT: movl %esp, %ebp
+ # movl %esp, %ebp ## not quite start of the line
+// CHECK-NOT: movl %esp, %ebp
+bar:
+// CHECK-LABEL: bar: