[llvm] 70771d8 - [Utils] Allow update_test_checks to scrub attribute annotations

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 30 23:52:52 PST 2019


Author: Johannes Doerfert
Date: 2019-12-31T01:51:22-06:00
New Revision: 70771d8b9e8dba857bce39eee8f5d10ecc17d00f

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

LOG: [Utils] Allow update_test_checks to scrub attribute annotations

Attribute annotations on calls, e.g., #0, are not useful on their own.
This patch adds a flag to update_test_checks.py to scrub them.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D68851

Added: 
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.plain.expected
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.scrub.expected
    llvm/test/tools/UpdateTestChecks/update_test_checks/scrub_attrs.test

Modified: 
    llvm/utils/UpdateTestChecks/common.py
    llvm/utils/update_test_checks.py

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll
new file mode 100644
index 000000000000..2733cfbce820
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll
@@ -0,0 +1,8 @@
+; RUN: opt -S < %s | FileCheck %s
+
+declare void @foo()
+
+define internal void @bar() {
+  call void @foo() readnone
+  ret void
+}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.plain.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.plain.expected
new file mode 100644
index 000000000000..525e57432fb7
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.plain.expected
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S < %s | FileCheck %s
+
+declare void @foo()
+
+define internal void @bar() {
+; CHECK-LABEL: @bar(
+; CHECK-NEXT:    call void @foo() #0
+; CHECK-NEXT:    ret void
+;
+  call void @foo() readnone
+  ret void
+}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.scrub.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.scrub.expected
new file mode 100644
index 000000000000..cbea04a09719
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.scrub.expected
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S < %s | FileCheck %s
+
+declare void @foo()
+
+define internal void @bar() {
+; CHECK-LABEL: @bar(
+; CHECK-NEXT:    call void @foo()
+; CHECK-NEXT:    ret void
+;
+  call void @foo() readnone
+  ret void
+}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/scrub_attrs.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/scrub_attrs.test
new file mode 100644
index 000000000000..0adfb8440b36
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/scrub_attrs.test
@@ -0,0 +1,9 @@
+## scrub_attrs test checking that update_test_checks.py works correctly
+# RUN: cp -f %S/Inputs/scrub_attrs.ll %t.ll && %update_test_checks %t.ll
+# RUN: 
diff  -u %t.ll %S/Inputs/scrub_attrs.ll.plain.expected
+## Check that running the script again does not change the result:
+# RUN: %update_test_checks %t.ll
+# RUN: 
diff  -u %t.ll %S/Inputs/scrub_attrs.ll.plain.expected
+## Also try the --scrub-attributes flag
+# RUN: %update_test_checks %t.ll --scrub-attributes
+# RUN: 
diff  -u %t.ll %S/Inputs/scrub_attrs.ll.scrub.expected

diff  --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index f93f8bf1cc75..ccb6ba586de6 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -81,6 +81,8 @@ def invoke_tool(exe, cmd_args, ir):
 SCRUB_LEADING_WHITESPACE_RE = re.compile(r'^(\s+)')
 SCRUB_WHITESPACE_RE = re.compile(r'(?!^(|  \w))[ \t]+', flags=re.M)
 SCRUB_TRAILING_WHITESPACE_RE = re.compile(r'[ \t]+$', flags=re.M)
+SCRUB_TRAILING_WHITESPACE_TEST_RE = SCRUB_TRAILING_WHITESPACE_RE
+SCRUB_TRAILING_WHITESPACE_AND_ATTRIBUTES_RE = re.compile(r'([ \t]|(#[0-9]+))+$', flags=re.M)
 SCRUB_KILL_COMMENT_RE = re.compile(r'^ *#+ +kill:.*\n')
 SCRUB_LOOP_COMMENT_RE = re.compile(
     r'# =>This Inner Loop Header:.*|# in Loop:.*', flags=re.M)
@@ -125,7 +127,7 @@ def scrub_body(body):
   # Expand the tabs used for indentation.
   body = string.expandtabs(body, 2)
   # Strip trailing whitespace.
-  body = SCRUB_TRAILING_WHITESPACE_RE.sub(r'', body)
+  body = SCRUB_TRAILING_WHITESPACE_TEST_RE.sub(r'', body)
   return body
 
 def do_scrub(body, scrubber, scrubber_args, extra):

diff  --git a/llvm/utils/update_test_checks.py b/llvm/utils/update_test_checks.py
index 8ee226549802..94e3fef1fcad 100755
--- a/llvm/utils/update_test_checks.py
+++ b/llvm/utils/update_test_checks.py
@@ -64,6 +64,8 @@ def main():
                       help='Do not scrub IR names')
   parser.add_argument('--function-signature', action='store_true',
                       help='Keep function signature information around for the check line')
+  parser.add_argument('--scrub-attributes', action='store_true',
+                      help='Remove attribute annotations (#0) from the end of check line')
   parser.add_argument('tests', nargs='+')
   args = common.parse_commandline_args(parser)
 
@@ -98,6 +100,13 @@ def main():
         continue
 
     run_lines = common.find_run_lines(test, input_lines)
+
+    # If requested we scrub trailing attribute annotations, e.g., '#0', together with whitespaces
+    if args.scrub_attributes:
+      common.SCRUB_TRAILING_WHITESPACE_TEST_RE = common.SCRUB_TRAILING_WHITESPACE_AND_ATTRIBUTES_RE
+    else:
+      common.SCRUB_TRAILING_WHITESPACE_TEST_RE = common.SCRUB_TRAILING_WHITESPACE_RE
+
     prefix_list = []
     for l in run_lines:
       if '|' not in l:


        


More information about the llvm-commits mailing list