[llvm] fix(llvm/**.py): fix invalid escape sequences (PR #94035)

Eisuke Kawashima via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 10 15:24:15 PST 2024


https://github.com/e-kwsm updated https://github.com/llvm/llvm-project/pull/94035

>From fefa226091ebc173604786154655d6d1c841f861 Mon Sep 17 00:00:00 2001
From: Eisuke Kawashima <e-kwsm at users.noreply.github.com>
Date: Sat, 11 May 2024 02:39:21 +0900
Subject: [PATCH] fix(llvm/**.py): fix invalid escape sequences

---
 llvm/test/CodeGen/NVPTX/wmma.py            |  2 +-
 llvm/tools/opt-viewer/opt-viewer.py        |  2 +-
 llvm/utils/DSAclean.py                     |  2 +-
 llvm/utils/DSAextract.py                   |  4 ++--
 llvm/utils/add_argument_names.py           |  2 +-
 llvm/utils/convert-constraint-log-to-z3.py |  2 +-
 llvm/utils/extract_symbols.py              | 24 +++++++++++-----------
 llvm/utils/extract_vplan.py                |  2 +-
 llvm/utils/git/github-automation.py        |  6 +++---
 llvm/utils/indirect_calls.py               |  2 +-
 llvm/utils/relative_lines.py               |  4 ++--
 llvm/utils/update_test_prefix.py           | 10 ++++-----
 12 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/llvm/test/CodeGen/NVPTX/wmma.py b/llvm/test/CodeGen/NVPTX/wmma.py
index e1e46f0b8cab34..8f6378e3ce3cc1 100644
--- a/llvm/test/CodeGen/NVPTX/wmma.py
+++ b/llvm/test/CodeGen/NVPTX/wmma.py
@@ -847,7 +847,7 @@ def gen_check_unsupported_ops(items):
     )
     print("; INTRINSICS: {{^; INTRINSICS_LIST_BEGIN}}")
     print(
-        """
+        r"""
 
 ; NOEXTGEOM-NOT: {{m8n32|m32n8}}
 ; NOINT-NOT: .{{s32|s8}}
diff --git a/llvm/tools/opt-viewer/opt-viewer.py b/llvm/tools/opt-viewer/opt-viewer.py
index c9c7db726f7652..2d32d66bbe3aee 100755
--- a/llvm/tools/opt-viewer/opt-viewer.py
+++ b/llvm/tools/opt-viewer/opt-viewer.py
@@ -135,7 +135,7 @@ def render_inline_remarks(self, r, line):
         # Column is the number of characters *including* tabs, keep those and
         # replace everything else with spaces.
         indent = line[: max(r.Column, 1) - 1]
-        indent = re.sub("\S", " ", indent)
+        indent = re.sub(r"\S", " ", indent)
 
         # Create expanded message and link if we have a multiline message.
         lines = r.message.split("\n")
diff --git a/llvm/utils/DSAclean.py b/llvm/utils/DSAclean.py
index 1b833ff8932483..6937ca9e614f56 100755
--- a/llvm/utils/DSAclean.py
+++ b/llvm/utils/DSAclean.py
@@ -24,7 +24,7 @@
 # it would kill old computers
 buffer = input.readline()
 while buffer != "":
-    if re.compile('label(\s*)=(\s*)"\s%tmp(.\w*)*(\s*)"').search(buffer):
+    if re.compile(r'label(\s*)=(\s*)"\s%tmp(.\w*)*(\s*)"').search(buffer):
         # skip next line, write neither this line nor the next
         buffer = input.readline()
     else:
diff --git a/llvm/utils/DSAextract.py b/llvm/utils/DSAextract.py
index 96f818bd2a8316..9787922e5f6742 100755
--- a/llvm/utils/DSAextract.py
+++ b/llvm/utils/DSAextract.py
@@ -69,7 +69,7 @@
             # if this name is for the current node, add the dot variable name
             # for the node (it will be Node(hex number)) to our set of nodes
             if regexp.search(buffer):
-                node_set |= set([re.split("\s+", buffer, 2)[1]])
+                node_set |= set([re.split(r"\s+", buffer, 2)[1]])
                 break
     buffer = input.readline()
 
@@ -105,7 +105,7 @@
         if nodes[0][:13] in node_set and nodes[1][:13] in node_set:
             output.write(buffer)
     elif nodeexp.search(buffer):  # this is a node line
-        node = re.split("\s+", buffer, 2)[1]
+        node = re.split(r"\s+", buffer, 2)[1]
         if node in node_set:
             output.write(buffer)
     else:  # this is a support line
diff --git a/llvm/utils/add_argument_names.py b/llvm/utils/add_argument_names.py
index 2860dd4b90bcb5..af2f1297d9ee7f 100755
--- a/llvm/utils/add_argument_names.py
+++ b/llvm/utils/add_argument_names.py
@@ -4,7 +4,7 @@
 
 def fix_string(s):
     TYPE = re.compile(
-        '\s*(i[0-9]+|float|double|x86_fp80|fp128|ppc_fp128|\[\[.*?\]\]|\[2 x \[\[[A-Z_0-9]+\]\]\]|<.*?>|{.*?}|\[[0-9]+ x .*?\]|%["a-z:A-Z0-9._]+({{.*?}})?|%{{.*?}}|{{.*?}}|\[\[.*?\]\])(\s*(\*|addrspace\(.*?\)|dereferenceable\(.*?\)|byval\(.*?\)|sret|zeroext|inreg|returned|signext|nocapture|align \d+|swiftself|swifterror|readonly|noalias|inalloca|nocapture))*\s*'
+        r'\s*(i[0-9]+|float|double|x86_fp80|fp128|ppc_fp128|\[\[.*?\]\]|\[2 x \[\[[A-Z_0-9]+\]\]\]|<.*?>|{.*?}|\[[0-9]+ x .*?\]|%["a-z:A-Z0-9._]+({{.*?}})?|%{{.*?}}|{{.*?}}|\[\[.*?\]\])(\s*(\*|addrspace\(.*?\)|dereferenceable\(.*?\)|byval\(.*?\)|sret|zeroext|inreg|returned|signext|nocapture|align \d+|swiftself|swifterror|readonly|noalias|inalloca|nocapture))*\s*'
     )
 
     counter = 0
diff --git a/llvm/utils/convert-constraint-log-to-z3.py b/llvm/utils/convert-constraint-log-to-z3.py
index a3c33f2ef45996..f96ac3106f68b4 100755
--- a/llvm/utils/convert-constraint-log-to-z3.py
+++ b/llvm/utils/convert-constraint-log-to-z3.py
@@ -46,7 +46,7 @@ def main():
         content = f.read()
 
     groups = content.split("---")
-    var_re = re.compile("x\d+")
+    var_re = re.compile(r"x\d+")
 
     print("from z3 import *")
     for group in groups:
diff --git a/llvm/utils/extract_symbols.py b/llvm/utils/extract_symbols.py
index 684e124c762594..eccbc496699fee 100755
--- a/llvm/utils/extract_symbols.py
+++ b/llvm/utils/extract_symbols.py
@@ -53,12 +53,12 @@ def nm_get_symbols(tool, lib):
         # The -P flag displays the size field for symbols only when applicable,
         # so the last field is optional. There's no space after the value field,
         # but \s+ match newline also, so \s+\S* will match the optional size field.
-        match = re.match("^(\S+)\s+[BDGRSTuVW]\s+\S+\s+\S*$", line)
+        match = re.match(r"^(\S+)\s+[BDGRSTuVW]\s+\S+\s+\S*$", line)
         if match:
             yield (match.group(1), True)
         # Look for undefined symbols, which have type U and may or may not
         # (depending on which nm is being used) have value and size.
-        match = re.match("^(\S+)\s+U\s+(\S+\s+\S*)?$", line)
+        match = re.match(r"^(\S+)\s+U\s+(\S+\s+\S*)?$", line)
         if match:
             yield (match.group(1), False)
     process.wait()
@@ -71,7 +71,7 @@ def readobj_is_32bit_windows(tool, lib):
         [tool, "--file-header", lib], universal_newlines=True
     )
     for line in output.splitlines():
-        match = re.match("Format: (\S+)", line)
+        match = re.match(r"Format: (\S+)", line)
         if match:
             return match.group(1) == "COFF-i386"
     return False
@@ -100,10 +100,10 @@ def should_keep_microsoft_symbol(symbol, calling_convention_decoration):
     # An anonymous namespace is mangled as ?A(maybe hex number)@. Any symbol
     # that mentions an anonymous namespace can be discarded, as the anonymous
     # namespace doesn't exist outside of that translation unit.
-    elif re.search("\?A(0x\w+)?@", symbol):
+    elif re.search(r"\?A(0x\w+)?@", symbol):
         return None
     # Skip X86GenMnemonicTables functions, they are not exposed from llvm/include/.
-    elif re.match("\?is[A-Z0-9]*@X86 at llvm", symbol):
+    elif re.match(r"\?is[A-Z0-9]*@X86 at llvm", symbol):
         return None
     # Keep mangled llvm:: and clang:: function symbols. How we detect these is a
     # bit of a mess and imprecise, but that avoids having to completely demangle
@@ -140,7 +140,7 @@ def should_keep_itanium_symbol(symbol, calling_convention_decoration):
     if not symbol.startswith("_") and not symbol.startswith("."):
         return symbol
     # Discard manglings that aren't nested names
-    match = re.match("\.?_Z(T[VTIS])?(N.+)", symbol)
+    match = re.match(r"\.?_Z(T[VTIS])?(N.+)", symbol)
     if not match:
         return None
     # Demangle the name. If the name is too complex then we don't need to keep
@@ -169,7 +169,7 @@ class TooComplexName(Exception):
 # (name, rest of string) pair.
 def parse_itanium_name(arg):
     # Check for a normal name
-    match = re.match("(\d+)(.+)", arg)
+    match = re.match(r"(\d+)(.+)", arg)
     if match:
         n = int(match.group(1))
         name = match.group(1) + match.group(2)[:n]
@@ -196,7 +196,7 @@ def skip_itanium_template(arg):
     tmp = arg[1:]
     while tmp:
         # Check for names
-        match = re.match("(\d+)(.+)", tmp)
+        match = re.match(r"(\d+)(.+)", tmp)
         if match:
             n = int(match.group(1))
             tmp = match.group(2)[n:]
@@ -280,19 +280,19 @@ def parse_microsoft_mangling(arg):
         if arg.startswith("@"):
             return components
         # Check for a simple name
-        match = re.match("(\w+)@(.+)", arg)
+        match = re.match(r"(\w+)@(.+)", arg)
         if match:
             components.append((match.group(1), False))
             arg = match.group(2)
             continue
         # Check for a special function name
-        match = re.match("(\?_?\w)(.+)", arg)
+        match = re.match(r"(\?_?\w)(.+)", arg)
         if match:
             components.append((match.group(1), False))
             arg = match.group(2)
             continue
         # Check for a template name
-        match = re.match("\?\$(\w+)@[^@]+@(.+)", arg)
+        match = re.match(r"\?\$(\w+)@[^@]+@(.+)", arg)
         if match:
             components.append((match.group(1), True))
             arg = match.group(2)
@@ -323,7 +323,7 @@ def get_template_name(sym, mangling):
         if mangling == "microsoft":
             names = parse_microsoft_mangling(sym)
         else:
-            match = re.match("\.?_Z(T[VTIS])?(N.+)", sym)
+            match = re.match(r"\.?_Z(T[VTIS])?(N.+)", sym)
             if match:
                 names, _ = parse_itanium_nested_name(match.group(2))
             else:
diff --git a/llvm/utils/extract_vplan.py b/llvm/utils/extract_vplan.py
index cff6f5074d7716..96b9fd1b9a936b 100755
--- a/llvm/utils/extract_vplan.py
+++ b/llvm/utils/extract_vplan.py
@@ -24,7 +24,7 @@
 matches = re.findall(pattern, sys.stdin.read())
 
 for vplan in matches:
-    m = re.search("graph \[.+(VF=.+,UF.+)", vplan)
+    m = re.search(r"graph \[.+(VF=.+,UF.+)", vplan)
     if not m:
         raise ValueError("Can't get the right VPlan name")
     name = re.sub("[^a-zA-Z0-9]", "", m.group(1))
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index da467f46b4dd31..ef6032c524c285 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -53,9 +53,9 @@ def escape_description(str):
     # https://github.com/github/markup/issues/1168#issuecomment-494946168
     str = html.escape(str, False)
     # '@' followed by alphanum is a user name
-    str = re.sub("@(?=\w)", "@<!-- -->", str)
+    str = re.sub(r"@(?=\w)", "@<!-- -->", str)
     # '#' followed by digits is considered an issue number
-    str = re.sub("#(?=\d)", "#<!-- -->", str)
+    str = re.sub(r"#(?=\d)", "#<!-- -->", str)
     return str
 
 
@@ -474,7 +474,7 @@ def issue_remove_cherry_pick_failed_label(self):
     def get_main_commit(self, cherry_pick_sha: str) -> github.Commit.Commit:
         commit = self.repo.get_commit(cherry_pick_sha)
         message = commit.commit.message
-        m = re.search("\(cherry picked from commit ([0-9a-f]+)\)", message)
+        m = re.search(r"\(cherry picked from commit ([0-9a-f]+)\)", message)
         if not m:
             return None
         return self.repo.get_commit(m.group(1))
diff --git a/llvm/utils/indirect_calls.py b/llvm/utils/indirect_calls.py
index c18cffb26e7ae2..0c123cc143ab1a 100755
--- a/llvm/utils/indirect_calls.py
+++ b/llvm/utils/indirect_calls.py
@@ -33,7 +33,7 @@ def look_for_indirect(file):
     for line in stdout.splitlines():
         if not line.startswith(" "):
             function = line
-        result = re.search("(call|jmp).*\*", line)
+        result = re.search(r"(call|jmp).*\*", line)
         if result is not None:
             # TODO: Perhaps use cxxfilt to demangle functions?
             print(function)
diff --git a/llvm/utils/relative_lines.py b/llvm/utils/relative_lines.py
index 86b190d5ea1824..d4c2d9d0429b90 100755
--- a/llvm/utils/relative_lines.py
+++ b/llvm/utils/relative_lines.py
@@ -17,8 +17,8 @@
 USAGE = """Example usage:
     find -type f clang/test/CodeCompletion | grep -v /Inputs/ | \\
     xargs relative_lines.py --dry-run --verbose --near=100 \\
-    --pattern='-code-completion-at[ =]%s:(\d+)' \\
-    --pattern='requires fix-it: {(\d+):\d+-(\d+):\d+}'
+    --pattern='-code-completion-at[ =]%s:(\\d+)' \\
+    --pattern='requires fix-it: {(\\d+):\\d+-(\\d+):\\d+}'
 """
 
 import argparse
diff --git a/llvm/utils/update_test_prefix.py b/llvm/utils/update_test_prefix.py
index 434dc84fa4fc03..d11f2ae43abc43 100755
--- a/llvm/utils/update_test_prefix.py
+++ b/llvm/utils/update_test_prefix.py
@@ -17,13 +17,13 @@ def remove_prefix(i, d=0):
             p = r.group(1)
             s = re.sub("=" + p + ",", "=", s)
             s = re.sub("," + p + "([, \n])", "\\1", s)
-            s = re.sub("\s+-?-check-prefix=" + p + "([ \n])", "\\1", s)
+            s = re.sub("\\s+-?-check-prefix=" + p + "([ \n])", "\\1", s)
         else:
             s = re.sub(
-                "-?-check-prefixes=([\w-]+)(\Z|[ \t\n])", "--check-prefix=\\1\\2", s
+                "-?-check-prefixes=([\\w-]+)(\\Z|[ \t\n])", "--check-prefix=\\1\\2", s
             )
             t = re.search(
-                "-?-check-(?:prefix|prefixes)=([^ ]+)\s+-?-check-(?:prefix|prefixes)=([^ ]+)",
+                r"-?-check-(?:prefix|prefixes)=([^ ]+)\s+-?-check-(?:prefix|prefixes)=([^ ]+)",
                 s,
             )
             while t:
@@ -31,10 +31,10 @@ def remove_prefix(i, d=0):
                     t.group(), "--check-prefixes=" + t.group(1) + "," + t.group(2), s
                 )
                 t = re.search(
-                    "-?-check-(?:prefix|prefixes)=([^ ]+)\s+-?-check-(?:prefix|prefixes)=([^ ]+)",
+                    r"-?-check-(?:prefix|prefixes)=([^ ]+)\s+-?-check-(?:prefix|prefixes)=([^ ]+)",
                     s,
                 )
-            s = re.sub("\s+-?-check-prefix=CHECK[ \t]*\n", "\n", s)
+            s = re.sub("\\s+-?-check-prefix=CHECK[ \t]*\n", "\n", s)
         f.truncate(0)
         f.seek(0)
         f.write(s)



More information about the llvm-commits mailing list