Skip to content

Commit

Permalink
[ItaniumDemangle] Set InConstraintExpr to true when demangling a cons…
Browse files Browse the repository at this point in the history
…traint expression.

This prevents demangler failures until the TODO in the [demangler](https://github.com/llvm/llvm-project/blob/3e070906eff720dc44aee86e533e12aafc8bb14b/llvm/include/llvm/Demangle/ItaniumDemangle.h#L5678) is implemented.

This is a temporary fix for [#89914](#89914).
  • Loading branch information
VitaNuo committed Sep 10, 2024
1 parent 07bef02 commit 36aabbe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
12 changes: 9 additions & 3 deletions libcxxabi/src/demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {

bool TryToParseTemplateArgs = true;
bool PermitForwardTemplateReferences = false;
bool InConstraintExpr = false;
bool HasIncompleteTemplateParameterTracking = false;
size_t ParsingLambdaParamsAtLevel = (size_t)-1;

unsigned NumSyntheticTemplateParameters[3] = {};
Expand Down Expand Up @@ -4818,7 +4818,7 @@ template <typename Derived, typename Alloc>
Node *AbstractManglingParser<Derived, Alloc>::parseConstraintExpr() {
// Within this expression, all enclosing template parameter lists are in
// scope.
ScopedOverride<bool> SaveInConstraintExpr(InConstraintExpr, true);
ScopedOverride<bool> SaveIncompleteTemplateParameterTracking(HasIncompleteTemplateParameterTracking, true);
return getDerived().parseExpr();
}

Expand Down Expand Up @@ -5676,7 +5676,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseTemplateParam() {
// substitute them all within a <constraint-expression>, so print the
// parameter numbering instead for now.
// TODO: Track all enclosing template parameters and substitute them here.
if (InConstraintExpr) {
if (HasIncompleteTemplateParameterTracking) {
return make<NameType>(std::string_view(Begin, First - 1 - Begin));
}

Expand Down Expand Up @@ -5737,6 +5737,12 @@ Node *AbstractManglingParser<Derived, Alloc>::parseTemplateParamDecl(
}

if (consumeIf("Tk")) {
// We don't track enclosing template parameter levels well enough to reliably
// demangle template parameter substitutions, so print an arbitrary
// string in place of a parameter for now.
// TODO: Track all enclosing template parameters and demangle substitutions.
ScopedOverride<bool> SaveIncompleteTemplateParameterTrackingExpr(
HasIncompleteTemplateParameterTracking, true);
Node *Constraint = getDerived().parseName();
if (!Constraint)
return nullptr;
Expand Down
12 changes: 9 additions & 3 deletions llvm/include/llvm/Demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {

bool TryToParseTemplateArgs = true;
bool PermitForwardTemplateReferences = false;
bool InConstraintExpr = false;
bool HasIncompleteTemplateParameterTracking = false;
size_t ParsingLambdaParamsAtLevel = (size_t)-1;

unsigned NumSyntheticTemplateParameters[3] = {};
Expand Down Expand Up @@ -4818,7 +4818,7 @@ template <typename Derived, typename Alloc>
Node *AbstractManglingParser<Derived, Alloc>::parseConstraintExpr() {
// Within this expression, all enclosing template parameter lists are in
// scope.
ScopedOverride<bool> SaveInConstraintExpr(InConstraintExpr, true);
ScopedOverride<bool> SaveIncompleteTemplateParameterTracking(HasIncompleteTemplateParameterTracking, true);
return getDerived().parseExpr();
}

Expand Down Expand Up @@ -5676,7 +5676,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseTemplateParam() {
// substitute them all within a <constraint-expression>, so print the
// parameter numbering instead for now.
// TODO: Track all enclosing template parameters and substitute them here.
if (InConstraintExpr) {
if (HasIncompleteTemplateParameterTracking) {
return make<NameType>(std::string_view(Begin, First - 1 - Begin));
}

Expand Down Expand Up @@ -5737,6 +5737,12 @@ Node *AbstractManglingParser<Derived, Alloc>::parseTemplateParamDecl(
}

if (consumeIf("Tk")) {
// We don't track enclosing template parameter levels well enough to reliably
// demangle template parameter substitutions, so print an arbitrary
// string in place of a parameter for now.
// TODO: Track all enclosing template parameters and demangle substitutions.
ScopedOverride<bool> SaveIncompleteTemplateParameterTrackingExpr(
HasIncompleteTemplateParameterTracking, true);
Node *Constraint = getDerived().parseName();
if (!Constraint)
return nullptr;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RUN: llvm-cxxfilt -n _ZN3FooIiE6methodITk4TrueIT_EiEEvS3_ | FileCheck %s

CHECK: void Foo<int>::method<int>(T)

0 comments on commit 36aabbe

Please sign in to comment.