Skip to content

[compiler-rt] Fix invalid escape sequences in python files #94030

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

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

e-kwsm
Copy link
Contributor

@e-kwsm e-kwsm commented May 31, 2024

\d, ( and ) are not valid escape sequences; since python 3.12
they give SyntaxWarning, and will raise SyntaxError in future. https://docs.python.org/3.12/whatsnew/3.12.html#other-language-changes

r"(\d)" and "\(\d\)" are equivalent but the former is the shorter.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented May 31, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Eisuke Kawashima (e-kwsm)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/94030.diff

1 Files Affected:

  • (modified) compiler-rt/lib/asan/scripts/asan_symbolize.py (+2-2)
diff --git a/compiler-rt/lib/asan/scripts/asan_symbolize.py b/compiler-rt/lib/asan/scripts/asan_symbolize.py
index b08769614aeb1..058a1614b55e6 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:

@e-kwsm e-kwsm force-pushed the compiler-rt/W605 branch from 4178c34 to 7751594 Compare June 23, 2024 12:22
@e-kwsm e-kwsm force-pushed the compiler-rt/W605 branch from 7751594 to 3c0d333 Compare July 16, 2024 05:36
@e-kwsm e-kwsm force-pushed the compiler-rt/W605 branch 2 times, most recently from 340b4c7 to ec9747f Compare September 2, 2024 07:15
@llvmbot llvmbot added the compiler-rt:hwasan Hardware-assisted address sanitizer label Sep 2, 2024
@cjappl
Copy link
Contributor

cjappl commented Oct 24, 2024

Will you add a description saying why these are invalid, and why the r" is preferable?

@e-kwsm
Copy link
Contributor Author

e-kwsm commented Oct 28, 2024

\d, \( and \) are not valid escape sequences; since python 3.12
they give SyntaxWarning, and will raise SyntaxError in future. https://docs.python.org/3.12/whatsnew/3.12.html#other-language-changes

r"\(\d\)" and "\\(\\d\\)" are equivalent but the former is the shorter.

Copy link
Contributor

@fmayer fmayer left a comment

Choose a reason for hiding this comment

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

verified that LHS equals RHS in python 3.11

>>> "^(.*) \(in (.*)\) \((.*:\d*)\)$" == r"^(.*) \(in (.*)\) \((.*:\d*)\)$"
True
>>> "^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)" == r"^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)"
True
>>> (r'.*?(0x[0-9a-f]+):' + '([ ]*[\[ ][0-9a-f][0-9a-f]\]?)') ==  ( 
KeyboardInterrupt
>>> (r'.*?(0x[0-9a-f]+):' + '([ ]*[\[ ][0-9a-f][0-9a-f]\]?)' * 16) == (r'.*?(0x[0-9a-f]+):' + r'([ ]*[\[ ][0-9a-f][0-9a-f]\]?)' * 16)
True
>>> 

@cjappl cjappl changed the title fix(compiler-rt/**.py): fix invalid escape sequences [compiler-rt] Fix invalid escape sequences in python files Oct 28, 2024
Copy link
Contributor

@cjappl cjappl left a comment

Choose a reason for hiding this comment

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

I'll submit this once tests are green. Thanks for the contribution :)

@cjappl cjappl merged commit 61353cc into llvm:main Oct 29, 2024
7 checks passed
Copy link

@e-kwsm Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@e-kwsm e-kwsm deleted the compiler-rt/W605 branch November 3, 2024 09:07
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
\d, \( and \) are not valid escape sequences; since python 3.12
they give SyntaxWarning, and will raise SyntaxError in future.
https://docs.python.org/3.12/whatsnew/3.12.html#other-language-changes

r"\(\d\)" and "\\(\\d\\)" are equivalent but the former is the shorter.

Co-authored-by: Eisuke Kawashima <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt:asan Address sanitizer compiler-rt:hwasan Hardware-assisted address sanitizer compiler-rt:sanitizer compiler-rt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants