[llvm] 998c323 - [UTC] Keep function args parenthesis on label line (bumps version to 3)
Jannik Silvanus via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 29 07:40:25 PDT 2023
Author: Jannik Silvanus
Date: 2023-08-29T16:40:06+02:00
New Revision: 998c323910134ba5e88046a7f52cc2100cf30282
URL: https://github.com/llvm/llvm-project/commit/998c323910134ba5e88046a7f52cc2100cf30282
DIFF: https://github.com/llvm/llvm-project/commit/998c323910134ba5e88046a7f52cc2100cf30282.diff
LOG: [UTC] Keep function args parenthesis on label line (bumps version to 3)
If the function argument block contains patterns, we split argument
matching into a separate SAME line, because LABEL labels may not contain
pattern matches.
Until now, in this case we moved the parenthesis opening the argument block
into the second line.
This generates incorrect labels in case function names are not prefix-free.
For example, for a function `foo` we generated:
CHECK-LABEL: foo
CHECK-SAME: (<args of foo>)
If the output also contains a function `foo.specialzied`, then the label for
`foo` can match `foo.specialized`, depending on output order.
This patch moves opening parenthesis to the first line, breaking common prefixes:
CHECK-LABEL: foo(
CHECK-SAME: <args of foo>)
Bump the UTC version to 3, and only move the parenthesis for version 3 and later.
Differential Revision: https://reviews.llvm.org/D158497
Added:
Modified:
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/named_function_arguments_split.ll.expected
llvm/test/tools/UpdateTestChecks/update_test_checks/named_function_arguments_split.test
llvm/utils/UpdateTestChecks/common.py
Removed:
################################################################################
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/named_function_arguments_split.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/named_function_arguments_split.ll.expected
index 188d311707b194..b1eb87b741a0c5 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/named_function_arguments_split.ll.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/named_function_arguments_split.ll.expected
@@ -1,14 +1,13 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
; Check that we split named function arguments correctly into a separate CHECK line,
; ensuring the opening parenthesis is on the label name, avoiding incorrect label
; matches if function names are not prefix free.
-; Note: This is a precommitted test, the current result is incorrect.
;
; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
;
define i32 @"foo"(i32 %named) {
-; CHECK-LABEL: define i32 @foo
-; CHECK-SAME: (i32 [[NAMED:%.*]]) {
+; CHECK-LABEL: define i32 @foo(
+; CHECK-SAME: i32 [[NAMED:%.*]]) {
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i32 [[NAMED]]
;
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/named_function_arguments_split.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/named_function_arguments_split.test
index fac7a34f3253de..245e611b29e2c3 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/named_function_arguments_split.test
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/named_function_arguments_split.test
@@ -1,7 +1,7 @@
# REQUIRES: x86-registered-target
## Basic test checking that update_test_checks.py works correctly
-# RUN: cp -f %S/Inputs/named_function_arguments_split.ll %t.ll && %update_test_checks %t.ll --version=2
+# RUN: cp -f %S/Inputs/named_function_arguments_split.ll %t.ll && %update_test_checks %t.ll --version=3
# RUN:
diff -u %t.ll %S/Inputs/named_function_arguments_split.ll.expected
## Check that running the script again does not change the result:
-# RUN: %update_test_checks %t.ll --version=2
+# RUN: %update_test_checks %t.ll --version=3
# RUN:
diff -u %t.ll %S/Inputs/named_function_arguments_split.ll.expected
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index fe333d4973035a..22c05322d9c7db 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -24,8 +24,10 @@
1: Initial version, used by tests that don't specify --version explicitly.
2: --function-signature is now enabled by default and also checks return
type/attributes.
+3: Opening parenthesis of function args is kept on the first LABEL line
+ in case arguments are split to a separate SAME line.
"""
-DEFAULT_VERSION = 2
+DEFAULT_VERSION = 3
class Regex(object):
@@ -1277,13 +1279,27 @@ def add_checks(
)[0]
func_name_separator = func_dict[checkprefix][func_name].func_name_separator
if "[[" in args_and_sig:
+ # Captures in label lines are not supported, thus split into a -LABEL
+ # and a separate -SAME line that contains the arguments with captures.
+ args_and_sig_prefix = ""
+ if version >= 3 and args_and_sig.startswith("("):
+ # Ensure the "(" separating function name and arguments is in the
+ # label line. This is required in case of function names that are
+ # prefixes of each other. Otherwise, the label line for "foo" might
+ # incorrectly match on "foo.specialized".
+ args_and_sig_prefix = args_and_sig[0]
+ args_and_sig = args_and_sig[1:]
+
+ # Removing args_and_sig from the label match line requires
+ # func_name_separator to be empty. Otherwise, the match will not work.
+ assert func_name_separator == ""
output_lines.append(
check_label_format
% (
checkprefix,
funcdef_attrs_and_ret,
func_name,
- "",
+ args_and_sig_prefix,
func_name_separator,
)
)
More information about the llvm-commits
mailing list