[PATCH] D97107: Replace func name with regex in update_cc_test_checks

2021-03-12 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis updated this revision to Diff 330399.
ggeorgakoudis added a comment.

NFC change in update_llc_test_checks for compatibility


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97107

Files:
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
  clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
  llvm/utils/UpdateTestChecks/common.py
  llvm/utils/update_llc_test_checks.py

Index: llvm/utils/update_llc_test_checks.py
===
--- llvm/utils/update_llc_test_checks.py
+++ llvm/utils/update_llc_test_checks.py
@@ -109,7 +109,8 @@
 flags=type('', (object,), {
 'verbose': ti.args.verbose,
 'function_signature': False,
-'check_attributes': False}),
+'check_attributes': False,
+'replace_function_regex': []}),
 scrubber_args=[ti.args])
 
 for prefixes, llc_args, triple_in_cmd, march_in_cmd in run_list:
Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -30,6 +30,8 @@
help='Activate CHECK line generation from this point forward')
   parser.add_argument('--disable', action='store_false', dest='enabled',
   help='Deactivate CHECK line generation from this point forward')
+  parser.add_argument('--replace-function-regex', nargs='+', default=[],
+  help='List of regular expressions to replace matching function names')
   args = parser.parse_args()
   global _verbose
   _verbose = args.verbose
@@ -264,6 +266,8 @@
 self._record_args = flags.function_signature
 self._check_attributes = flags.check_attributes
 self._scrubber_args = scrubber_args
+# Strip double-quotes if input was read by UTC_ARGS
+self._replace_function_regex = list(map(lambda x: x.strip('"'), flags.replace_function_regex))
 self._func_dict = {}
 self._func_order = {}
 for tuple in run_list:
@@ -331,6 +335,30 @@
   self._func_dict[prefix][func] = None
   continue
 
+# Replace function names matching the regex.
+for regex in self._replace_function_regex:
+  # Pattern that matches capture groups in the regex in leftmost order.
+  group_regex = re.compile('\(.*?\)')
+  # Replace function name with regex.
+  match = re.match(regex, func)
+  if match:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+  func_repl = group_regex.sub(g, func_repl, count=1)
+func = '{{' + func_repl + '}}'
+
+  # Replace all calls to regex matching functions.
+  matches = re.finditer(regex, scrubbed_body)
+  for match in matches:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+func_repl = group_regex.sub(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)
+
 self._func_dict[prefix][func] = function_body(
 scrubbed_body, scrubbed_extra, args_and_sig, attrs)
 self._func_order[prefix].append(func)
@@ -633,6 +661,8 @@
   continue  # Don't add default values
 autogenerated_note_args += action.option_strings[0] + ' '
 if action.const is None:  # action takes a parameter
+  if action.nargs == '+':
+value = ' '.join(map(lambda v: '"' + v.strip('"') + '"', value))
   autogenerated_note_args += '%s ' % value
   if autogenerated_note_args:
 autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args[:-1])
Index: clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
@@ -0,0 +1,9 @@
+## Test that CHECK lines are generated for clang-generated functions replaced
+## by regex
+
+## RUN: cp %S/Inputs/generated-funcs-regex.c %t-generated-funcs-regex.c && %update_cc_test_checks --include-generated-funcs --replace-function-regex "__([a-z]+)_offloading_[a-z0-9]+_[a-z0-9]+_(.*)_l[0-9]+" -- %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
+
+## Check that re-running update_cc_test_checks doesn't change the output
+# RUN: %update_cc_test_checks %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected 

[PATCH] D97107: Replace func name with regex in update_cc_test_checks

2021-03-10 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis added a comment.

In D97107#2617897 , @thakis wrote:

> This breaks check-llvm on linux and mac:
> http://45.33.8.238/linux/41398/step_12.txt
> http://45.33.8.238/macm1/5291/step_10.txt
> http://lab.llvm.org:8011/#/builders/109
> (and on my local build too)
>
> Please take a look, and please revert for now if it takes a while to fix.

Reverted, I'm going to test better, fix and re-land.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97107

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97107: Replace func name with regex in update_cc_test_checks

2021-03-10 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This breaks check-llvm on linux and mac:
http://45.33.8.238/linux/41398/step_12.txt
http://45.33.8.238/macm1/5291/step_10.txt
http://lab.llvm.org:8011/#/builders/109
(and on my local build too)

Please take a look, and please revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97107

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97107: Replace func name with regex in update_cc_test_checks

2021-03-10 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbf58d6a1f922: Replace func name with regex in 
update_cc_test_checks (authored by ggeorgakoudis).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97107

Files:
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
  clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
  llvm/utils/UpdateTestChecks/common.py

Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -30,6 +30,8 @@
help='Activate CHECK line generation from this point forward')
   parser.add_argument('--disable', action='store_false', dest='enabled',
   help='Deactivate CHECK line generation from this point forward')
+  parser.add_argument('--replace-function-regex', nargs='+', default=[],
+  help='List of regular expressions to replace matching function names')
   args = parser.parse_args()
   global _verbose
   _verbose = args.verbose
@@ -264,6 +266,8 @@
 self._record_args = flags.function_signature
 self._check_attributes = flags.check_attributes
 self._scrubber_args = scrubber_args
+# Strip double-quotes if input was read by UTC_ARGS
+self._replace_function_regex = list(map(lambda x: x.strip('"'), flags.replace_function_regex))
 self._func_dict = {}
 self._func_order = {}
 for tuple in run_list:
@@ -331,6 +335,30 @@
   self._func_dict[prefix][func] = None
   continue
 
+# Replace function names matching the regex.
+for regex in self._replace_function_regex:
+  # Pattern that matches capture groups in the regex in leftmost order.
+  group_regex = re.compile('\(.*?\)')
+  # Replace function name with regex.
+  match = re.match(regex, func)
+  if match:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+  func_repl = group_regex.sub(g, func_repl, count=1)
+func = '{{' + func_repl + '}}'
+
+  # Replace all calls to regex matching functions.
+  matches = re.finditer(regex, scrubbed_body)
+  for match in matches:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+func_repl = group_regex.sub(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)
+
 self._func_dict[prefix][func] = function_body(
 scrubbed_body, scrubbed_extra, args_and_sig, attrs)
 self._func_order[prefix].append(func)
@@ -633,6 +661,8 @@
   continue  # Don't add default values
 autogenerated_note_args += action.option_strings[0] + ' '
 if action.const is None:  # action takes a parameter
+  if action.nargs == '+':
+value = ' '.join(map(lambda v: '"' + v.strip('"') + '"', value))
   autogenerated_note_args += '%s ' % value
   if autogenerated_note_args:
 autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args[:-1])
Index: clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
@@ -0,0 +1,9 @@
+## Test that CHECK lines are generated for clang-generated functions replaced
+## by regex
+
+## RUN: cp %S/Inputs/generated-funcs-regex.c %t-generated-funcs-regex.c && %update_cc_test_checks --include-generated-funcs --replace-function-regex "__([a-z]+)_offloading_[a-z0-9]+_[a-z0-9]+_(.*)_l[0-9]+" -- %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
+
+## Check that re-running update_cc_test_checks doesn't change the output
+# RUN: %update_cc_test_checks %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
Index: clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
@@ -0,0 +1,36 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --replace-function-regex "__([a-z]+)_offloading_[a-z0-9]+_[a-z0-9]+_(.*)_l[0-9]+"
+// RUN: 

[PATCH] D97107: Replace func name with regex in update_cc_test_checks

2021-03-10 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis updated this revision to Diff 329747.
ggeorgakoudis added a comment.

Add triple in test to avoid spurious failures


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97107

Files:
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
  clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
  llvm/utils/UpdateTestChecks/common.py

Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -30,6 +30,8 @@
help='Activate CHECK line generation from this point forward')
   parser.add_argument('--disable', action='store_false', dest='enabled',
   help='Deactivate CHECK line generation from this point forward')
+  parser.add_argument('--replace-function-regex', nargs='+', default=[],
+  help='List of regular expressions to replace matching function names')
   args = parser.parse_args()
   global _verbose
   _verbose = args.verbose
@@ -264,6 +266,8 @@
 self._record_args = flags.function_signature
 self._check_attributes = flags.check_attributes
 self._scrubber_args = scrubber_args
+# Strip double-quotes if input was read by UTC_ARGS
+self._replace_function_regex = list(map(lambda x: x.strip('"'), flags.replace_function_regex))
 self._func_dict = {}
 self._func_order = {}
 for tuple in run_list:
@@ -331,6 +335,30 @@
   self._func_dict[prefix][func] = None
   continue
 
+# Replace function names matching the regex.
+for regex in self._replace_function_regex:
+  # Pattern that matches capture groups in the regex in leftmost order.
+  group_regex = re.compile('\(.*?\)')
+  # Replace function name with regex.
+  match = re.match(regex, func)
+  if match:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+  func_repl = group_regex.sub(g, func_repl, count=1)
+func = '{{' + func_repl + '}}'
+
+  # Replace all calls to regex matching functions.
+  matches = re.finditer(regex, scrubbed_body)
+  for match in matches:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+func_repl = group_regex.sub(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)
+
 self._func_dict[prefix][func] = function_body(
 scrubbed_body, scrubbed_extra, args_and_sig, attrs)
 self._func_order[prefix].append(func)
@@ -633,6 +661,8 @@
   continue  # Don't add default values
 autogenerated_note_args += action.option_strings[0] + ' '
 if action.const is None:  # action takes a parameter
+  if action.nargs == '+':
+value = ' '.join(map(lambda v: '"' + v.strip('"') + '"', value))
   autogenerated_note_args += '%s ' % value
   if autogenerated_note_args:
 autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args[:-1])
Index: clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
@@ -0,0 +1,9 @@
+## Test that CHECK lines are generated for clang-generated functions replaced
+## by regex
+
+## RUN: cp %S/Inputs/generated-funcs-regex.c %t-generated-funcs-regex.c && %update_cc_test_checks --include-generated-funcs --replace-function-regex "__([a-z]+)_offloading_[a-z0-9]+_[a-z0-9]+_(.*)_l[0-9]+" -- %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
+
+## Check that re-running update_cc_test_checks doesn't change the output
+# RUN: %update_cc_test_checks %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
Index: clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
@@ -0,0 +1,36 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --replace-function-regex "__([a-z]+)_offloading_[a-z0-9]+_[a-z0-9]+_(.*)_l[0-9]+"
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp %s -emit-llvm -o - | FileCheck %s
+
+void 

[PATCH] D97107: Replace func name with regex in update_cc_test_checks

2021-03-08 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis updated this revision to Diff 329008.
ggeorgakoudis added a comment.

Change regex to avoid failing windows test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97107

Files:
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
  clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
  llvm/utils/UpdateTestChecks/common.py

Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -30,6 +30,8 @@
help='Activate CHECK line generation from this point forward')
   parser.add_argument('--disable', action='store_false', dest='enabled',
   help='Deactivate CHECK line generation from this point forward')
+  parser.add_argument('--replace-function-regex', nargs='+', default=[],
+  help='List of regular expressions to replace matching function names')
   args = parser.parse_args()
   global _verbose
   _verbose = args.verbose
@@ -264,6 +266,8 @@
 self._record_args = flags.function_signature
 self._check_attributes = flags.check_attributes
 self._scrubber_args = scrubber_args
+# Strip double-quotes if input was read by UTC_ARGS
+self._replace_function_regex = list(map(lambda x: x.strip('"'), flags.replace_function_regex))
 self._func_dict = {}
 self._func_order = {}
 for tuple in run_list:
@@ -331,6 +335,30 @@
   self._func_dict[prefix][func] = None
   continue
 
+# Replace function names matching the regex.
+for regex in self._replace_function_regex:
+  # Pattern that matches capture groups in the regex in leftmost order.
+  group_regex = re.compile('\(.*?\)')
+  # Replace function name with regex.
+  match = re.match(regex, func)
+  if match:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+  func_repl = group_regex.sub(g, func_repl, count=1)
+func = '{{' + func_repl + '}}'
+
+  # Replace all calls to regex matching functions.
+  matches = re.finditer(regex, scrubbed_body)
+  for match in matches:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+func_repl = group_regex.sub(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)
+
 self._func_dict[prefix][func] = function_body(
 scrubbed_body, scrubbed_extra, args_and_sig, attrs)
 self._func_order[prefix].append(func)
@@ -633,6 +661,8 @@
   continue  # Don't add default values
 autogenerated_note_args += action.option_strings[0] + ' '
 if action.const is None:  # action takes a parameter
+  if action.nargs == '+':
+value = ' '.join(map(lambda v: '"' + v.strip('"') + '"', value))
   autogenerated_note_args += '%s ' % value
   if autogenerated_note_args:
 autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args[:-1])
Index: clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
@@ -0,0 +1,9 @@
+## Test that CHECK lines are generated for clang-generated functions replaced
+## by regex
+
+## RUN: cp %S/Inputs/generated-funcs-regex.c %t-generated-funcs-regex.c && %update_cc_test_checks --include-generated-funcs --replace-function-regex "__([a-z]+)_offloading_[a-z0-9]+_[a-z0-9]+_(.*)_l[0-9]+" -- %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
+
+## Check that re-running update_cc_test_checks doesn't change the output
+# RUN: %update_cc_test_checks %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
Index: clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
@@ -0,0 +1,36 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --replace-function-regex "__([a-z]+)_offloading_[a-z0-9]+_[a-z0-9]+_(.*)_l[0-9]+"
+// RUN: %clang_cc1 -fopenmp %s -emit-llvm -o - | FileCheck %s
+
+void __test_offloading_42_abcdef_bar_l123();
+void use(int);
+

[PATCH] D97107: Replace func name with regex in update_cc_test_checks

2021-03-07 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis updated this revision to Diff 328845.
ggeorgakoudis added a comment.

Fix (another) for multiple capture groups


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97107

Files:
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
  clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
  llvm/utils/UpdateTestChecks/common.py

Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -30,6 +30,8 @@
help='Activate CHECK line generation from this point forward')
   parser.add_argument('--disable', action='store_false', dest='enabled',
   help='Deactivate CHECK line generation from this point forward')
+  parser.add_argument('--replace-function-regex', nargs='+', default=[],
+  help='List of regular expressions to replace matching function names')
   args = parser.parse_args()
   global _verbose
   _verbose = args.verbose
@@ -264,6 +266,8 @@
 self._record_args = flags.function_signature
 self._check_attributes = flags.check_attributes
 self._scrubber_args = scrubber_args
+# Strip double-quotes if input was read by UTC_ARGS
+self._replace_function_regex = list(map(lambda x: x.strip('"'), flags.replace_function_regex))
 self._func_dict = {}
 self._func_order = {}
 for tuple in run_list:
@@ -331,6 +335,30 @@
   self._func_dict[prefix][func] = None
   continue
 
+# Replace function names matching the regex.
+for regex in self._replace_function_regex:
+  # Pattern that matches capture groups in the regex in leftmost order.
+  group_regex = re.compile('\(.*?\)')
+  # Replace function name with regex.
+  match = re.match(regex, func)
+  if match:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+  func_repl = group_regex.sub(g, func_repl, count=1)
+func = '{{' + func_repl + '}}'
+
+  # Replace all calls to regex matching functions.
+  matches = re.finditer(regex, scrubbed_body)
+  for match in matches:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+func_repl = group_regex.sub(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)
+
 self._func_dict[prefix][func] = function_body(
 scrubbed_body, scrubbed_extra, args_and_sig, attrs)
 self._func_order[prefix].append(func)
@@ -633,6 +661,8 @@
   continue  # Don't add default values
 autogenerated_note_args += action.option_strings[0] + ' '
 if action.const is None:  # action takes a parameter
+  if action.nargs == '+':
+value = ' '.join(map(lambda v: '"' + v.strip('"') + '"', value))
   autogenerated_note_args += '%s ' % value
   if autogenerated_note_args:
 autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args[:-1])
Index: clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
@@ -0,0 +1,9 @@
+## Test that CHECK lines are generated for clang-generated functions replaced
+## by regex
+
+## RUN: cp %S/Inputs/generated-funcs-regex.c %t-generated-funcs-regex.c && %update_cc_test_checks --include-generated-funcs --replace-function-regex "__([a-z]+)_offloading_[0-9]+_[a-z0-9]+_(.*)_l[0-9]+" -- %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
+
+## Check that re-running update_cc_test_checks doesn't change the output
+# RUN: %update_cc_test_checks %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
Index: clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
@@ -0,0 +1,36 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --replace-function-regex "__([a-z]+)_offloading_[0-9]+_[a-z0-9]+_(.*)_l[0-9]+"
+// RUN: %clang_cc1 -fopenmp %s -emit-llvm -o - | FileCheck %s
+
+void __test_offloading_42_abcdef_bar_l123();
+void use(int);
+
+void 

[PATCH] D97107: Replace func name with regex in update_cc_test_checks

2021-03-06 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis updated this revision to Diff 328824.
ggeorgakoudis added a comment.

Fix for multiple capture groups


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97107

Files:
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
  clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
  llvm/utils/UpdateTestChecks/common.py

Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -30,6 +30,8 @@
help='Activate CHECK line generation from this point forward')
   parser.add_argument('--disable', action='store_false', dest='enabled',
   help='Deactivate CHECK line generation from this point forward')
+  parser.add_argument('--replace-function-regex', nargs='+', default=[],
+  help='List of regular expressions to replace matching function names')
   args = parser.parse_args()
   global _verbose
   _verbose = args.verbose
@@ -264,6 +266,8 @@
 self._record_args = flags.function_signature
 self._check_attributes = flags.check_attributes
 self._scrubber_args = scrubber_args
+# Strip double-quotes if input was read by UTC_ARGS
+self._replace_function_regex = list(map(lambda x: x.strip('"'), flags.replace_function_regex))
 self._func_dict = {}
 self._func_order = {}
 for tuple in run_list:
@@ -331,6 +335,30 @@
   self._func_dict[prefix][func] = None
   continue
 
+# Replace function names matching the regex.
+for regex in self._replace_function_regex:
+  # Pattern that matches capture groups in the regex in leftmost order.
+  group_regex = re.compile('\(.*?\)')
+  # Replace function name with regex.
+  match = re.match(regex, func)
+  if match:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+  func_repl = group_regex.sub(g, func_repl, count=1)
+func = '{{' + func_repl + '}}'
+
+  # Replace all calls to regex matching functions.
+  matches = re.findall(regex, scrubbed_body)
+  for groups in matches:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in groups:
+func_repl = group_regex.sub(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)
+
 self._func_dict[prefix][func] = function_body(
 scrubbed_body, scrubbed_extra, args_and_sig, attrs)
 self._func_order[prefix].append(func)
@@ -633,6 +661,8 @@
   continue  # Don't add default values
 autogenerated_note_args += action.option_strings[0] + ' '
 if action.const is None:  # action takes a parameter
+  if action.nargs == '+':
+value = ' '.join(map(lambda v: '"' + v.strip('"') + '"', value))
   autogenerated_note_args += '%s ' % value
   if autogenerated_note_args:
 autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args[:-1])
Index: clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
@@ -0,0 +1,9 @@
+## Test that CHECK lines are generated for clang-generated functions replaced
+## by regex
+
+## RUN: cp %S/Inputs/generated-funcs-regex.c %t-generated-funcs-regex.c && %update_cc_test_checks --include-generated-funcs --replace-function-regex "__([a-z]+)_offloading_[0-9]+_[a-z0-9]+_(.*)_l[0-9]+" -- %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
+
+## Check that re-running update_cc_test_checks doesn't change the output
+# RUN: %update_cc_test_checks %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
Index: clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
@@ -0,0 +1,36 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --replace-function-regex "__([a-z]+)_offloading_[0-9]+_[a-z0-9]+_(.*)_l[0-9]+"
+// RUN: %clang_cc1 -fopenmp %s -emit-llvm -o - | FileCheck %s
+
+void __test_offloading_42_abcdef_bar_l123();
+void use(int);
+
+void foo(int a)
+{
+

[PATCH] D97107: Replace func name with regex in update_cc_test_checks

2021-03-06 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

Cool, almost able to generate offloading tests :) LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97107

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97107: Replace func name with regex in update_cc_test_checks

2021-03-06 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis updated this revision to Diff 328823.
ggeorgakoudis added a comment.

Remove testing print


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97107

Files:
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
  clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
  llvm/utils/UpdateTestChecks/common.py

Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -30,6 +30,8 @@
help='Activate CHECK line generation from this point forward')
   parser.add_argument('--disable', action='store_false', dest='enabled',
   help='Deactivate CHECK line generation from this point forward')
+  parser.add_argument('--replace-function-regex', nargs='+', default=[],
+  help='List of regular expressions to replace matching function names')
   args = parser.parse_args()
   global _verbose
   _verbose = args.verbose
@@ -264,6 +266,8 @@
 self._record_args = flags.function_signature
 self._check_attributes = flags.check_attributes
 self._scrubber_args = scrubber_args
+# Strip double-quotes if input was read by UTC_ARGS
+self._replace_function_regex = list(map(lambda x: x.strip('"'), flags.replace_function_regex))
 self._func_dict = {}
 self._func_order = {}
 for tuple in run_list:
@@ -331,6 +335,29 @@
   self._func_dict[prefix][func] = None
   continue
 
+# Replace function names matching the regex.
+for regex in self._replace_function_regex:
+  # Pattern that matches capture groups in the regex in leftmost order.
+  group_regex = re.compile('\(.*?\)')
+  # Replace function name with regex.
+  match = re.match(regex, func)
+  if match:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+  func_repl = group_regex.sub(g, func_repl, count=1)
+func = '{{' + func_repl + '}}'
+
+  # Replace all calls to regex matching functions.
+  matches = re.findall(regex, scrubbed_body)
+  for found in matches:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+func_repl = group_regex.sub(found, 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)
+
 self._func_dict[prefix][func] = function_body(
 scrubbed_body, scrubbed_extra, args_and_sig, attrs)
 self._func_order[prefix].append(func)
@@ -633,6 +660,8 @@
   continue  # Don't add default values
 autogenerated_note_args += action.option_strings[0] + ' '
 if action.const is None:  # action takes a parameter
+  if action.nargs == '+':
+value = ' '.join(map(lambda v: '"' + v.strip('"') + '"', value))
   autogenerated_note_args += '%s ' % value
   if autogenerated_note_args:
 autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args[:-1])
Index: clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
@@ -0,0 +1,9 @@
+## Test that CHECK lines are generated for clang-generated functions replaced
+## by regex
+
+## RUN: cp %S/Inputs/generated-funcs-regex.c %t-generated-funcs-regex.c && %update_cc_test_checks --include-generated-funcs --replace-function-regex "__omp_offloading_[0-9]+_[a-z0-9]+_(.*)_l[0-9]+" -- %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
+
+## Check that re-running update_cc_test_checks doesn't change the output
+# RUN: %update_cc_test_checks %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
Index: clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
@@ -0,0 +1,32 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --replace-function-regex "__omp_offloading_[0-9]+_[a-z0-9]+_(.*)_l[0-9]+"
+// RUN: %clang_cc1 -fopenmp %s -emit-llvm -o - | FileCheck %s
+
+void use(int);
+
+void foo(int a)
+{
+#pragma omp target
+use(a);
+}
+// CHECK-LABEL: @foo(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT: 

[PATCH] D97107: Replace func name with regex in update_cc_test_checks

2021-03-06 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis updated this revision to Diff 328810.
ggeorgakoudis added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Move implementation in common, add tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97107

Files:
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
  clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
  llvm/utils/UpdateTestChecks/common.py

Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -30,6 +30,8 @@
help='Activate CHECK line generation from this point forward')
   parser.add_argument('--disable', action='store_false', dest='enabled',
   help='Deactivate CHECK line generation from this point forward')
+  parser.add_argument('--replace-function-regex', nargs='+', default=[],
+  help='List of regular expressions to replace matching function names')
   args = parser.parse_args()
   global _verbose
   _verbose = args.verbose
@@ -264,6 +266,8 @@
 self._record_args = flags.function_signature
 self._check_attributes = flags.check_attributes
 self._scrubber_args = scrubber_args
+# Strip double-quotes if input was read by UTC_ARGS
+self._replace_function_regex = list(map(lambda x: x.strip('"'), flags.replace_function_regex))
 self._func_dict = {}
 self._func_order = {}
 for tuple in run_list:
@@ -331,6 +335,30 @@
   self._func_dict[prefix][func] = None
   continue
 
+# Replace function names matching the regex.
+for regex in self._replace_function_regex:
+  # Pattern that matches capture groups in the regex in leftmost order.
+  group_regex = re.compile('\(.*?\)')
+  # Replace function name with regex.
+  match = re.match(regex, func)
+  if match:
+func_repl = regex
+# Replace any capture groups with their matched strings.
+for g in match.groups():
+  func_repl = group_regex.sub(g, func_repl, count=1)
+func = '{{' + func_repl + '}}'
+
+  # Replace all calls to regex matching functions.
+  matches = re.findall(regex, scrubbed_body)
+  for found in matches:
+print('found', found)
+func_repl = regex
+# Replace any capture groups with their matched strings.
+func_repl = group_regex.sub(found, 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)
+
 self._func_dict[prefix][func] = function_body(
 scrubbed_body, scrubbed_extra, args_and_sig, attrs)
 self._func_order[prefix].append(func)
@@ -633,6 +661,8 @@
   continue  # Don't add default values
 autogenerated_note_args += action.option_strings[0] + ' '
 if action.const is None:  # action takes a parameter
+  if action.nargs == '+':
+value = ' '.join(map(lambda v: '"' + v.strip('"') + '"', value))
   autogenerated_note_args += '%s ' % value
   if autogenerated_note_args:
 autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args[:-1])
Index: clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/generated-funcs-regex.test
@@ -0,0 +1,9 @@
+## Test that CHECK lines are generated for clang-generated functions replaced
+## by regex
+
+## RUN: cp %S/Inputs/generated-funcs-regex.c %t-generated-funcs-regex.c && %update_cc_test_checks --include-generated-funcs --replace-function-regex "__omp_offloading_[0-9]+_[a-z0-9]+_(.*)_l[0-9]+" -- %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
+
+## Check that re-running update_cc_test_checks doesn't change the output
+# RUN: %update_cc_test_checks %t-generated-funcs-regex.c
+# RUN: diff -u %S/Inputs/generated-funcs-regex.c.expected %t-generated-funcs-regex.c
Index: clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
@@ -0,0 +1,32 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --replace-function-regex "__omp_offloading_[0-9]+_[a-z0-9]+_(.*)_l[0-9]+"
+// RUN: %clang_cc1 -fopenmp %s -emit-llvm -o - | FileCheck %s
+
+void use(int);
+