[PATCH] D98712: [Utils] Support lit-like substitutions in update_cc_test_checks

Giorgis Georgakoudis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 16 10:29:44 PDT 2021


ggeorgakoudis updated this revision to Diff 331035.
ggeorgakoudis added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98712/new/

https://reviews.llvm.org/D98712

Files:
  clang/test/utils/update_cc_test_checks/Inputs/exec-all-runlines.c
  clang/test/utils/update_cc_test_checks/Inputs/exec-all-runlines.c.expected
  llvm/utils/update_cc_test_checks.py


Index: llvm/utils/update_cc_test_checks.py
===================================================================
--- llvm/utils/update_cc_test_checks.py
+++ llvm/utils/update_cc_test_checks.py
@@ -176,7 +176,7 @@
   return args, parser
 
 
-def get_function_body(builder, args, filename, clang_args, extra_commands, 
+def get_function_body(builder, args, filename, clang_args, extra_commands,
                       prefixes):
   # TODO Clean up duplication of asm/common build_function_body_dictionary
   # Invoke external tool and extract function bodies.
@@ -221,6 +221,13 @@
     # Build a list of clang command lines and check prefixes from RUN lines.
     run_list = []
     line2spell_and_mangled_list = collections.defaultdict(list)
+
+    subs = {
+      '%s' : ti.path,
+      '%t' : tempfile.NamedTemporaryFile().name,
+      '%S' : os.getcwd(),
+    }
+
     for l in ti.run_lines:
       commands = [cmd.strip() for cmd in l.split('|')]
 
@@ -234,15 +241,18 @@
       # Execute non-clang runline.
       if exec_args[0] not in SUBST:
         print('NOTE: Executing non-clang RUN line: ' + l, file=sys.stderr)
-        # Replace %s by `filename`.
-        exec_args = [i.replace('%s', ti.path) if '%s' in i else i for i in exec_args]
+        # Do lit-like substitutions.
+        for s in subs:
+          exec_args = [i.replace(s, subs[s]) if s in i else i for i in exec_args]
         exec_run_line(exec_args)
         continue
-      # This is a clang runline, apply %clang substitution rule, replace %s by `filename`,
+      # This is a clang runline, apply %clang substitution rule, do lit-like substitutions,
       # and append args.clang_args
       clang_args = exec_args
       clang_args[0:1] = SUBST[clang_args[0]]
-      clang_args = [i.replace('%s', ti.path) if '%s' in i else i for i in clang_args] + ti.args.clang_args
+      for s in subs:
+        clang_args = [i.replace(s, subs[s]) if s in i else i for i in clang_args]
+      clang_args += ti.args.clang_args
 
       # Extract -check-prefix in FileCheck args
       filecheck_cmd = commands[-1]
@@ -271,7 +281,7 @@
       common.debug('Extracted clang cmd: clang {}'.format(clang_args))
       common.debug('Extracted FileCheck prefixes: {}'.format(prefixes))
 
-      get_function_body(builder, ti.args, ti.path, clang_args, extra_commands, 
+      get_function_body(builder, ti.args, ti.path, clang_args, extra_commands,
                         prefixes)
 
       # Invoke clang -Xclang -ast-dump=json to get mapping from start lines to
@@ -315,7 +325,7 @@
                              prefixes,
                              func_dict, func)
 
-      common.add_checks_at_end(output_lines, run_list, builder.func_order(), 
+      common.add_checks_at_end(output_lines, run_list, builder.func_order(),
                                '//', lambda my_output_lines, prefixes, func:
                                check_generator(my_output_lines,
                                                prefixes, func))
Index: clang/test/utils/update_cc_test_checks/Inputs/exec-all-runlines.c.expected
===================================================================
--- clang/test/utils/update_cc_test_checks/Inputs/exec-all-runlines.c.expected
+++ clang/test/utils/update_cc_test_checks/Inputs/exec-all-runlines.c.expected
@@ -1,6 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // Check that the non-clang/non-filechecked runlines execute
-// RUN: cp %s %s.copy.c
+// RUN: cp %s %S/Output/tmp.copy.c
+// RUN: cp %S/Output/tmp.copy.c %s.copy.c
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp %s.copy.c -emit-llvm-bc -o %t-host.bc
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp -fopenmp-host-ir-file-path %t-host.bc %s.copy.c -emit-llvm -o - | FileCheck %s
 
Index: clang/test/utils/update_cc_test_checks/Inputs/exec-all-runlines.c
===================================================================
--- clang/test/utils/update_cc_test_checks/Inputs/exec-all-runlines.c
+++ clang/test/utils/update_cc_test_checks/Inputs/exec-all-runlines.c
@@ -1,5 +1,6 @@
 // Check that the non-clang/non-filechecked runlines execute
-// RUN: cp %s %s.copy.c
+// RUN: cp %s %S/Output/tmp.copy.c
+// RUN: cp %S/Output/tmp.copy.c %s.copy.c
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp %s.copy.c -emit-llvm-bc -o %t-host.bc
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp -fopenmp-host-ir-file-path %t-host.bc %s.copy.c -emit-llvm -o - | FileCheck %s
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98712.331035.patch
Type: text/x-patch
Size: 4516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210316/faecdba7/attachment-0001.bin>


More information about the cfe-commits mailing list