Skip to content

Commit 527c8ff

Browse files
authored
[lit] Update internal shell lexer to handle LLDB persistent vars. (#156125)
LLDB allows creation of 'persistent' variables, with names that start with '$'. The lit internal shell was escaping the '$', making it '\\$', in some CHECK lines, which causes an LLDB test, TestExprWithSideEffectOnConvenienceVar, to fail when using the lit internal shell. Further explanation of the failing LLDB test: LLDB convenience variables start with '$'. The test passes several quoted commands that use and update convenience variables to lldb as arguments to be run in batch mode. The tool that packages up the complete string and passes it to the lit internal shell lexer for lexing inserts a backslash in front of the '$' before passing the string in for lexing. The lexer was passing this change along, causing the tests to fail. This PR fixes the issue by having the lexer remove the newly added escape on the '$'.
1 parent bad2036 commit 527c8ff

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

llvm/utils/lit/lit/ShUtil.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ def lex_arg_quoted(self, delim):
115115
c = self.eat()
116116
if c == delim:
117117
return str
118+
# LLDB uses "$" at the start of global variable names; it should
119+
# not be escaped nor dropped.
120+
elif c == "\\" and self.look() == "$":
121+
c = self.eat()
122+
str += c
118123
elif c == "\\" and delim == '"':
119124
# Inside a '"' quoted string, '\\' only escapes the quote
120125
# character and backslash, otherwise it is preserved.

llvm/utils/lit/tests/unit/ShUtil.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def test_quoting(self):
2828
self.assertEqual(self.lex(""" a\\ b a\\\\b """), ["a b", "a\\b"])
2929
self.assertEqual(self.lex(""" "" "" """), ["", ""])
3030
self.assertEqual(self.lex(""" a\\ b """, win32Escapes=True), ["a\\", "b"])
31-
31+
self.assertEqual(self.lex('"\\$y = 11"'), ["$y = 11"])
32+
self.assertEqual(self.lex('"expr \\$y = 11"'), ["expr $y = 11"])
3233

3334
class TestShParse(unittest.TestCase):
3435
def parse(self, str):

0 commit comments

Comments
 (0)