[PATCH] D158497: [UTC] Keep function args parenthesis on label line (bumps version to 3)

Jannik Silvanus via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 22 02:31:18 PDT 2023


jsilvanus created this revision.
Herald added a subscriber: arichardson.
Herald added a project: All.
jsilvanus requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.

The test case is new. I'll precommit it if this patch is accepted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158497

Files:
  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


Index: llvm/utils/UpdateTestChecks/common.py
===================================================================
--- llvm/utils/UpdateTestChecks/common.py
+++ 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):
@@ -1271,13 +1273,27 @@
                 )[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,
                     )
                 )
Index: llvm/test/tools/UpdateTestChecks/update_test_checks/named_function_arguments_split.test
===================================================================
--- llvm/test/tools/UpdateTestChecks/update_test_checks/named_function_arguments_split.test
+++ 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
Index: llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/named_function_arguments_split.ll.expected
===================================================================
--- llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/named_function_arguments_split.ll.expected
+++ llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/named_function_arguments_split.ll.expected
@@ -1,4 +1,4 @@
-; 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.
@@ -7,8 +7,8 @@
 ; 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]]
 ;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158497.552270.patch
Type: text/x-patch
Size: 4200 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230822/ac05118a/attachment.bin>


More information about the llvm-commits mailing list