[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:51:57 PDT 2025


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

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.

>From 5d66f1eeb7722ff358f0a4c6286e66fac3a383a7 Mon Sep 17 00:00:00 2001
From: Caroline Tice <cmtice at google.com>
Date: Wed, 3 Sep 2025 12:50:03 -0700
Subject: [PATCH] lit] Update internal shell lexer to remove escape on '$' only
 for double-quoted strings.

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.
---
 llvm/utils/lit/lit/ShUtil.py        | 2 +-
 llvm/utils/lit/tests/unit/ShUtil.py | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

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):



More information about the llvm-commits mailing list