Skip to content

Conversation

@Michael137
Copy link

Currently OutputBuffer::GtIsGt is used to tell us if we're inside template arguments and have printed a '(' without a closing ')'. If so, we don't need to quote '<' when printing it as part of a binary expression inside a template argument. Otherwise we need to. E.g.,

foo<a<(b < c)>> // Quotes around binary expression needed.

LLDB's TrackingOutputBuffer has heuristics that rely on checking whether we are inside template arguments, regardless of the current parentheses depth. We've been using isGtInsideTemplateArgs for this, but that isn't correct. Resulting in us incorrectly tracking the basename of function like:

void func<(foo::Enum)1>()

Here GtIsGt > 0 despite us being inside template arguments (because we incremented it when seeing '(').

This patch adds a isInsideTemplateArgs API which LLDB will use to more accurately track parts of the demangled name.

To make sure this API doesn't go untested in the actual libcxxabi test-suite, I changed the existing GtIsGt logic to use it. Also renamed the various variables/APIs involved to make it (in my opinion) more straightforward to understand what's going on. But happy to rename it back if people disagree.

Also adjusted LLDB to use the newly introduced API (and added a unit-test that would previously fail).

(cherry picked from commit 54c9ddd)

…llvm#166578)

Currently `OutputBuffer::GtIsGt` is used to tell us if we're inside
template arguments and have printed a '(' without a closing ')'. If so,
we don't need to quote '<' when printing it as part of a binary
expression inside a template argument. Otherwise we need to. E.g.,
```
foo<a<(b < c)>> // Quotes around binary expression needed.
```

LLDB's `TrackingOutputBuffer` has heuristics that rely on checking
whether we are inside template arguments, regardless of the current
parentheses depth. We've been using `isGtInsideTemplateArgs` for this,
but that isn't correct. Resulting in us incorrectly tracking the
basename of function like:
```
void func<(foo::Enum)1>()
```
Here `GtIsGt > 0` despite us being inside template arguments (because we
incremented it when seeing '(').

This patch adds a `isInsideTemplateArgs` API which LLDB will use to more
accurately track parts of the demangled name.

To make sure this API doesn't go untested in the actual libcxxabi
test-suite, I changed the existing `GtIsGt` logic to use it. Also
renamed the various variables/APIs involved to make it (in my opinion)
more straightforward to understand what's going on. But happy to rename
it back if people disagree.

Also adjusted LLDB to use the newly introduced API (and added a
unit-test that would previously fail).

(cherry picked from commit 54c9ddd)
@Michael137
Copy link
Author

@swift-ci test

@Michael137
Copy link
Author

@swift-ci test windows

@Michael137 Michael137 merged commit c9d322e into stable/21.x Nov 7, 2025
3 checks passed
@Michael137 Michael137 deleted the libcxxabi/template-tracking-to-21.x branch November 7, 2025 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants