[Mlir-commits] [mlir] [mlir][AsmParser] Fix comment detection in string literals (PR #174125)

Mehdi Amini llvmlistbot at llvm.org
Wed Jan 14 07:13:10 PST 2026


================
@@ -198,6 +198,43 @@ InFlightDiagnostic Parser::emitError(const Twine &message) {
   return emitError(SMLoc::getFromPointer(loc.getPointer() - 1), message);
 }
 
+/// Find the start of a line comment (`//`) in the given string, ignoring
+/// occurrences inside string literals. Returns StringRef::npos if no comment
+/// is found.
+static size_t findCommentStart(StringRef line) {
+  // Fast path: no comment in line at all.
+  size_t slashPos = line.find("//");
+  if (slashPos == StringRef::npos)
+    return StringRef::npos;
+
----------------
joker-eph wrote:

Another fast path here could be slashPos == 0?

https://github.com/llvm/llvm-project/pull/174125


More information about the Mlir-commits mailing list