Skip to content

Commit 998c323

Browse files
committed
[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
1 parent dd1cf3a commit 998c323

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/named_function_arguments_split.ll.expected

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
22
; Check that we split named function arguments correctly into a separate CHECK line,
33
; ensuring the opening parenthesis is on the label name, avoiding incorrect label
44
; matches if function names are not prefix free.
5-
; Note: This is a precommitted test, the current result is incorrect.
65
;
76
; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
87
;
98
define i32 @"foo"(i32 %named) {
10-
; CHECK-LABEL: define i32 @foo
11-
; CHECK-SAME: (i32 [[NAMED:%.*]]) {
9+
; CHECK-LABEL: define i32 @foo(
10+
; CHECK-SAME: i32 [[NAMED:%.*]]) {
1211
; CHECK-NEXT: entry:
1312
; CHECK-NEXT: ret i32 [[NAMED]]
1413
;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# REQUIRES: x86-registered-target
22
## Basic test checking that update_test_checks.py works correctly
3-
# RUN: cp -f %S/Inputs/named_function_arguments_split.ll %t.ll && %update_test_checks %t.ll --version=2
3+
# RUN: cp -f %S/Inputs/named_function_arguments_split.ll %t.ll && %update_test_checks %t.ll --version=3
44
# RUN: diff -u %t.ll %S/Inputs/named_function_arguments_split.ll.expected
55
## Check that running the script again does not change the result:
6-
# RUN: %update_test_checks %t.ll --version=2
6+
# RUN: %update_test_checks %t.ll --version=3
77
# RUN: diff -u %t.ll %S/Inputs/named_function_arguments_split.ll.expected

llvm/utils/UpdateTestChecks/common.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
1: Initial version, used by tests that don't specify --version explicitly.
2525
2: --function-signature is now enabled by default and also checks return
2626
type/attributes.
27+
3: Opening parenthesis of function args is kept on the first LABEL line
28+
in case arguments are split to a separate SAME line.
2729
"""
28-
DEFAULT_VERSION = 2
30+
DEFAULT_VERSION = 3
2931

3032

3133
class Regex(object):
@@ -1277,13 +1279,27 @@ def add_checks(
12771279
)[0]
12781280
func_name_separator = func_dict[checkprefix][func_name].func_name_separator
12791281
if "[[" in args_and_sig:
1282+
# Captures in label lines are not supported, thus split into a -LABEL
1283+
# and a separate -SAME line that contains the arguments with captures.
1284+
args_and_sig_prefix = ""
1285+
if version >= 3 and args_and_sig.startswith("("):
1286+
# Ensure the "(" separating function name and arguments is in the
1287+
# label line. This is required in case of function names that are
1288+
# prefixes of each other. Otherwise, the label line for "foo" might
1289+
# incorrectly match on "foo.specialized".
1290+
args_and_sig_prefix = args_and_sig[0]
1291+
args_and_sig = args_and_sig[1:]
1292+
1293+
# Removing args_and_sig from the label match line requires
1294+
# func_name_separator to be empty. Otherwise, the match will not work.
1295+
assert func_name_separator == ""
12801296
output_lines.append(
12811297
check_label_format
12821298
% (
12831299
checkprefix,
12841300
funcdef_attrs_and_ret,
12851301
func_name,
1286-
"",
1302+
args_and_sig_prefix,
12871303
func_name_separator,
12881304
)
12891305
)

0 commit comments

Comments
 (0)