[llvm] bfdc255 - [utils] change update_test_checks.py use of 'TMP' value names

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Sun May 31 07:48:17 PDT 2020


Author: Sanjay Patel
Date: 2020-05-31T10:46:11-04:00
New Revision: bfdc2552664d6f0bb332a9c6a115877020f3c1df

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

LOG: [utils] change update_test_checks.py use of 'TMP' value names

As discussed in PR45951:
https://bugs.llvm.org/show_bug.cgi?id=45951

There's a potential name collision between update_test_checks.py and -instnamer
and/or manually-generated IR test files because all of them try to use the
variable name that should never be used: "tmp".

This patch proposes to reduce the odds of collision and adds a warning if we
detect the problem. This will cause regression test churn when regenerating
CHECK lines on existing files.

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

Added: 
    

Modified: 
    llvm/utils/UpdateTestChecks/common.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index a3fca4905f3d..a2e9787253c5 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -218,10 +218,12 @@ def build_function_body_dictionary(function_re, scrubber, scrubber_args, raw_too
 # spaces, commas, paren, or end of the string
 IR_VALUE_RE = re.compile(r'(\s+)%([\w.-]+?)([,\s\(\)]|\Z)')
 
+NAMELESS_PREFIX = "NAMELESS"
+
 # Create a FileCheck variable name based on an IR name.
 def get_value_name(var):
   if var.isdigit():
-    var = 'TMP' + var
+    var = NAMELESS_PREFIX + var
   var = var.replace('.', '_')
   var = var.replace('-', '_')
   return var.upper()
@@ -243,6 +245,8 @@ def genericize_check_lines(lines, is_analyze, vars_seen):
   # into defs, and variables we have seen into uses.
   def transform_line_vars(match):
     var = match.group(2)
+    if NAMELESS_PREFIX.lower() in var.lower():
+      warn("Change IR value name '%s' to prevent possible conflict with scripted FileCheck name." % (var,))
     if var in vars_seen:
       rv = get_value_use(var)
     else:


        


More information about the llvm-commits mailing list