[llvm] 5375b63 - [UTC] Add --version argument
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 30 00:59:51 PST 2023
Author: Nikita Popov
Date: 2023-01-30T09:57:26+01:00
New Revision: 5375b638be874b5438e98bd8a435e198af3ef2d0
URL: https://github.com/llvm/llvm-project/commit/5375b638be874b5438e98bd8a435e198af3ef2d0
DIFF: https://github.com/llvm/llvm-project/commit/5375b638be874b5438e98bd8a435e198af3ef2d0.diff
LOG: [UTC] Add --version argument
We have a number of pending changes to update_test_checks.py
(and friends) that are essentially blocked on test churn:
If the output of UTC for an existing flag combination changes,
then the next time a test is regenerated, it will contain many
spurious changes. This makes changes to UTC default
behavior essentially impossible.
Examples of such changes are:
* D133943/D142373 want --function-signature to also check the
return type/attributes.
* D139006/D140212 want to make --function-signature the default
behavior.
* D142452 wants to add wildcards for block labels.
This patch tries to resolve this issue by adding a --version
argument, which works as follows:
* When regenerating an old test, the default version is 1.
* When generating a new test, the default version is the newest.
When an explicit version is specified, that of course wins.
This means that any currently existing tests will keep using
--version 1 format, while any new tests will automatically embed
--version N where N is the latest version, and then keep using
that test format from then on.
This patch only implements the --version flag without bumping
the default version, so it does not have any visible behavior
change by itself.
Differential Revision: https://reviews.llvm.org/D142473
Added:
Modified:
clang/test/utils/update_cc_test_checks/lit.local.cfg
llvm/test/tools/UpdateTestChecks/lit.local.cfg
llvm/utils/UpdateTestChecks/common.py
Removed:
################################################################################
diff --git a/clang/test/utils/update_cc_test_checks/lit.local.cfg b/clang/test/utils/update_cc_test_checks/lit.local.cfg
index b78c4ffdab585..b461878880e47 100644
--- a/clang/test/utils/update_cc_test_checks/lit.local.cfg
+++ b/clang/test/utils/update_cc_test_checks/lit.local.cfg
@@ -26,6 +26,10 @@ else:
extra_args = '--clang ' + shell_quote(clang_path)
opt_path = os.path.join(config.llvm_tools_dir, 'opt')
extra_args += ' --opt ' + shell_quote(opt_path)
+ # Specify an explicit default version in UTC tests, so that the --version
+ # embedded in UTC_ARGS does not change in all test expectations every time
+ # the default is bumped.
+ extra_args += ' --version=1'
script_path = os.path.join(config.llvm_src_root, 'utils',
'update_cc_test_checks.py')
assert os.path.isfile(script_path)
diff --git a/llvm/test/tools/UpdateTestChecks/lit.local.cfg b/llvm/test/tools/UpdateTestChecks/lit.local.cfg
index d9d11b5a06c07..cdaf1b3464d22 100644
--- a/llvm/test/tools/UpdateTestChecks/lit.local.cfg
+++ b/llvm/test/tools/UpdateTestChecks/lit.local.cfg
@@ -15,6 +15,10 @@ def add_update_script_substition(name, python_exe=config.python_executable,
assert name.startswith('%')
script_path = os.path.join(config.llvm_src_root, 'utils', name[1:] + '.py')
assert os.path.isfile(script_path)
+ # Specify an explicit default version in UTC tests, so that the --version
+ # embedded in UTC_ARGS does not change in all test expectations every time
+ # the default is bumped.
+ extra_args += ' --version=1'
config.substitutions.append(
(name, "'%s' %s %s" % (python_exe, script_path, extra_args)))
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index cf382c0ff23fa..7e538d775efa7 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -18,6 +18,13 @@
_verbose = False
_prefix_filecheck_ir_name = ''
+"""
+Version changelog:
+
+1: Initial version, used by tests that don't specify --version explicitly.
+"""
+DEFAULT_VERSION = 1
+
class Regex(object):
"""Wrap a compiled regular expression object to allow deep copy of a regexp.
This is required for the deep copy done in do_scrub.
@@ -138,6 +145,10 @@ def __call__(self, parser, namespace, values, option_string=None):
dest='gen_unused_prefix_body',
default=True,
help='Generate a function body that always matches for unused prefixes. This is useful when unused prefixes are desired, and it avoids needing to annotate each FileCheck as allowing them.')
+ # This is the default when regenerating existing tests. The default when
+ # generating new tests is determined by DEFAULT_VERSION.
+ parser.add_argument('--version', type=int, default=1,
+ help='The version of output format')
args = parser.parse_args()
global _verbose, _global_value_regex, _global_hex_value_regex
_verbose = args.verbose
@@ -226,12 +237,18 @@ def itertests(test_patterns, parser, script_name, comment_prefix=None, argparse_
for test in tests_list:
with open(test) as f:
input_lines = [l.rstrip() for l in f]
- args = parser.parse_args()
+ first_line = input_lines[0] if input_lines else ""
+ is_regenerate = UTC_ADVERT in first_line
+
+ # If we're generating a new test, set the default version to the latest.
+ argv = sys.argv[:]
+ if not is_regenerate:
+ argv.insert(1, '--version=' + str(DEFAULT_VERSION))
+
+ args = parser.parse_args(argv[1:])
if argparse_callback is not None:
argparse_callback(args)
- argv = sys.argv[:]
- first_line = input_lines[0] if input_lines else ""
- if UTC_ADVERT in first_line:
+ if is_regenerate:
if script_name not in first_line and not args.force_update:
warn("Skipping test which wasn't autogenerated by " + script_name, test)
continue
More information about the llvm-commits
mailing list