[llvm] Fix regular expression to guard against a repeating version string (PR #84575)

Wolfgang Pieb via llvm-commits llvm-commits at lists.llvm.org
Fri May 24 13:37:09 PDT 2024


https://github.com/wolfy1961 updated https://github.com/llvm/llvm-project/pull/84575

>From 5b3266da997c5934e807d80739e612224439aaef Mon Sep 17 00:00:00 2001
From: wpieb <Wolfgang.Pieb at sony.com>
Date: Fri, 8 Mar 2024 13:44:47 -0800
Subject: [PATCH 1/2] Fix regular expression to guard against a repeating
 version string

---
 llvm/utils/UpdateTestChecks/common.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 85c129488d950..e869a75beecba 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -2201,7 +2201,7 @@ def add(var):
 
 METADATA_FILTERS = [
     (
-        r"(?<=\")(.+ )?(\w+ version )[\d.]+(?:[^\" ]*)(?: \([^)]+\))?",
+        r"(?<=\")(.+ )??(\w+ version )[\d.]+(?:[^\" ]*)(?: \([^)]+\))?",
         r"{{.*}}\2{{.*}}",
     ),  # preface with glob also, to capture optional CLANG_VENDOR
     (r'(!DIFile\(filename: ".+", directory: )".+"', r"\1{{.*}}"),

>From 48686a14623475887ff0a8c97f8a7839de4b1a07 Mon Sep 17 00:00:00 2001
From: wpieb <Wolfgang.Pieb at sony.com>
Date: Tue, 12 Mar 2024 15:14:31 -0700
Subject: [PATCH 2/2] Test that version strings that repeat "version" are
 changed into the correct pattern.

---
 .../Inputs/version_string_regex.ll                  |  7 +++++++
 .../Inputs/version_string_regex.ll.expected         | 13 +++++++++++++
 .../update_test_checks/version_string_regex.test    |  5 +++++
 3 files changed, 25 insertions(+)
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/version_string_regex.ll
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/version_string_regex.ll.expected
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_test_checks/version_string_regex.test

diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/version_string_regex.ll b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/version_string_regex.ll
new file mode 100644
index 0000000000000..e6bd7fd4e4676
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/version_string_regex.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -S | FileCheck %s
+!llvm.module.flags = !{!0, !1}
+!llvm.ident = !{!2}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 7, !"openmp", i32 51}
+!2 = !{!"clang version 19.0.0 (myvendor clang version 99.99.0.59070 deadbabe asserts)"}
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/version_string_regex.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/version_string_regex.ll.expected
new file mode 100644
index 0000000000000..7b1b14e1e33a2
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/version_string_regex.ll.expected
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --no-generate-body-for-unused-prefixes
+; RUN: opt < %s -S | FileCheck %s
+!llvm.module.flags = !{!0, !1}
+!llvm.ident = !{!2}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 7, !"openmp", i32 51}
+!2 = !{!"clang version 19.0.0 (myvendor clang version 99.99.0.59070 deadbabe asserts)"}
+;.
+; CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+; CHECK: [[META1:![0-9]+]] = !{i32 7, !"openmp", i32 51}
+; CHECK: [[META2:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
+;.
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/version_string_regex.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/version_string_regex.test
new file mode 100644
index 0000000000000..e27983d353531
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/version_string_regex.test
@@ -0,0 +1,5 @@
+# We check that if a version string emitted by a tool repeats "version", we generate
+# the correct pattern for FileCheck.
+RUN: cp -f %S/Inputs/version_string_regex.ll %t.ll
+RUN: %update_test_checks --no-generate-body-for-unused-prefixes --check-globals all %t.ll
+RUN: diff -u %t.ll %S/Inputs/version_string_regex.ll.expected



More information about the llvm-commits mailing list