Skip to content

Commit

Permalink
[ItaniumDemangle] Set InConstraintExpr to true when demangling a …
Browse files Browse the repository at this point in the history
…constraint expression (#107385)

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](llvm/llvm-project#89914).
  • Loading branch information
VitaNuo authored Sep 12, 2024
1 parent e2723c2 commit c22b68c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
13 changes: 10 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,8 @@ 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 +5677,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 +5738,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
1 change: 1 addition & 0 deletions libcxxabi/test/test_demangle.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30137,6 +30137,7 @@ const char* cases[][2] =
{"_ZZN5test71fIiEEvvENKUlTyQaa1CIT_E1CITL0__ET0_E0_clIiiEEDaS3_Qaa1CIDtfp_EELb1E", "auto void test7::f<int>()::'lambda0'<typename $T> requires C<T> && C<TL0_> (auto)::operator()<int, int>(auto) const requires C<decltype(fp)> && true"},
{"_ZZN5test71fIiEEvvENKUlTyQaa1CIT_E1CITL0__ET0_E1_clIiiEEDaS3_Q1CIDtfp_EE", "auto void test7::f<int>()::'lambda1'<typename $T> requires C<T> && C<TL0_> (auto)::operator()<int, int>(auto) const requires C<decltype(fp)>"},
{"_ZZN5test71fIiEEvvENKUlTyT0_E_clIiiEEDaS1_", "auto void test7::f<int>()::'lambda'<typename $T>(auto)::operator()<int, int>(auto) const"},
{"_ZN3FooIiE6methodITk4TrueIT_EiEEvS3_", "void Foo<int>::method<int>(T)"},

// C++20 requires expressions, see https://github.com/itanium-cxx-abi/cxx-abi/issues/24.
{"_Z1fIiEviQrqXcvT__EXfp_Xeqfp_cvS0__EXplcvS0__ELi1ER5SmallXmicvS0__ELi1ENXmlcvS0__ELi2ENR11SmallerThanILi1234EETS0_T1XIS0_ETNS3_4typeETS2_IiEQ11SmallerThanIS0_Li256EEE", "void f<int>(int) requires requires { (T)(); fp; fp == (T)(); {(T)() + 1} -> Small; {(T)() - 1} noexcept; {(T)() * 2} noexcept -> SmallerThan<1234>; typename T; typename X<T>; typename X<T>::type; typename X<int>; requires SmallerThan<T, 256>; }"},
Expand Down
13 changes: 10 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,8 @@ 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 +5677,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 +5738,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

0 comments on commit c22b68c

Please sign in to comment.