       }
 
       // Scan to next CHECK-LABEL match, ignoring CHECK-NOT and CHECK-DAG
-      guard let (matchLabelPos, matchLabelLen) = checkStr.check(buffer, true, variableTable) else {
+      guard let range = checkStr.check(buffer, true, variableTable) else {
         // Immediately bail of CHECK-LABEL fails, nothing else we can do.
         return false
       }
 
-      checkRegion = buffer.substring(to: buffer.index(buffer.startIndex, offsetBy: matchLabelPos + matchLabelLen))
-      buffer = buffer.substring(from: buffer.index(buffer.startIndex, offsetBy: matchLabelPos + matchLabelLen))
+
+      checkRegion = buffer.substring(to: buffer.index(buffer.startIndex, offsetBy: NSMaxRange(range)))
+      buffer = buffer.substring(from: buffer.index(buffer.startIndex, offsetBy: NSMaxRange(range)))
       j += 1
     }
 

  /// Matches the pattern string against the input buffer.
  ///
  /// This returns the position that is matched or npos if there is no match. If
  /// there is a match, the size of the matched string is returned in \p
  /// MatchLen.
  ///
  /// The \p VariableTable StringMap provides the current values of filecheck
  /// variables and is updated if this match defines new values.
  func match(_ buffer : String, _ variableTable : BoxedTable) -> (Int, Int)? {
    var matchLen : Int = 0
    // If this is the EOF pattern, match it immediately.
    if self.type == .EOF {
      matchLen = 0
      return (buffer.utf8.count, matchLen)
    }

    // If this is a fixed string pattern, just match it now.
    if !self.fixedString.isEmpty {
      matchLen = self.fixedString.utf8.count
      if let b = buffer.range(of: self.fixedString)?.lowerBound {
        return (buffer.distance(from: buffer.startIndex, to: b), matchLen)
      }
      return nil
    }

      }
      return nil
    }
    let (matchPos, matchLen) = (range.location, range.length)

    // Similar to the above, in "label-scan mode" we can't yet handle CHECK-NEXT
    // or CHECK-NOT
