[Mlir-commits] [clang] [clang-tools-extra] [compiler-rt] [libcxx] [lld] [lldb] [llvm] [mlir] Fix SyntaxWarning messages from python 3.12 (PR #86806)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Mar 27 07:29:51 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
@llvm/pr-subscribers-clang-tidy
@llvm/pr-subscribers-lldb
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-mlir

Author: None (AngryLoki)

<details>
<summary>Changes</summary>

This fixes "SyntaxWarning: invalid escape sequence" and "SyntaxWarning: "is" with 'int' literal", except for polly and summarizeStats.py, which won't run on Python 3.

The fix is done in every file, because otherwise with OS-wide Python 3.12 these SyntaxWarnings appear here and there, as Python 3.12 [now produce a SyntaxWarning](https://docs.python.org/3/whatsnew/3.12.html#other-language-changes) instead of DeprecationWarning.

There are no warnings anymore, which can be checked with `python -m compileall -x "polly|summarizeStats.py" -d . -f -q .`

---

Patch is 128.29 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/86806.diff


106 Files Affected:

- (modified) .github/workflows/version-check.py (+1-1) 
- (modified) clang-tools-extra/clang-tidy/add_new_check.py (+6-6) 
- (modified) clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py (+2-2) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py (+1-1) 
- (modified) clang/docs/tools/dump_ast_matchers.py (+2-2) 
- (modified) clang/test/Analysis/check-analyzer-fixit.py (+1-1) 
- (modified) clang/utils/ABITest/TypeGen.py (+1-1) 
- (modified) compiler-rt/lib/asan/scripts/asan_symbolize.py (+2-2) 
- (modified) cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py (+2-2) 
- (modified) cross-project-tests/lit.cfg.py (+3-3) 
- (modified) libcxx/test/libcxx/transitive_includes.gen.py (+1-1) 
- (modified) libcxx/utils/generate_escaped_output_table.py (+1-1) 
- (modified) libcxx/utils/generate_width_estimation_table.py (+1-1) 
- (modified) lld/test/MachO/tools/validate-unwind-info.py (+1-1) 
- (modified) lld/utils/benchmark.py (+1-1) 
- (modified) lldb/examples/python/crashlog.py (+4-4) 
- (modified) lldb/examples/python/delta.py (+1-1) 
- (modified) lldb/examples/python/gdbremote.py (+5-5) 
- (modified) lldb/examples/python/jump.py (+3-3) 
- (modified) lldb/examples/python/performance.py (+1-1) 
- (modified) lldb/examples/python/symbolication.py (+4-4) 
- (modified) lldb/packages/Python/lldbsuite/test/decorators.py (+1-1) 
- (modified) lldb/packages/Python/lldbsuite/test/lldbpexpect.py (+1-1) 
- (modified) lldb/packages/Python/lldbsuite/test/lldbtest.py (+1-1) 
- (modified) lldb/packages/Python/lldbsuite/test/test_runner/process_control.py (+1-1) 
- (modified) lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py (+2-2) 
- (modified) lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py (+1-1) 
- (modified) lldb/test/API/commands/command/backticks/TestBackticksInAlias.py (+2-2) 
- (modified) lldb/test/API/commands/expression/memory-allocation/TestMemoryAllocSettings.py (+1-1) 
- (modified) lldb/test/API/commands/expression/test/TestExprs.py (+1-1) 
- (modified) lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py (+1-1) 
- (modified) lldb/test/API/commands/help/TestHelp.py (+3-3) 
- (modified) lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py (+1-1) 
- (modified) lldb/test/API/commands/register/register/TestRegistersUnavailable.py (+2-2) 
- (modified) lldb/test/API/commands/settings/TestSettings.py (+6-6) 
- (modified) lldb/test/API/commands/target/basic/TestTargetCommand.py (+1-1) 
- (modified) lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py (+10-10) 
- (modified) lldb/test/API/commands/target/dump-separate-debug-info/oso/TestDumpOso.py (+11-11) 
- (modified) lldb/test/API/commands/trace/TestTraceDumpInfo.py (+1-1) 
- (modified) lldb/test/API/commands/trace/TestTraceEvents.py (+2-2) 
- (modified) lldb/test/API/commands/trace/TestTraceStartStop.py (+6-6) 
- (modified) lldb/test/API/commands/trace/TestTraceTSC.py (+5-5) 
- (modified) lldb/test/API/driver/quit_speed/TestQuitWithProcess.py (+1-1) 
- (modified) lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py (+1-1) 
- (modified) lldb/test/API/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py (+2-2) 
- (modified) lldb/test/API/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py (+3-3) 
- (modified) lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py (+3-3) 
- (modified) lldb/test/API/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSContainer.py (+8-8) 
- (modified) lldb/test/API/functionalities/data-formatter/data-formatter-skip-summary/TestDataFormatterSkipSummary.py (+1-1) 
- (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/unordered/TestDataFormatterGenericUnordered.py (+11-11) 
- (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/TestLibCxxAtomic.py (+1-1) 
- (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/initializerlist/TestInitializerList.py (+1-1) 
- (modified) lldb/test/API/functionalities/data-formatter/type_summary_list_arg/TestTypeSummaryListArg.py (+2-2) 
- (modified) lldb/test/API/functionalities/memory-region/TestMemoryRegion.py (+1-1) 
- (modified) lldb/test/API/functionalities/target_var/TestTargetVar.py (+1-1) 
- (modified) lldb/test/API/iohandler/completion/TestIOHandlerCompletion.py (+1-1) 
- (modified) lldb/test/API/lang/c/function_types/TestFunctionTypes.py (+1-1) 
- (modified) lldb/test/API/lang/c/register_variables/TestRegisterVariables.py (+1-1) 
- (modified) lldb/test/API/lang/c/set_values/TestSetValues.py (+2-2) 
- (modified) lldb/test/API/lang/c/strings/TestCStrings.py (+1-1) 
- (modified) lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py (+4-4) 
- (modified) lldb/test/API/lang/cpp/char1632_t/TestChar1632T.py (+4-4) 
- (modified) lldb/test/API/lang/cpp/class_static/TestStaticVariables.py (+2-2) 
- (modified) lldb/test/API/lang/cpp/class_types/TestClassTypes.py (+1-1) 
- (modified) lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py (+1-1) 
- (modified) lldb/test/API/lang/cpp/namespace/TestNamespace.py (+2-2) 
- (modified) lldb/test/API/lang/cpp/signed_types/TestSignedTypes.py (+2-2) 
- (modified) lldb/test/API/lang/cpp/unsigned_types/TestUnsignedTypes.py (+1-1) 
- (modified) lldb/test/API/lang/mixed/TestMixedLanguages.py (+2-2) 
- (modified) lldb/test/API/lang/objc/foundation/TestObjCMethods.py (+1-1) 
- (modified) lldb/test/API/lang/objc/foundation/TestObjCMethodsNSArray.py (+5-5) 
- (modified) lldb/test/API/lang/objc/foundation/TestObjCMethodsNSError.py (+1-1) 
- (modified) lldb/test/API/lang/objc/foundation/TestObjCMethodsString.py (+5-5) 
- (modified) lldb/test/API/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py (+1-1) 
- (modified) lldb/test/API/lang/objcxx/objc-builtin-types/TestObjCBuiltinTypes.py (+3-3) 
- (modified) lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py (+23-23) 
- (modified) lldb/test/API/linux/aarch64/mte_tag_access/TestAArch64LinuxMTEMemoryTagAccess.py (+84-84) 
- (modified) lldb/test/API/linux/aarch64/mte_tag_faults/TestAArch64LinuxMTEMemoryTagFaults.py (+3-3) 
- (modified) lldb/test/API/linux/aarch64/tagged_memory_region/TestAArch64LinuxTaggedMemoryRegion.py (+2-2) 
- (modified) lldb/test/API/macosx/add-dsym/TestAddDsymDownload.py (+1-1) 
- (modified) lldb/test/API/macosx/lc-note/firmware-corefile/TestFirmwareCorefiles.py (+1-1) 
- (modified) lldb/test/API/macosx/lc-note/kern-ver-str/TestKernVerStrLCNOTE.py (+1-1) 
- (modified) lldb/test/API/macosx/lc-note/multiple-binary-corefile/TestMultipleBinaryCorefile.py (+1-1) 
- (modified) lldb/test/API/macosx/simulator/TestSimulatorPlatform.py (+1-1) 
- (modified) lldb/test/API/macosx/skinny-corefile/TestSkinnyCorefile.py (+1-1) 
- (modified) lldb/test/API/python_api/target-arch-from-module/TestTargetArchFromModule.py (+1-1) 
- (modified) lldb/test/API/source-manager/TestSourceManager.py (+1-1) 
- (modified) lldb/test/API/tools/lldb-server/TestGdbRemoteModuleInfo.py (+3-3) 
- (modified) lldb/test/API/tools/lldb-server/TestPtyServer.py (+1-1) 
- (modified) lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py (+1-1) 
- (modified) lldb/test/API/types/AbstractBase.py (+3-3) 
- (modified) lldb/utils/lui/sourcewin.py (+1-1) 
- (modified) llvm/test/CodeGen/NVPTX/wmma.py (+1-1) 
- (modified) llvm/tools/opt-viewer/opt-viewer.py (+1-1) 
- (modified) llvm/utils/DSAclean.py (+1-1) 
- (modified) llvm/utils/DSAextract.py (+2-2) 
- (modified) llvm/utils/add_argument_names.py (+1-1) 
- (modified) llvm/utils/convert-constraint-log-to-z3.py (+1-1) 
- (modified) llvm/utils/extract_symbols.py (+10-10) 
- (modified) llvm/utils/extract_vplan.py (+1-1) 
- (modified) llvm/utils/git/github-automation.py (+3-3) 
- (modified) llvm/utils/indirect_calls.py (+1-1) 
- (modified) llvm/utils/relative_lines.py (+1-1) 
- (modified) llvm/utils/update_test_prefix.py (+5-5) 
- (modified) mlir/test/Integration/Dialect/SparseTensor/python/test_output.py (+3-3) 
- (modified) mlir/utils/spirv/gen_spirv_dialect.py (+5-5) 


``````````diff
diff --git a/.github/workflows/version-check.py b/.github/workflows/version-check.py
index f75fd50300881b..ed41ef4e1b16b0 100755
--- a/.github/workflows/version-check.py
+++ b/.github/workflows/version-check.py
@@ -6,7 +6,7 @@
 
 
 def get_version_from_tag(tag):
-    m = re.match("llvmorg-([0-9]+)\.([0-9]+)\.([0-9]+)(-rc[0-9]+)?$", tag)
+    m = re.match(r"llvmorg-([0-9]+)\.([0-9]+)\.([0-9]+)(-rc[0-9]+)?$", tag)
     if m:
         if m.lastindex == 4:
             # We have an rc tag.
diff --git a/clang-tools-extra/clang-tidy/add_new_check.py b/clang-tools-extra/clang-tidy/add_new_check.py
index a6af76809af02a..3b14d5d158d2d0 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -211,7 +211,7 @@ def adapt_module(module_path, module, check_name, check_name_camel):
                         f.write(check_decl)
                     else:
                         match = re.search(
-                            'registerCheck<(.*)> *\( *(?:"([^"]*)")?', line
+                            r'registerCheck<(.*)> *\( *(?:"([^"]*)")?', line
                         )
                         prev_line = None
                         if match:
@@ -383,7 +383,7 @@ def filename_from_module(module_name, check_name):
             if stmt_start_pos == -1:
                 return ""
             stmt = code[stmt_start_pos + 1 : stmt_end_pos]
-            matches = re.search('registerCheck<([^>:]*)>\(\s*"([^"]*)"\s*\)', stmt)
+            matches = re.search(r'registerCheck<([^>:]*)>\(\s*"([^"]*)"\s*\)', stmt)
             if matches and matches[2] == full_check_name:
                 class_name = matches[1]
                 if "::" in class_name:
@@ -401,8 +401,8 @@ def filename_from_module(module_name, check_name):
     # Examine code looking for a c'tor definition to get the base class name.
     def get_base_class(code, check_file):
         check_class_name = os.path.splitext(os.path.basename(check_file))[0]
-        ctor_pattern = check_class_name + "\([^:]*\)\s*:\s*([A-Z][A-Za-z0-9]*Check)\("
-        matches = re.search("\s+" + check_class_name + "::" + ctor_pattern, code)
+        ctor_pattern = check_class_name + r"\([^:]*\)\s*:\s*([A-Z][A-Za-z0-9]*Check)\("
+        matches = re.search(r"\s+" + check_class_name + "::" + ctor_pattern, code)
 
         # The constructor might be inline in the header.
         if not matches:
@@ -476,7 +476,7 @@ def process_doc(doc_file):
                 # Orphan page, don't list it.
                 return "", ""
 
-            match = re.search(".*:http-equiv=refresh: \d+;URL=(.*).html(.*)", content)
+            match = re.search(r".*:http-equiv=refresh: \d+;URL=(.*).html(.*)", content)
             # Is it a redirect?
             return check_name, match
 
@@ -505,7 +505,7 @@ def format_link_alias(doc_file):
                 ref_begin = ""
                 ref_end = "_"
             else:
-                redirect_parts = re.search("^\.\./([^/]*)/([^/]*)$", match.group(1))
+                redirect_parts = re.search(r"^\.\./([^/]*)/([^/]*)$", match.group(1))
                 title = redirect_parts[1] + "-" + redirect_parts[2]
                 target = redirect_parts[1] + "/" + redirect_parts[2]
                 autofix = has_auto_fix(title)
diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index d96b3450fdbe81..537d78a82cad65 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -242,7 +242,7 @@ def main():
     filename = None
     lines_by_file = {}
     for line in sys.stdin:
-        match = re.search('^\+\+\+\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
+        match = re.search(r'^\+\+\+\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
         if match:
             filename = match.group(2)
         if filename is None:
@@ -255,7 +255,7 @@ def main():
             if not re.match("^%s$" % args.iregex, filename, re.IGNORECASE):
                 continue
 
-        match = re.search("^@@.*\+(\d+)(,(\d+))?", line)
+        match = re.search(r"^@@.*\+(\d+)(,(\d+))?", line)
         if match:
             start_line = int(match.group(1))
             line_count = 1
diff --git a/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py b/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py
index 6545a3906fa50e..c19a0d3de7f11f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py
+++ b/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py
@@ -59,7 +59,7 @@ def get_checkers(checkers_td, checkers_rst):
             "clang-analyzer-" + checker_package_prefix + "." + checker_name
         )
         anchor_url = re.sub(
-            "\.", "-", checker_package_prefix + "." + checker_name
+            r"\.", "-", checker_package_prefix + "." + checker_name
         ).lower()
 
         if not hidden and "alpha" not in full_package_name.lower():
diff --git a/clang/docs/tools/dump_ast_matchers.py b/clang/docs/tools/dump_ast_matchers.py
index 705ff0d4d40985..b5dab8bc9ed080 100755
--- a/clang/docs/tools/dump_ast_matchers.py
+++ b/clang/docs/tools/dump_ast_matchers.py
@@ -101,7 +101,7 @@ def extract_result_types(comment):
 
 
 def strip_doxygen(comment):
-    """Returns the given comment without \-escaped words."""
+    """Returns the given comment without \\-escaped words."""
     # If there is only a doxygen keyword in the line, delete the whole line.
     comment = re.sub(r"^\\[^\s]+\n", r"", comment, flags=re.M)
 
@@ -236,7 +236,7 @@ def act_on_decl(declaration, comment, allowed_types):
 
         # Parse the various matcher definition macros.
         m = re.match(
-            """.*AST_TYPE(LOC)?_TRAVERSE_MATCHER(?:_DECL)?\(
+            r""".*AST_TYPE(LOC)?_TRAVERSE_MATCHER(?:_DECL)?\(
                        \s*([^\s,]+\s*),
                        \s*(?:[^\s,]+\s*),
                        \s*AST_POLYMORPHIC_SUPPORTED_TYPES\(([^)]*)\)
diff --git a/clang/test/Analysis/check-analyzer-fixit.py b/clang/test/Analysis/check-analyzer-fixit.py
index b616255de89b0c..efed0afc626b95 100644
--- a/clang/test/Analysis/check-analyzer-fixit.py
+++ b/clang/test/Analysis/check-analyzer-fixit.py
@@ -55,7 +55,7 @@ def run_test_once(args, extra_args):
     # themselves.  We need to keep the comments to preserve line numbers while
     # avoiding empty lines which could potentially trigger formatting-related
     # checks.
-    cleaned_test = re.sub("// *CHECK-[A-Z0-9\-]*:[^\r\n]*", "//", input_text)
+    cleaned_test = re.sub(r"// *CHECK-[A-Z0-9\-]*:[^\r\n]*", "//", input_text)
     write_file(temp_file_name, cleaned_test)
 
     original_file_name = temp_file_name + ".orig"
diff --git a/clang/utils/ABITest/TypeGen.py b/clang/utils/ABITest/TypeGen.py
index 6ebec7bdf1d1c4..df4b0ef60fff6a 100644
--- a/clang/utils/ABITest/TypeGen.py
+++ b/clang/utils/ABITest/TypeGen.py
@@ -43,7 +43,7 @@ def isBitField(self):
         return self.bitFieldSize is not None
 
     def isPaddingBitField(self):
-        return self.bitFieldSize is 0
+        return self.bitFieldSize == 0
 
     def getBitFieldSize(self):
         assert self.isBitField()
diff --git a/compiler-rt/lib/asan/scripts/asan_symbolize.py b/compiler-rt/lib/asan/scripts/asan_symbolize.py
index b08769614aeb18..058a1614b55e6a 100755
--- a/compiler-rt/lib/asan/scripts/asan_symbolize.py
+++ b/compiler-rt/lib/asan/scripts/asan_symbolize.py
@@ -316,7 +316,7 @@ def symbolize(self, addr, binary, offset):
         #   * For C functions atos omits parentheses and argument types.
         #   * For C++ functions the function name (i.e., `foo` above) may contain
         #     templates which may contain parentheses.
-        match = re.match("^(.*) \(in (.*)\) \((.*:\d*)\)$", atos_line)
+        match = re.match(r"^(.*) \(in (.*)\) \((.*:\d*)\)$", atos_line)
         logging.debug("atos_line: %s", atos_line)
         if match:
             function_name = match.group(1)
@@ -541,7 +541,7 @@ def process_line_posix(self, line):
         # names in the regex because it could be an
         # Objective-C or C++ demangled name.
         stack_trace_line_format = (
-            "^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)"
+            r"^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)"
         )
         match = re.match(stack_trace_line_format, line)
         if not match:
diff --git a/cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py b/cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py
index 29d7867e808673..fa6647a0fd56dc 100644
--- a/cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py
+++ b/cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py
@@ -128,7 +128,7 @@ def get_address_object(address_name: str, offset: int = 0):
 
 
 def _search_line_for_cmd_start(line: str, start: int, valid_commands: dict) -> int:
-    """Scan `line` for a string matching any key in `valid_commands`.
+    r"""Scan `line` for a string matching any key in `valid_commands`.
 
     Start searching from `start`.
     Commands escaped with `\` (E.g. `\DexLabel('a')`) are ignored.
@@ -543,7 +543,7 @@ def test_parse_share_line(self):
     def test_parse_escaped(self):
         """Escaped commands are ignored."""
 
-        lines = ['words \MockCmd("IGNORED") words words words\n']
+        lines = ['words \\MockCmd("IGNORED") words words words\n']
 
         values = self._find_all_mock_values_in_lines(lines)
 
diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py
index 774c4eaf4d976b..c7d3217c99304f 100644
--- a/cross-project-tests/lit.cfg.py
+++ b/cross-project-tests/lit.cfg.py
@@ -226,7 +226,7 @@ def can_target_host():
     xcode_lldb_vers = subprocess.check_output(["xcrun", "lldb", "--version"]).decode(
         "utf-8"
     )
-    match = re.search("lldb-(\d+)", xcode_lldb_vers)
+    match = re.search(r"lldb-(\d+)", xcode_lldb_vers)
     if match:
         apple_lldb_vers = int(match.group(1))
         if apple_lldb_vers < 1000:
@@ -250,7 +250,7 @@ def get_gdb_version_string():
     if len(gdb_vers_lines) < 1:
         print("Unkown GDB version format (too few lines)", file=sys.stderr)
         return None
-    match = re.search("GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines[0].strip())
+    match = re.search(r"GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines[0].strip())
     if match is None:
         print(f"Unkown GDB version format: {gdb_vers_lines[0]}", file=sys.stderr)
         return None
@@ -264,7 +264,7 @@ def get_clang_default_dwarf_version_string(triple):
     # Get the flags passed by the driver and look for -dwarf-version.
     cmd = f'{llvm_config.use_llvm_tool("clang")} -g -xc  -c - -v -### --target={triple}'
     stderr = subprocess.run(cmd.split(), stderr=subprocess.PIPE).stderr.decode()
-    match = re.search("-dwarf-version=(\d+)", stderr)
+    match = re.search(r"-dwarf-version=(\d+)", stderr)
     if match is None:
         print("Cannot determine default dwarf version", file=sys.stderr)
         return None
diff --git a/libcxx/test/libcxx/transitive_includes.gen.py b/libcxx/test/libcxx/transitive_includes.gen.py
index 28f223c422a9b0..3b61d9d39fef2a 100644
--- a/libcxx/test/libcxx/transitive_includes.gen.py
+++ b/libcxx/test/libcxx/transitive_includes.gen.py
@@ -57,7 +57,7 @@
       continue
 
     # Escape slashes for the awk command below
-    escaped_header = header.replace('/', '\/')
+    escaped_header = header.replace('/', '\\/')
 
     print(f"""\
 //--- {header}.sh.cpp
diff --git a/libcxx/utils/generate_escaped_output_table.py b/libcxx/utils/generate_escaped_output_table.py
index c6bde8f2411cf6..5e85235e2f7db4 100755
--- a/libcxx/utils/generate_escaped_output_table.py
+++ b/libcxx/utils/generate_escaped_output_table.py
@@ -136,7 +136,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
 
 /// Returns whether the code unit needs to be escaped.
 ///
-/// \pre The code point is a valid Unicode code point.
+/// \\pre The code point is a valid Unicode code point.
 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool __needs_escape(const char32_t __code_point) noexcept {{
   // Since __unallocated_region_lower_bound contains the unshifted range do the
   // comparison without shifting.
diff --git a/libcxx/utils/generate_width_estimation_table.py b/libcxx/utils/generate_width_estimation_table.py
index 918dae25fe49e5..2fe51490449ddb 100644
--- a/libcxx/utils/generate_width_estimation_table.py
+++ b/libcxx/utils/generate_width_estimation_table.py
@@ -155,7 +155,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
 
 /// Returns the estimated width of a Unicode code point.
 ///
-/// \pre The code point is a valid Unicode code point.
+/// \\pre The code point is a valid Unicode code point.
 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int __estimated_width(const char32_t __code_point) noexcept {{
   // Since __table_upper_bound contains the unshifted range do the
   // comparison without shifting.
diff --git a/lld/test/MachO/tools/validate-unwind-info.py b/lld/test/MachO/tools/validate-unwind-info.py
index ac49f1ecb58899..1cc82f82792731 100755
--- a/lld/test/MachO/tools/validate-unwind-info.py
+++ b/lld/test/MachO/tools/validate-unwind-info.py
@@ -11,7 +11,7 @@
 
 
 def main():
-    hex = "[a-f\d]"
+    hex = r"[a-f\d]"
     hex8 = hex + "{8}"
 
     parser = argparse.ArgumentParser(description=__doc__)
diff --git a/lld/utils/benchmark.py b/lld/utils/benchmark.py
index a07d5ecc69417c..7202e07ec438d2 100755
--- a/lld/utils/benchmark.py
+++ b/lld/utils/benchmark.py
@@ -51,7 +51,7 @@ def __str__(self):
 def getBenchmarks():
     ret = []
     for i in glob.glob("*/response*.txt"):
-        m = re.match("response-(.*)\.txt", os.path.basename(i))
+        m = re.match(r"response-(.*)\.txt", os.path.basename(i))
         variant = m.groups()[0] if m else None
         ret.append(Bench(os.path.dirname(i), variant))
     return ret
diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py
index c992348b24be17..6ee09c5c90d8b7 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -294,7 +294,7 @@ class DarwinImage(symbolication.Image):
             except:
                 dsymForUUIDBinary = ""
 
-        dwarfdump_uuid_regex = re.compile("UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")
+        dwarfdump_uuid_regex = re.compile(r"UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")
 
         def __init__(
             self, text_addr_lo, text_addr_hi, identifier, version, uuid, path, verbose
@@ -488,7 +488,7 @@ def find_image_with_identifier(self, identifier):
         for image in self.images:
             if image.identifier == identifier:
                 return image
-        regex_text = "^.*\.%s$" % (re.escape(identifier))
+        regex_text = r"^.*\.%s$" % (re.escape(identifier))
         regex = re.compile(regex_text)
         for image in self.images:
             if regex.match(image.identifier):
@@ -865,7 +865,7 @@ def get(cls):
             version = r"(?:" + super().version + r"\s+)?"
             address = r"(0x[0-9a-fA-F]{4,})"  # 4 digits or more
 
-            symbol = """
+            symbol = r"""
                         (?:
                             [ ]+
                             (?P<symbol>.+)
@@ -1035,7 +1035,7 @@ def parse_normal(self, line):
             self.crashlog.process_identifier = line[11:].strip()
         elif line.startswith("Version:"):
             version_string = line[8:].strip()
-            matched_pair = re.search("(.+)\((.+)\)", version_string)
+            matched_pair = re.search(r"(.+)\((.+)\)", version_string)
             if matched_pair:
                 self.crashlog.process_version = matched_pair.group(1)
                 self.crashlog.process_compatability_version = matched_pair.group(2)
diff --git a/lldb/examples/python/delta.py b/lldb/examples/python/delta.py
index eeb3c177cfa901..f847b95ab119f1 100755
--- a/lldb/examples/python/delta.py
+++ b/lldb/examples/python/delta.py
@@ -99,7 +99,7 @@ def parse_log_file(file, options):
     print("# Log file: '%s'" % file)
     print("#----------------------------------------------------------------------")
 
-    timestamp_regex = re.compile("(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
+    timestamp_regex = re.compile(r"(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
 
     base_time = 0.0
     last_time = 0.0
diff --git a/lldb/examples/python/gdbremote.py b/lldb/examples/python/gdbremote.py
index 40ee15853fdb21..d7c3b24cfbff65 100755
--- a/lldb/examples/python/gdbremote.py
+++ b/lldb/examples/python/gdbremote.py
@@ -1537,13 +1537,13 @@ def parse_gdb_log(file, options):
     a long time during a preset set of debugger commands."""
 
     tricky_commands = ["qRegisterInfo"]
-    timestamp_regex = re.compile("(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
-    packet_name_regex = re.compile("([A-Za-z_]+)[^a-z]")
+    timestamp_regex = re.compile(r"(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
+    packet_name_regex = re.compile(r"([A-Za-z_]+)[^a-z]")
     packet_transmit_name_regex = re.compile(
-        "(?P<direction>send|read) packet: (?P<packet>.*)"
+        r"(?P<direction>send|read) packet: (?P<packet>.*)"
     )
-    packet_contents_name_regex = re.compile("\$([^#]*)#[0-9a-fA-F]{2}")
-    packet_checksum_regex = re.compile(".*#[0-9a-fA-F]{2}$")
+    packet_contents_name_regex = re.compile(r"\$([^#]*)#[0-9a-fA-F]{2}")
+    packet_checksum_regex = re.compile(r".*#[0-9a-fA-F]{2}$")
     packet_names_regex_str = "(" + "|".join(gdb_remote_commands.keys()) + ")(.*)"
     packet_names_regex = re.compile(packet_names_regex_str)
 
diff --git a/lldb/examples/python/jump.py b/lldb/examples/python/jump.py
index e086df5fd15282..8d52bd9af43f6d 100644
--- a/lldb/examples/python/jump.py
+++ b/lldb/examples/python/jump.py
@@ -38,7 +38,7 @@ def parse_linespec(linespec, frame, result):
             )
 
     if not matched:
-        mo = re.match("^\+([0-9]+)$", linespec)
+        mo = re.match(r"^\+([0-9]+)$", linespec)
         if mo is not None:
             matched = True
             # print "Matched +<count>"
@@ -54,7 +54,7 @@ def parse_linespec(linespec, frame, result):
             )
 
     if not matched:
-        mo = re.match("^\-([0-9]+)$", linespec)
+        mo = re.match(r"^\-([0-9]+)$", linespec)
         if mo is not None:
             matched = True
             # print "Matched -<count>"
@@ -79,7 +79,7 @@ def parse_linespec(linespec, frame, result):
             breakpoint = target.BreakpointCreateByLocation(file_name, line_number)
 
     if not matched:
-        mo = re.match("\*((0x)?([0-9a-f]+))$", linespec)
+        mo = re.match(r"\*((0x)?([0-9a-f]+))$", linespec)
         if mo is not None:
             matched = True
             # print "Matched <address-expression>"
diff --git a/lldb/examples/python/performance.py b/lldb/examples/python/performance.py
index 869a0b061cf852..b86b5a52522e09 100755
--- a/lldb/examples/python/performance.py
+++ b/lldb/examples/python/performance.py
@@ -346,7 +346,7 @@ def __init__(self, pid):
 
     def Measure(self):
         output = subprocess.getoutput(self.command).split("\n")[-1]
-        values = re.split("[-+\s]+", output)
+        values = re.split(r"[-+\s]+", output)
         for idx, stat in enumerate(values):
             multiplier = 1
             if stat:
diff --git a/lldb/examples/python/symbolication.py b/lldb/examples/python/symbolication.py
index f6dcc8b9a79437..d47ae8bed64723 100755
--- a/lldb/examples/python/symbolication.py
+++ b/lldb/examples/python/symbolication.py
@@ -176,10 +176,10 @@ def symbolicate(self, verbose=False):
 class Section:
     """Class that represents an load address range"""
 
-    sect_info_regex = re.compile("(?P<name>[^=]+)=(?P<range>.*)")
-    addr_regex = re.compile("^\s*(?P<start>0x[0-9A-Fa-f]+)\s*$")
+    sect_info_regex = re.compile(r"(?P<name>[^=]+)=(?P<range>.*)")
+    addr_regex = re.compile(r"^\s*(?P<start>0x[0-9A-Fa-f]+)\s*$")
     range_regex = re.compile(
-        "^\s*(?P<start>0x[0-9A-Fa-f]+)\s*(?P<op>[-+])\s*(?P<end>0x[0-9A-Fa-f]+)\s*$"
+        r"^\s*(?P<start>0x[0-9A-Fa-f]+)\s*(?P<op>[-+])\s*(?P<end>0x[0-9A-Fa-f]+)\s*$"
     )
 
     def __init__(self, start_addr=None, end_addr=None, name=None):
@@ -557,7 +557,7 @@ def find_images_with_identifier(self, identifier):
             if image....
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/86806


More information about the Mlir-commits mailing list