[Mlir-commits] [mlir] [mlir] generate-test-checks.py does not double insert note. (PR #166443)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Nov 4 12:59:07 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Michael Maitland (michaelmaitland)

<details>
<summary>Changes</summary>

When we generate test checks into the original test file (inplace), it was incorrectly removing empty lines.

I tested this by running

```
my-downstream-opt-tool file.mlir -mypass | python3 ~/llvm-project/mlir/utils/generate-test-checks.py --source file.mlir -i
```

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


1 Files Affected:

- (modified) mlir/utils/generate-test-checks.py (+8-1) 


``````````diff
diff --git a/mlir/utils/generate-test-checks.py b/mlir/utils/generate-test-checks.py
index 3712a6b9c963d..aae0b14965cad 100755
--- a/mlir/utils/generate-test-checks.py
+++ b/mlir/utils/generate-test-checks.py
@@ -234,10 +234,17 @@ def process_source_lines(source_lines, note, args):
     source_split_re = re.compile(args.source_delim_regex)
 
     source_segments = [[]]
+    skip_next_empty_line = False
     for line in source_lines:
         # Remove previous note.
-        if line in note:
+        if line and line in note:
+            skip_next_empty_line = True
             continue
+        # Skip the first empty line after the note
+        if skip_next_empty_line and not line:
+            skip_next_empty_line = False
+            continue
+        skip_next_empty_line = False
         # Remove previous CHECK lines.
         if line.find(args.check_prefix) != -1:
             continue

``````````

</details>


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


More information about the Mlir-commits mailing list