[llvm] f50bc82 - [UpdateTestChecks] Make generation of UTC_ARGS: comment more robust

Alex Richardson via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 05:13:04 PDT 2020


Author: Alex Richardson
Date: 2020-04-23T13:12:27+01:00
New Revision: f50bc823fe6f4279eb2f426dd54f3151878c0216

URL: https://github.com/llvm/llvm-project/commit/f50bc823fe6f4279eb2f426dd54f3151878c0216
DIFF: https://github.com/llvm/llvm-project/commit/f50bc823fe6f4279eb2f426dd54f3151878c0216.diff

LOG: [UpdateTestChecks] Make generation of UTC_ARGS: comment more robust

We now use the argparse Action objects to determine the name of the flags.
This fixes cases where the key for the stored result ('dest') is not the
same as the command line flag (e.g. --enable/--disable).
Also add a test that --disabled can be part of the initial UTC_ARGS.

This is split out from D78478

Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D78617

Added: 
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/on_the_fly_arg_change.ll.initially_disabled.expected

Modified: 
    llvm/test/tools/UpdateTestChecks/update_test_checks/on_the_fly_arg_change.test
    llvm/utils/UpdateTestChecks/common.py

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/on_the_fly_arg_change.ll.initially_disabled.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/on_the_fly_arg_change.ll.initially_disabled.expected
new file mode 100644
index 000000000000..994209d46ddb
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/on_the_fly_arg_change.ll.initially_disabled.expected
@@ -0,0 +1,42 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes --disable
+; RUN: opt -S < %s | FileCheck %s
+
+declare void @foo()
+
+define void @check_lines_1() {
+  ret void
+}
+
+; UTC_ARGS: --disable
+
+; A check line that would not be auto generated.
+; CHECK: define void @no_check_lines() {
+define void @no_check_lines() {
+  ret void
+}
+
+; UTC_ARGS: --enable
+
+define void @check_lines_2() {
+; CHECK-LABEL: define {{[^@]+}}@check_lines_2()
+; CHECK-NEXT:    ret void
+;
+  ret void
+}
+
+define void @scrub() {
+; CHECK-LABEL: define {{[^@]+}}@scrub()
+; CHECK-NEXT:    call void @foo()
+; CHECK-NEXT:    ret void
+;
+  call void @foo() readnone
+  ret void
+}
+
+define i32 @signature(i32 %arg) {
+; CHECK-LABEL: define {{[^@]+}}@signature
+; CHECK-SAME: (i32 [[ARG:%.*]])
+; CHECK-NEXT:    ret i32 [[ARG]]
+;
+  ret i32 %arg
+}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/on_the_fly_arg_change.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/on_the_fly_arg_change.test
index bb5f6367cd05..b9bcc6528b34 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/on_the_fly_arg_change.test
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/on_the_fly_arg_change.test
@@ -4,3 +4,13 @@
 ## Check that running the script again does not change the result:
 # RUN: %update_test_checks %t.ll
 # RUN: 
diff  -u %t.ll %S/Inputs/on_the_fly_arg_change.ll.expected
+## Check that the --disable flag is added to the initial UTC_ARGS:
+# RUN: cp -f %S/Inputs/on_the_fly_arg_change.ll %t.ll
+# RUN: %update_test_checks --function-signature --scrub-attributes --disable %t.ll
+# RUN: 
diff  -u %t.ll %S/Inputs/on_the_fly_arg_change.ll.initially_disabled.expected
+## Check that the --disable flag from UTC_ARGS is used:
+# RUN: %update_test_checks %t.ll
+# RUN: 
diff  -u %t.ll %S/Inputs/on_the_fly_arg_change.ll.initially_disabled.expected
+## Check that UTC_ARGS: is parsed after the real command line arguments:
+# RUN: %update_test_checks --enable %t.ll
+# RUN: 
diff  -u %t.ll %S/Inputs/on_the_fly_arg_change.ll.initially_disabled.expected

diff  --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 86b36eeb2b2c..a3fca4905f3d 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -396,19 +396,30 @@ def verify_filecheck_prefixes(fc_cmd):
         if prefixes.count(prefix) > 1:
           warn("Supplied prefix '%s' is not unique in the prefix list." % (prefix,))
 
+
 def get_autogennote_suffix(parser, args):
-    autogenerated_note_args = ''
-    for k, v in args._get_kwargs():
-        if parser.get_default(k) == v or k == 'tests' or k == 'update_only' or k == 'opt_binary':
-            continue
-        k = k.replace('_', '-')
-        if type(v) is bool:
-            autogenerated_note_args += '--%s ' % (k)
-        else:
-            autogenerated_note_args += '--%s %s ' % (k, v)
-    if autogenerated_note_args:
-        autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args[:-1])
-    return autogenerated_note_args
+  autogenerated_note_args = ''
+  for action in parser._actions:
+    if not hasattr(args, action.dest):
+      continue  # Ignore options such as --help that aren't included in args
+    # Ignore parameters such as paths to the binary or the list of tests
+    if action.dest in ('tests', 'update_only', 'opt_binary', 'llc_binary',
+                       'clang', 'opt', 'llvm_bin', 'verbose'):
+      continue
+    value = getattr(args, action.dest)
+    if action.const is not None:  # action stores a constant (usually True/False)
+      # Skip actions with 
diff erent constant values (this happens with boolean
+      # --foo/--no-foo options)
+      if value != action.const:
+        continue
+    if parser.get_default(action.dest) == value:
+      continue  # Don't add default values
+    autogenerated_note_args += action.option_strings[0] + ' '
+    if action.const is None:  # action takes a parameter
+      autogenerated_note_args += '%s ' % value
+  if autogenerated_note_args:
+    autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args[:-1])
+  return autogenerated_note_args
 
 
 def check_for_command(line, parser, args, argv):


        


More information about the llvm-commits mailing list