Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/NVPTX/wmma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/opt-viewer/opt-viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/DSAclean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/DSAextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/add_argument_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/convert-constraint-log-to-z3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/extract_vplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions llvm/utils/git/github-automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/indirect_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/relative_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use raw string here as well if you replace the existing \\ with \?

"""

import argparse
Expand Down
10 changes: 5 additions & 5 deletions llvm/utils/update_test_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to use raw strings here as well. \n is both a python and regex escape sequence, and there's no need to use the python one here, if it makes things less similar to other places.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
s = re.sub("\\s+-?-check-prefix=" + p + "([ \n])", "\\1", s)
s = re.sub(r"\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
Copy link
Contributor

@nikic nikic Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"-?-check-prefixes=([\\w-]+)(\\Z|[ \t\n])", "--check-prefix=\\1\\2", s
r"-?-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:
s = re.sub(
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
s = re.sub("\\s+-?-check-prefix=CHECK[ \t]*\n", "\n", s)
s = re.sub(r"\s+-?-check-prefix=CHECK[ \t]*\n", "\n", s)

f.truncate(0)
f.seek(0)
f.write(s)
Expand Down
Loading