Skip to content

[Demangle] demangle builtin type transformations #65902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion libcxxabi/src/demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,23 @@ class ElaboratedTypeSpefType : public Node {
}
};

class TransformedType : public Node {
std::string_view Transform;
Node *BaseType;
public:
TransformedType(std::string_view Transform_, Node *BaseType_)
: Node(KTransformedType), Transform(Transform_), BaseType(BaseType_) {}

template<typename Fn> void match(Fn F) const { F(Transform, BaseType); }

void printLeft(OutputBuffer &OB) const override {
OB += Transform;
OB += '(';
BaseType->print(OB);
OB += ')';
}
};

struct AbiTagAttr : Node {
Node *Base;
std::string_view Tag;
Expand Down Expand Up @@ -3894,7 +3911,15 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
// Typically, <builtin-type>s are not considered substitution candidates,
// but the exception to that exception is vendor extended types (Itanium C++
// ABI 5.9.1).
Result = make<NameType>(Res);
if (consumeIf('I')) {
Node *BaseType = parseType();
if (BaseType == nullptr)
return nullptr;
if (!consumeIf('E'))
return nullptr;
Result = make<TransformedType>(Res, BaseType);
} else
Result = make<NameType>(Res);
break;
}
case 'D':
Expand Down
1 change: 1 addition & 0 deletions libcxxabi/src/demangle/ItaniumNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ NODE(QualType)
NODE(ConversionOperatorType)
NODE(PostfixQualifiedType)
NODE(ElaboratedTypeSpefType)
NODE(TransformedType)
NODE(NameType)
NODE(AbiTagAttr)
NODE(EnableIfAttr)
Expand Down
9 changes: 9 additions & 0 deletions libcxxabi/test/test_demangle.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30114,6 +30114,15 @@ const char* cases[][2] =
" std::allocator<char>>::basic_string()"},
{"_ZN1SB8ctor_tagC2Ev", "S[abi:ctor_tag]::S()"},
{"_ZN1SB8ctor_tagD2Ev", "S[abi:ctor_tag]::~S()"},

// clang builtin type transform
{"_Z2f5IiEvu22__add_lvalue_referenceIT_E", "void f5<int>(__add_lvalue_reference(int))"},
{"_Z2f5IiEvu13__add_pointerIT_E", "void f5<int>(__add_pointer(int))"},
{"_Z2f5IiEvu7__decayIT_E", "void f5<int>(__decay(int))"},
{"_Z2f5IjEvu13__make_signedIT_E", "void f5<unsigned int>(__make_signed(unsigned int))"},
{"_Z2f5IKiEvu14__remove_constIT_E", "void f5<int const>(__remove_const(int const))"},
{"_Z2f5IPiEvu16__remove_pointerIT_E", "void f5<int*>(__remove_pointer(int*))"},
{"_Z2f5IiEvu14__remove_cvrefIT_E", "void f5<int>(__remove_cvref(int))"},
};

const unsigned N = sizeof(cases) / sizeof(cases[0]);
Expand Down
27 changes: 26 additions & 1 deletion llvm/include/llvm/Demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,23 @@ class ElaboratedTypeSpefType : public Node {
}
};

class TransformedType : public Node {
std::string_view Transform;
Node *BaseType;
public:
TransformedType(std::string_view Transform_, Node *BaseType_)
: Node(KTransformedType), Transform(Transform_), BaseType(BaseType_) {}

template<typename Fn> void match(Fn F) const { F(Transform, BaseType); }

void printLeft(OutputBuffer &OB) const override {
OB += Transform;
OB += '(';
BaseType->print(OB);
OB += ')';
}
};

struct AbiTagAttr : Node {
Node *Base;
std::string_view Tag;
Expand Down Expand Up @@ -3889,7 +3906,15 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
// Typically, <builtin-type>s are not considered substitution candidates,
// but the exception to that exception is vendor extended types (Itanium C++
// ABI 5.9.1).
Result = make<NameType>(Res);
if (consumeIf('I')) {
Node *BaseType = parseType();
if (BaseType == nullptr)
return nullptr;
if (!consumeIf('E'))
return nullptr;
Result = make<TransformedType>(Res, BaseType);
} else
Result = make<NameType>(Res);
break;
}
case 'D':
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/Demangle/ItaniumNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ NODE(QualType)
NODE(ConversionOperatorType)
NODE(PostfixQualifiedType)
NODE(ElaboratedTypeSpefType)
NODE(TransformedType)
NODE(NameType)
NODE(AbiTagAttr)
NODE(EnableIfAttr)
Expand Down