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

Henrik G. Olsson via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 07:39:03 PDT 2023


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

>From c4476c3bdd4cf93f396fccb419f62aa3f3aa83e7 Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" <hnrklssn at gmail.com>
Date: Tue, 24 Oct 2023 16:29:01 +0200
Subject: [PATCH 1/2] [UTC] Recognise CHECK lines with globals matched
 literally

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.
---
 .../Inputs/global_preserve_name.ll                 | 13 +++++++++++++
 .../Inputs/global_preserve_name.ll.expected        | 14 ++++++++++++++
 .../update_test_checks/global_preserve_name.test   |  7 +++++++
 llvm/utils/UpdateTestChecks/common.py              |  2 +-
 4 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_preserve_name.ll
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_preserve_name.ll.expected
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_test_checks/global_preserve_name.test

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
 

>From 4257023f04af8b02e26de74398420047e3664559 Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" <hnrklssn at gmail.com>
Date: Tue, 24 Oct 2023 16:38:32 +0200
Subject: [PATCH 2/2] [UTC] Update comment describing test

---
 .../update_test_checks/global_preserve_name.test              | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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
index 824c221f1ad78d6..2ef050abe15b9a1 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/global_preserve_name.test
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/global_preserve_name.test
@@ -1,7 +1,7 @@
-## Basic test checking that update_test_checks.py works correctly
+## Basic test checking that we capture existing lines matching global variable names
 # 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
+## Verify that running without the --global-value-regex flag respects UTC_ARGS, and that the output is a fixed point.
 # RUN: %update_test_checks %t.ll
 # RUN: diff -u %t.ll %S/Inputs/global_preserve_name.ll.expected
 



More information about the llvm-commits mailing list