[llvm] [UTC] Recognise CHECK lines with globals matched literally (PR #70050)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 07:36:55 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-testing-tools

Author: Henrik G. Olsson (hnrklssn)

<details>
<summary>Changes</summary>

Previously when using `-p` a.k.a. `--preserve-names` existing lines for checking globals were not recognised as such, leading to the line being kept while also being emitted again, resulting in duplicated CHECK lines.

This resolves #<!-- -->70048.

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


4 Files Affected:

- (added) llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_preserve_name.ll (+13) 
- (added) llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_preserve_name.ll.expected (+14) 
- (added) llvm/test/tools/UpdateTestChecks/update_test_checks/global_preserve_name.test (+7) 
- (modified) llvm/utils/UpdateTestChecks/common.py (+1-1) 


``````````diff
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_preserve_name.ll b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_preserve_name.ll
new file mode 100644
index 000000000000000..b872e9d53e2cba1
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_preserve_name.ll
@@ -0,0 +1,13 @@
+; RUN: opt -S < %s | FileCheck %s
+
+ at G = constant i32 42
+
+;.
+; CHECK: @G = constant i32 42
+;.
+define ptr @foo() {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:    ret ptr @G
+;
+  ret ptr @G
+}
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_preserve_name.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_preserve_name.ll.expected
new file mode 100644
index 000000000000000..f29ed24be3fec7c
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_preserve_name.ll.expected
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: -p --check-globals
+; RUN: opt -S < %s | FileCheck %s
+
+ at G = constant i32 42
+
+;.
+; CHECK: @G = constant i32 42
+;.
+define ptr @foo() {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:    ret ptr @G
+;
+  ret ptr @G
+}
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/global_preserve_name.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/global_preserve_name.test
new file mode 100644
index 000000000000000..824c221f1ad78d6
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/global_preserve_name.test
@@ -0,0 +1,7 @@
+## Basic test checking that update_test_checks.py works correctly
+# RUN: cp -f %S/Inputs/global_preserve_name.ll %t.ll && %update_test_checks %t.ll --check-globals --preserve-names
+# RUN: diff -u %t.ll %S/Inputs/global_preserve_name.ll.expected
+## Verify that running without the --global-value-regex flag respects UTC_ARGS
+# RUN: %update_test_checks %t.ll
+# RUN: diff -u %t.ll %S/Inputs/global_preserve_name.ll.expected
+
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index c8c8d85e0dc68c8..33da7b3b8665dd5 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -391,7 +391,7 @@ def should_add_line_to_output(
     m = CHECK_RE.match(input_line)
     if m and m.group(1) in prefix_set:
         if skip_global_checks:
-            global_ir_value_re = re.compile(r"\[\[", flags=(re.M))
+            global_ir_value_re = re.compile(r"(\[\[|@)", flags=(re.M))
             return not global_ir_value_re.search(input_line)
         return False
 

``````````

</details>


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


More information about the llvm-commits mailing list