[llvm] [UTC][LV] Allow running multiple UTC scripts on a single file (PR #212374)

Andrei Elovikov via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 31 15:47:25 PDT 2026


================
@@ -664,12 +714,68 @@ def find_run_lines(test, lines):
             run_lines[-1] = run_lines[-1].rstrip("\\") + " " + l
         else:
             run_lines.append(l)
+    if run_lines_filter is not None:
+        selected = parse_run_lines_argument(run_lines_filter, len(run_lines))
+        run_lines = [
+            line for (index, line) in enumerate(run_lines, start=1) if index in selected
+        ]
     debug("Found {} RUN lines in {}:".format(len(run_lines), test))
     for l in run_lines:
         debug("  RUN: {}".format(l))
     return run_lines
 
 
+def parse_run_lines_argument(run_lines_filter, num_run_lines):
+    """Parse a --run-lines filter into a set of selected 1-based RUN indices.
+
+    The filter is a comma-separated list of items, where each item is either a
+    single positive line number ``N`` or an inclusive range ``N-M``. All
+    selected indices must refer to existing RUN lines in the current test file,
+    so values are validated against ``num_run_lines``.
+
+    Args:
+        run_lines_filter: The raw ``--run-lines`` option value.
+        num_run_lines: Total number of RUN lines available in the test.
+
+    Returns:
+        A set of 1-based RUN line indices selected by the filter.
+
+    Raises:
+        ValueError: If the filter contains an empty item, an invalid range,
+            non-positive indices, a descending range, or an index past the end
+            of the available RUN lines.
+    """
+    selected = set()
+    for item in run_lines_filter.split(","):
+        item = item.strip()
+        error_str = "invalid --run-lines entry '{}'; expected N or N-M, 0 < N <= M <= {}".format(
+            item, num_run_lines
+        )
+        if not item:
+            raise ValueError(error_str)
+
+        if "-" in item:
+            bounds = item.split("-", 1)
+            if len(bounds) != 2 or not bounds[0] or not bounds[1]:
+                raise ValueError(error_str)
+
+        try:
+            if "-" in item:
+                start = int(bounds[0])
+                end = int(bounds[1])
+            else:
+                start = end = int(item)
----------------
eas wrote:

I've modified this function, hopefully it addressed this.

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


More information about the llvm-commits mailing list