[llvm] lit] Update internal shell lexer to remove escape on '$' only for double-quoted strings. (PR #156742)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 3 12:52:32 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-testing-tools

Author: None (cmtice)

<details>
<summary>Changes</summary>

PR 156125 removed the escape (backslash) in front of '$' for all quoted strings. It has since been pointed out this should only happen for double-quoted strings. This PR fixes that.

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


2 Files Affected:

- (modified) llvm/utils/lit/lit/ShUtil.py (+1-1) 
- (modified) llvm/utils/lit/tests/unit/ShUtil.py (+2) 


``````````diff
diff --git a/llvm/utils/lit/lit/ShUtil.py b/llvm/utils/lit/lit/ShUtil.py
index ff151b1e29330..f3778ad23fddf 100644
--- a/llvm/utils/lit/lit/ShUtil.py
+++ b/llvm/utils/lit/lit/ShUtil.py
@@ -117,7 +117,7 @@ def lex_arg_quoted(self, delim):
                 return str
             # LLDB uses "$" at the start of global variable names; it should
             # not be escaped nor dropped.
-            elif c == "\\" and self.look() == "$":
+            elif c == "\\" and self.look() == "$" and delim == '"':
                 c = self.eat()
                 str += c
             elif c == "\\" and delim == '"':
diff --git a/llvm/utils/lit/tests/unit/ShUtil.py b/llvm/utils/lit/tests/unit/ShUtil.py
index 877fc007b8678..2904125b084f2 100644
--- a/llvm/utils/lit/tests/unit/ShUtil.py
+++ b/llvm/utils/lit/tests/unit/ShUtil.py
@@ -30,6 +30,8 @@ def test_quoting(self):
         self.assertEqual(self.lex(""" a\\ b """, win32Escapes=True), ["a\\", "b"])
         self.assertEqual(self.lex('"\\$y = 11"'), ["$y = 11"])
         self.assertEqual(self.lex('"expr \\$y = 11"'), ["expr $y = 11"])
+        self.assertEqual(self.lex("'\\$y = 11'"), ["\\$y = 11"])
+        self.assertEqual(self.lex("'expr \\$y = 11'"), ["expr \\$y = 11"])
 
 class TestShParse(unittest.TestCase):
     def parse(self, str):

``````````

</details>


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


More information about the llvm-commits mailing list