[clang] 2bfe053 - [UpdateCCTestChecks] Fix --replace-value-regex across RUN lines
Joel E. Denny via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 21 14:08:37 PDT 2021
Author: Joel E. Denny
Date: 2021-06-21T17:01:17-04:00
New Revision: 2bfe0536e5143caad80f7a9691fa775cf451317b
URL: https://github.com/llvm/llvm-project/commit/2bfe0536e5143caad80f7a9691fa775cf451317b
DIFF: https://github.com/llvm/llvm-project/commit/2bfe0536e5143caad80f7a9691fa775cf451317b.diff
LOG: [UpdateCCTestChecks] Fix --replace-value-regex across RUN lines
Without this patch, llvm/utils/update_cc_test_checks.py fails to
perform `--replace-value-regex` replacements when two RUN lines
produce the same output and use the same single FileCheck prefix. The
problem is that replacements in a RUN line's output are not performed
until after comparing against previous RUN lines' output, where
replacements have already been performed. This patch fixes that.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D104566
Added:
clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c
clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c.expected
clang/test/utils/update_cc_test_checks/replace-value-regex-across-runs.test
Modified:
llvm/utils/UpdateTestChecks/common.py
Removed:
################################################################################
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c b/clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c
new file mode 100644
index 000000000000..8914a2195371
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm -o - %s | \
+// RUN: FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm -o - %s | \
+// RUN: FileCheck %s
+
+void foo(void) {
+ #pragma omp target
+ ;
+}
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c.expected b/clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c.expected
new file mode 100644
index 000000000000..ea3cc9480f6d
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c.expected
@@ -0,0 +1,15 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+"
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm -o - %s | \
+// RUN: FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm -o - %s | \
+// RUN: FileCheck %s
+
+// CHECK-LABEL: @foo(
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_foo_l7() #[[ATTR2:[0-9]+]]
+// CHECK-NEXT: ret void
+//
+void foo(void) {
+ #pragma omp target
+ ;
+}
diff --git a/clang/test/utils/update_cc_test_checks/replace-value-regex-across-runs.test b/clang/test/utils/update_cc_test_checks/replace-value-regex-across-runs.test
new file mode 100644
index 000000000000..c2fdf6113fc2
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/replace-value-regex-across-runs.test
@@ -0,0 +1,7 @@
+# Test that --replace-value-regex is applied correctly when multiple RUN lines
+# use the same FileCheck prefix and have the same output.
+
+RUN: cp %S/Inputs/replace-value-regex-across-runs.c %t.c
+RUN: %update_cc_test_checks %t.c \
+RUN: --replace-value-regex '__omp_offloading_[0-9a-z]+_[0-9a-z]+'
+RUN:
diff -u %S/Inputs/replace-value-regex-across-runs.c.expected %t.c
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 80b0c847080c..3f3682c5b9de 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -351,27 +351,6 @@ def process_run_line(self, function_re, scrubber, raw_tool_output, prefixes):
for l in scrubbed_body.splitlines():
print(' ' + l, file=sys.stderr)
for prefix in prefixes:
- if func in self._func_dict[prefix]:
- if (self._func_dict[prefix][func] is None or
- str(self._func_dict[prefix][func]) != scrubbed_body or
- self._func_dict[prefix][func].args_and_sig != args_and_sig or
- self._func_dict[prefix][func].attrs != attrs):
- if (self._func_dict[prefix][func] is not None and
- self._func_dict[prefix][func].is_same_except_arg_names(
- scrubbed_extra,
- args_and_sig,
- attrs)):
- self._func_dict[prefix][func].scrub = scrubbed_extra
- self._func_dict[prefix][func].args_and_sig = args_and_sig
- continue
- else:
- # This means a previous RUN line produced a body for this function
- # that is
diff erent from the one produced by this current RUN line,
- # so the body can't be common accross RUN lines. We use None to
- # indicate that.
- self._func_dict[prefix][func] = None
- continue
-
# Replace function names matching the regex.
for regex in self._replace_value_regex:
# Pattern that matches capture groups in the regex in leftmost order.
@@ -394,7 +373,29 @@ def process_run_line(self, function_re, scrubber, raw_tool_output, prefixes):
func_repl = group_regex.sub(re.escape(g), func_repl, count=1)
# Substitute function call names that match the regex with the same
# capture groups set.
- scrubbed_body = re.sub(func_repl, '{{' + func_repl + '}}', scrubbed_body)
+ scrubbed_body = re.sub(func_repl, '{{' + func_repl + '}}',
+ scrubbed_body)
+
+ if func in self._func_dict[prefix]:
+ if (self._func_dict[prefix][func] is None or
+ str(self._func_dict[prefix][func]) != scrubbed_body or
+ self._func_dict[prefix][func].args_and_sig != args_and_sig or
+ self._func_dict[prefix][func].attrs != attrs):
+ if (self._func_dict[prefix][func] is not None and
+ self._func_dict[prefix][func].is_same_except_arg_names(
+ scrubbed_extra,
+ args_and_sig,
+ attrs)):
+ self._func_dict[prefix][func].scrub = scrubbed_extra
+ self._func_dict[prefix][func].args_and_sig = args_and_sig
+ continue
+ else:
+ # This means a previous RUN line produced a body for this function
+ # that is
diff erent from the one produced by this current RUN line,
+ # so the body can't be common accross RUN lines. We use None to
+ # indicate that.
+ self._func_dict[prefix][func] = None
+ continue
self._func_dict[prefix][func] = function_body(
scrubbed_body, scrubbed_extra, args_and_sig, attrs)
More information about the cfe-commits
mailing list