Skip to content

Commit a23652f

Browse files
committed
[demangler] Support C23 _BitInt type
Reviewed By: #libc_abi, aaron.ballman, urnathan Differential Revision: https://reviews.llvm.org/D122530
1 parent 497f87b commit a23652f

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

libcxxabi/src/demangle/ItaniumDemangle.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,26 @@ class NameType final : public Node {
482482
void printLeft(OutputBuffer &OB) const override { OB += Name; }
483483
};
484484

485+
class BitIntType final : public Node {
486+
const Node *Size;
487+
bool Signed;
488+
489+
public:
490+
BitIntType(const Node *Size_, bool Signed_)
491+
: Node(KBitIntType), Size(Size_), Signed(Signed_) {}
492+
493+
template <typename Fn> void match(Fn F) const { F(Size, Signed); }
494+
495+
void printLeft(OutputBuffer &OB) const override {
496+
if (!Signed)
497+
OB += "unsigned ";
498+
OB += "_BitInt";
499+
OB.printOpen();
500+
Size->printAsOperand(OB);
501+
OB.printClose();
502+
}
503+
};
504+
485505
class ElaboratedTypeSpefType : public Node {
486506
StringView Kind;
487507
Node *Child;
@@ -3924,6 +3944,22 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
39243944
return nullptr;
39253945
return make<BinaryFPType>(DimensionNumber);
39263946
}
3947+
// ::= DB <number> _ # C23 signed _BitInt(N)
3948+
// ::= DB <instantiation-dependent expression> _ # C23 signed _BitInt(N)
3949+
// ::= DU <number> _ # C23 unsigned _BitInt(N)
3950+
// ::= DU <instantiation-dependent expression> _ # C23 unsigned _BitInt(N)
3951+
case 'B':
3952+
case 'U': {
3953+
bool Signed = look(1) == 'B';
3954+
First += 2;
3955+
Node *Size = std::isdigit(look()) ? make<NameType>(parseNumber())
3956+
: getDerived().parseExpr();
3957+
if (!Size)
3958+
return nullptr;
3959+
if (!consumeIf('_'))
3960+
return nullptr;
3961+
return make<BitIntType>(Size, Signed);
3962+
}
39273963
// ::= Di # char32_t
39283964
case 'i':
39293965
First += 2;

libcxxabi/src/demangle/ItaniumNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ NODE(ModuleEntity)
4242
NODE(VectorType)
4343
NODE(PixelVectorType)
4444
NODE(BinaryFPType)
45+
NODE(BitIntType)
4546
NODE(SyntheticTemplateParamName)
4647
NODE(TypeTemplateParamDecl)
4748
NODE(NonTypeTemplateParamDecl)

libcxxabi/test/test_demangle.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const char* cases[][2] =
3232
{"_Z1A", "A"},
3333
{"_Z1Av", "A()"},
3434
{"_Z1A1B1C", "A(B, C)"},
35+
{"_Z1fDB3_", "f(_BitInt(3))"},
36+
{"_Z1fDU10_", "f(unsigned _BitInt(10))"},
37+
{"_Z1fIfEvDUstPT__", "void f<float>(unsigned _BitInt(sizeof (float*)))"},
38+
{"_Z1fIiEvDBstPT__", "void f<int>(_BitInt(sizeof (int*)))"},
3539
{"_Z4testI1A1BE1Cv", "C test<A, B>()"},
3640
{"_Z4testI1A1BET0_T_S3_", "B test<A, B>(A, A)"},
3741
{"_ZN1SgtEi", "S::operator>(int)"},

llvm/include/llvm/Demangle/ItaniumDemangle.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,26 @@ class NameType final : public Node {
482482
void printLeft(OutputBuffer &OB) const override { OB += Name; }
483483
};
484484

485+
class BitIntType final : public Node {
486+
const Node *Size;
487+
bool Signed;
488+
489+
public:
490+
BitIntType(const Node *Size_, bool Signed_)
491+
: Node(KBitIntType), Size(Size_), Signed(Signed_) {}
492+
493+
template <typename Fn> void match(Fn F) const { F(Size, Signed); }
494+
495+
void printLeft(OutputBuffer &OB) const override {
496+
if (!Signed)
497+
OB += "unsigned ";
498+
OB += "_BitInt";
499+
OB.printOpen();
500+
Size->printAsOperand(OB);
501+
OB.printClose();
502+
}
503+
};
504+
485505
class ElaboratedTypeSpefType : public Node {
486506
StringView Kind;
487507
Node *Child;
@@ -3924,6 +3944,22 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
39243944
return nullptr;
39253945
return make<BinaryFPType>(DimensionNumber);
39263946
}
3947+
// ::= DB <number> _ # C23 signed _BitInt(N)
3948+
// ::= DB <instantiation-dependent expression> _ # C23 signed _BitInt(N)
3949+
// ::= DU <number> _ # C23 unsigned _BitInt(N)
3950+
// ::= DU <instantiation-dependent expression> _ # C23 unsigned _BitInt(N)
3951+
case 'B':
3952+
case 'U': {
3953+
bool Signed = look(1) == 'B';
3954+
First += 2;
3955+
Node *Size = std::isdigit(look()) ? make<NameType>(parseNumber())
3956+
: getDerived().parseExpr();
3957+
if (!Size)
3958+
return nullptr;
3959+
if (!consumeIf('_'))
3960+
return nullptr;
3961+
return make<BitIntType>(Size, Signed);
3962+
}
39273963
// ::= Di # char32_t
39283964
case 'i':
39293965
First += 2;

llvm/include/llvm/Demangle/ItaniumNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ NODE(ModuleEntity)
4242
NODE(VectorType)
4343
NODE(PixelVectorType)
4444
NODE(BinaryFPType)
45+
NODE(BitIntType)
4546
NODE(SyntheticTemplateParamName)
4647
NODE(TypeTemplateParamDecl)
4748
NODE(NonTypeTemplateParamDecl)

0 commit comments

Comments
 (0)