Skip to content

Conversation

cmtice
Copy link
Contributor

@cmtice cmtice commented Aug 29, 2025

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 '$'.

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 some LLDB tests
to fail when using the lit internal shell.

This PR fixes that by having the lexer remove the escape on the '$'.
@cmtice cmtice marked this pull request as ready for review August 29, 2025 23:57
@cmtice cmtice requested a review from boomanaiden154 August 29, 2025 23:58
@llvmbot
Copy link
Member

llvmbot commented Aug 29, 2025

@llvm/pr-subscribers-testing-tools

Author: None (cmtice)

Changes

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 some LLDB tests to fail when using the lit internal shell.

This PR fixes that by having the lexer remove the escape on the '$'.


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

1 Files Affected:

  • (modified) llvm/utils/lit/lit/ShUtil.py (+5)
diff --git a/llvm/utils/lit/lit/ShUtil.py b/llvm/utils/lit/lit/ShUtil.py
index fa13167cad1be..ff151b1e29330 100644
--- a/llvm/utils/lit/lit/ShUtil.py
+++ b/llvm/utils/lit/lit/ShUtil.py
@@ -115,6 +115,11 @@ def lex_arg_quoted(self, delim):
             c = self.eat()
             if c == delim:
                 return str
+            # LLDB uses "$" at the start of global variable names; it should
+            # not be escaped nor dropped.
+            elif c == "\\" and self.look() == "$":
+                c = self.eat()
+                str += c
             elif c == "\\" and delim == '"':
                 # Inside a '"' quoted string, '\\' only escapes the quote
                 # character and backslash, otherwise it is preserved.

@arichardson
Copy link
Member

Is it possible to include a test for this?

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

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

This needs a test in llvm/utils/lit/tests.

Adding some information in the PR description on what LLDB tests are impacted by this would also be helpful. There are some existing issues related to enabling the lit internal shell in LLDB, and adding a link to those (particularly #102698, none of the others look relevant) wouldn't hurt.

@cmtice
Copy link
Contributor Author

cmtice commented Sep 3, 2025

This needs a test in llvm/utils/lit/tests.

Adding some information in the PR description on what LLDB tests are impacted by this would also be helpful. There are some existing issues related to enabling the lit internal shell in LLDB, and adding a link to those (particularly #102698, none of the others look relevant) wouldn't hurt.

I updated an existing internal shell lexer test to test for this. I also updated the PR description, giving a lot more detail. Also mentioned this PR in issue #102698.

Copy link

github-actions bot commented Sep 3, 2025

✅ With the latest revision this PR passed the Python code formatter.

@boomanaiden154
Copy link
Contributor

I updated an existing internal shell lexer test to test for this. I also updated the PR description, giving a lot more detail. Also mentioned this PR in issue #102698.

Thanks. Could you list the tests that this impacts somewhere as well?

@cmtice
Copy link
Contributor Author

cmtice commented Sep 3, 2025

I updated an existing internal shell lexer test to test for this. I also updated the PR description, giving a lot more detail. Also mentioned this PR in issue #102698.

Thanks. Could you list the tests that this impacts somewhere as well?

To the best of my knowledge it only impacts the test I mentioned in the commit message.

@cmtice cmtice merged commit 527c8ff into llvm:main Sep 3, 2025
9 checks passed
@boomanaiden154
Copy link
Contributor

Just making a note here in case anyone else comes across it:

Certain sequences after this change need to be double escaped if they are supposed to be passed to the command escaped, like the following from an lld test:

# RUN: awk '/^__OBJC_\\$_CATEGORY_MyBaseClass_\\$_Category01:/ { print; getline; sub(/^[ \t]*\.quad[ \t]+l_OBJC_CLASS_NAME_$/, "\t.quad\tL_OBJC_IMAGE_INFO+3"); print; next } { print }' merge_cat_minimal.s > merge_cat_minimal_bad_name.s

@arichardson
Copy link
Member

Just making a note here in case anyone else comes across it:

Certain sequences after this change need to be double escaped if they are supposed to be passed to the command escaped, like the following from an lld test:

# RUN: awk '/^__OBJC_\\$_CATEGORY_MyBaseClass_\\$_Category01:/ { print; getline; sub(/^[ \t]*\.quad[ \t]+l_OBJC_CLASS_NAME_$/, "\t.quad\tL_OBJC_IMAGE_INFO+3"); print; next } { print }' merge_cat_minimal.s > merge_cat_minimal_bad_name.s

Is this behaviour different from POSIX sh? I think we should make sure that the internal shell has the same behaviour.

I think maybe the difference we have here is that the removal of the \ should only happen for double-quoted strings but not single-quoted ones?

Comment on lines +31 to +32
self.assertEqual(self.lex('"\\$y = 11"'), ["$y = 11"])
self.assertEqual(self.lex('"expr \\$y = 11"'), ["expr $y = 11"])
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a test with single quotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #156742 for requested fix & test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants