[llvm] [llubi] Add UTC helper (PR #180603)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 10 07:33:15 PST 2026
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/180603
>From bba02f3664ebc964abe74cf35adcfb1111a328c3 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Tue, 10 Feb 2026 03:48:42 +0800
Subject: [PATCH 1/2] [llubi] Add UTC helper
---
llvm/docs/TestingGuide.rst | 3 +
llvm/test/tools/llubi/main.ll | 1 +
llvm/test/tools/llubi/main2.ll | 1 +
llvm/test/tools/llubi/poison.ll | 1 +
llvm/utils/UpdateTestChecks/common.py | 1 +
llvm/utils/update_llubi_test_checks.py | 137 +++++++++++++++++++++++++
6 files changed, 144 insertions(+)
create mode 100755 llvm/utils/update_llubi_test_checks.py
diff --git a/llvm/docs/TestingGuide.rst b/llvm/docs/TestingGuide.rst
index 6ab33383e929b..f2c953a6221fc 100644
--- a/llvm/docs/TestingGuide.rst
+++ b/llvm/docs/TestingGuide.rst
@@ -328,6 +328,9 @@ assertions:
update_test_checks.py
opt
+ update_llubi_test_checks.py
+ llubi
+
Precommit workflow for tests
----------------------------
diff --git a/llvm/test/tools/llubi/main.ll b/llvm/test/tools/llubi/main.ll
index c10824621018e..357614cb009f2 100644
--- a/llvm/test/tools/llubi/main.ll
+++ b/llvm/test/tools/llubi/main.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_llubi_test_checks.py UTC_ARGS: --version 6
; RUN: llubi --verbose < %s 2>&1 | FileCheck %s
define i32 @main(i32 %argc, ptr %argv) {
diff --git a/llvm/test/tools/llubi/main2.ll b/llvm/test/tools/llubi/main2.ll
index 58c5744bb0909..86836baeef4d0 100644
--- a/llvm/test/tools/llubi/main2.ll
+++ b/llvm/test/tools/llubi/main2.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_llubi_test_checks.py UTC_ARGS: --version 6
; RUN: llubi --verbose < %s 2>&1 | FileCheck %s
define i32 @main() {
diff --git a/llvm/test/tools/llubi/poison.ll b/llvm/test/tools/llubi/poison.ll
index cf3b69d1aeb77..34f18a05b4b94 100644
--- a/llvm/test/tools/llubi/poison.ll
+++ b/llvm/test/tools/llubi/poison.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_llubi_test_checks.py UTC_ARGS: --version 6
; RUN: not llubi --verbose < %s 2>&1 | FileCheck %s
define i32 @main(i32 %argc, ptr %argv) {
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 9cca0a7ad5d38..60ee18f5e4fc4 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -2723,6 +2723,7 @@ def get_autogennote_suffix(parser, args):
"tool_binary",
"opt_binary",
"llc_binary",
+ "llubi_binary",
"clang",
"opt",
"llvm_bin",
diff --git a/llvm/utils/update_llubi_test_checks.py b/llvm/utils/update_llubi_test_checks.py
new file mode 100755
index 0000000000000..23c5850c9eafa
--- /dev/null
+++ b/llvm/utils/update_llubi_test_checks.py
@@ -0,0 +1,137 @@
+#!/usr/bin/env python3
+
+"""A test case update script.
+
+This script is a utility to update LLVM 'llubi' based test cases with new
+FileCheck patterns.
+"""
+
+from __future__ import print_function
+
+from sys import stderr
+from traceback import print_exc
+import argparse
+import os # Used to advertise this file's name ("autogenerated_note").
+import subprocess
+import sys
+
+from UpdateTestChecks import common
+
+# llubi is the only llubi-like in the LLVM tree but downstream forks can add
+# additional ones here if they have them.
+LLUBI_LIKE_TOOLS = [
+ "llubi",
+]
+
+# Invoke the tool that is being tested.
+def invoke_tool(exe, cmd_args, ir, check_rc):
+ with open(ir) as ir_file:
+ substitutions = common.getSubstitutions(ir)
+ stdout = subprocess.run(
+ exe + " " + common.applySubstitutions(cmd_args, substitutions),
+ shell=True,
+ stdin=ir_file,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ check=check_rc
+ ).stdout.decode()
+ # Fix line endings to unix CR style.
+ return stdout.replace("\r\n", "\n")
+
+def update_test(ti: common.TestInfo):
+ if len(ti.run_lines) == 0:
+ common.warn("No RUN lines found in test: " + ti.path)
+ return
+ if len(ti.run_lines) > 1:
+ common.warn("Multiple RUN lines found in test: " + ti.path)
+ common.warn("Only the first RUN line will be processed.")
+
+ l = ti.run_lines[0]
+ if "|" not in l:
+ common.warn("Skipping unparsable RUN line: " + l)
+ return
+
+ commands = [cmd.strip() for cmd in l.split("|")]
+ assert len(commands) == 2
+ llubi_cmd = commands[-2]
+ filecheck_cmd = commands[-1]
+ args = llubi_cmd.split(" ")
+ llubi_tool = args[0]
+ check_rc = True
+ if len(args) > 1 and args[0] == "not":
+ llubi_tool = args[1]
+ check_rc = False
+
+ common.verify_filecheck_prefixes(filecheck_cmd)
+
+ llubi_like_tools = LLUBI_LIKE_TOOLS[:]
+ if ti.args.tool:
+ llubi_like_tools.append(ti.args.tool)
+ if llubi_tool not in llubi_like_tools:
+ common.warn("Skipping non-llubi RUN line: " + l)
+ return
+
+ if not filecheck_cmd.startswith("FileCheck "):
+ common.warn("Skipping non-FileChecked RUN line: " + l)
+ return
+
+ llubi_args = llubi_cmd[llubi_cmd.index(llubi_tool) + len(llubi_tool) :].strip()
+ llubi_args = llubi_args.replace("< %s", "").replace("%s", "").strip()
+ prefixes = common.get_check_prefixes(filecheck_cmd)
+
+ common.debug("Extracted llubi cmd:", llubi_tool, llubi_args)
+ common.debug("Extracted FileCheck prefixes:", str(prefixes))
+ prefix_set = set([prefix for prefix in prefixes])
+
+ raw_tool_output = invoke_tool(
+ ti.args.llubi_binary or llubi_tool,
+ llubi_args,
+ ti.path,
+ check_rc=check_rc,
+ )
+ if ti.args.llubi_binary:
+ raw_tool_output = raw_tool_output.replace(ti.args.llubi_binary, llubi_tool)
+
+ output_lines = []
+ common.dump_input_lines(output_lines, ti, prefix_set, ";")
+ output_lines.extend(
+ ["; CHECK: " + line for line in raw_tool_output.splitlines()]
+ )
+
+ common.debug("Writing %d lines to %s..." % (len(output_lines), ti.path))
+ with open(ti.path, "wb") as f:
+ f.writelines(["{}\n".format(l).encode("utf-8") for l in output_lines])
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument(
+ "--llubi-binary",
+ default=None,
+ help='The "llubi" binary to use to generate the test case',
+ )
+ parser.add_argument(
+ "--tool",
+ default=None,
+ help="Treat the given tool name as an llubi-like tool for which check lines should be generated",
+ )
+ parser.add_argument("tests", nargs="+")
+ initial_args = common.parse_commandline_args(parser)
+
+ script_name = os.path.basename(__file__)
+
+ returncode = 0
+ for ti in common.itertests(
+ initial_args.tests, parser, script_name="utils/" + script_name
+ ):
+ try:
+ update_test(ti)
+ except Exception as e:
+ stderr.write(f"Error: Failed to update test {ti.path}\n")
+ print_exc()
+ returncode = 1
+ return returncode
+
+
+if __name__ == "__main__":
+ sys.exit(main())
>From 95bb30c117b533011f95643e1269ff0fb92443d8 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Tue, 10 Feb 2026 23:32:50 +0800
Subject: [PATCH 2/2] [llubi] Address review comments.
---
llvm/test/tools/llubi/main.ll | 8 ++++----
llvm/test/tools/llubi/main2.ll | 4 ++--
llvm/test/tools/llubi/poison.ll | 10 ++++-----
llvm/utils/update_llubi_test_checks.py | 28 ++++++++++++--------------
4 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/llvm/test/tools/llubi/main.ll b/llvm/test/tools/llubi/main.ll
index 357614cb009f2..d1e91312314ea 100644
--- a/llvm/test/tools/llubi/main.ll
+++ b/llvm/test/tools/llubi/main.ll
@@ -6,7 +6,7 @@ define i32 @main(i32 %argc, ptr %argv) {
}
; CHECK: Entering function: main
-; CHECK: i32 %argc = i32 1
-; CHECK: ptr %argv = ptr 0x8 [argv]
-; CHECK: ret i32 0
-; CHECK: Exiting function: main
+; CHECK-NEXT: i32 %argc = i32 1
+; CHECK-NEXT: ptr %argv = ptr 0x8 [argv]
+; CHECK-NEXT: ret i32 0
+; CHECK-NEXT: Exiting function: main
diff --git a/llvm/test/tools/llubi/main2.ll b/llvm/test/tools/llubi/main2.ll
index 86836baeef4d0..0752f63354182 100644
--- a/llvm/test/tools/llubi/main2.ll
+++ b/llvm/test/tools/llubi/main2.ll
@@ -6,5 +6,5 @@ define i32 @main() {
}
; CHECK: Entering function: main
-; CHECK: ret i32 0
-; CHECK: Exiting function: main
+; CHECK-NEXT: ret i32 0
+; CHECK-NEXT: Exiting function: main
diff --git a/llvm/test/tools/llubi/poison.ll b/llvm/test/tools/llubi/poison.ll
index 34f18a05b4b94..9d98b7f75e868 100644
--- a/llvm/test/tools/llubi/poison.ll
+++ b/llvm/test/tools/llubi/poison.ll
@@ -5,8 +5,8 @@ define i32 @main(i32 %argc, ptr %argv) {
ret i32 poison
}
; CHECK: Entering function: main
-; CHECK: i32 %argc = i32 1
-; CHECK: ptr %argv = ptr 0x8 [argv]
-; CHECK: ret i32 poison
-; CHECK: Exiting function: main
-; CHECK: error: Execution of function 'main' resulted in poison return value.
+; CHECK-NEXT: i32 %argc = i32 1
+; CHECK-NEXT: ptr %argv = ptr 0x8 [argv]
+; CHECK-NEXT: ret i32 poison
+; CHECK-NEXT: Exiting function: main
+; CHECK-NEXT: error: Execution of function 'main' resulted in poison return value.
diff --git a/llvm/utils/update_llubi_test_checks.py b/llvm/utils/update_llubi_test_checks.py
index 23c5850c9eafa..6b26000698354 100755
--- a/llvm/utils/update_llubi_test_checks.py
+++ b/llvm/utils/update_llubi_test_checks.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
-
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""A test case update script.
This script is a utility to update LLVM 'llubi' based test cases with new
@@ -11,17 +13,12 @@
from sys import stderr
from traceback import print_exc
import argparse
-import os # Used to advertise this file's name ("autogenerated_note").
+import os
import subprocess
import sys
from UpdateTestChecks import common
-# llubi is the only llubi-like in the LLVM tree but downstream forks can add
-# additional ones here if they have them.
-LLUBI_LIKE_TOOLS = [
- "llubi",
-]
# Invoke the tool that is being tested.
def invoke_tool(exe, cmd_args, ir, check_rc):
@@ -33,11 +30,12 @@ def invoke_tool(exe, cmd_args, ir, check_rc):
stdin=ir_file,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
- check=check_rc
+ check=check_rc,
).stdout.decode()
# Fix line endings to unix CR style.
return stdout.replace("\r\n", "\n")
+
def update_test(ti: common.TestInfo):
if len(ti.run_lines) == 0:
common.warn("No RUN lines found in test: " + ti.path)
@@ -64,10 +62,7 @@ def update_test(ti: common.TestInfo):
common.verify_filecheck_prefixes(filecheck_cmd)
- llubi_like_tools = LLUBI_LIKE_TOOLS[:]
- if ti.args.tool:
- llubi_like_tools.append(ti.args.tool)
- if llubi_tool not in llubi_like_tools:
+ if llubi_tool != "llubi":
common.warn("Skipping non-llubi RUN line: " + l)
return
@@ -94,9 +89,12 @@ def update_test(ti: common.TestInfo):
output_lines = []
common.dump_input_lines(output_lines, ti, prefix_set, ";")
- output_lines.extend(
- ["; CHECK: " + line for line in raw_tool_output.splitlines()]
- )
+ tool_output_lines = raw_tool_output.splitlines()
+ if len(tool_output_lines) == 0:
+ common.warn("No output from llubi.")
+ else:
+ output_lines.append("; CHECK: " + tool_output_lines[0])
+ output_lines.extend(["; CHECK-NEXT: " + line for line in tool_output_lines[1:]])
common.debug("Writing %d lines to %s..." % (len(output_lines), ti.path))
with open(ti.path, "wb") as f:
More information about the llvm-commits
mailing list