Index: include/llvm/Demangle/ItaniumDemangle.h =================================================================== --- include/llvm/Demangle/ItaniumDemangle.h +++ include/llvm/Demangle/ItaniumDemangle.h @@ -637,7 +637,7 @@ NodeOrString Dimension; public: - ArrayType(const Node *Base_, NodeOrString Dimension_ = NodeOrString()) + ArrayType(const Node *Base_, NodeOrString Dimension_) : Node(KArrayType, /*RHSComponentCache=*/Cache::Yes, /*ArrayCache=*/Cache::Yes), @@ -1360,12 +1360,14 @@ class CtorDtorName final : public Node { const Node *Basename; const bool IsDtor; + const int Variant; public: - CtorDtorName(const Node *Basename_, bool IsDtor_) - : Node(KCtorDtorName), Basename(Basename_), IsDtor(IsDtor_) {} + CtorDtorName(const Node *Basename_, bool IsDtor_, int Variant_) + : Node(KCtorDtorName), Basename(Basename_), IsDtor(IsDtor_), + Variant(Variant_) {} - template void match(Fn F) const { F(Basename, IsDtor); } + template void match(Fn F) const { F(Basename, IsDtor, Variant); } void printLeft(OutputStream &S) const override { if (IsDtor) @@ -2800,20 +2802,22 @@ bool IsInherited = consumeIf('I'); if (look() != '1' && look() != '2' && look() != '3' && look() != '5') return nullptr; + int Variant = look() - '0'; ++First; if (State) State->CtorDtorConversion = true; if (IsInherited) { if (parseName(State) == nullptr) return nullptr; } - return make(SoFar, false); + return make(SoFar, false, Variant); } if (look() == 'D' && (look(1) == '0' || look(1) == '1' || look(1) == '2' || look(1) == '5')) { + int Variant = look(1) - '0'; First += 2; if (State) State->CtorDtorConversion = true; - return make(SoFar, true); + return make(SoFar, true, Variant); } return nullptr; @@ -3292,32 +3296,25 @@ if (!consumeIf('A')) return nullptr; + NodeOrString Dimension; + if (std::isdigit(look())) { - StringView Dimension = parseNumber(); + Dimension = parseNumber(); if (!consumeIf('_')) return nullptr; - Node *Ty = parseType(); - if (Ty == nullptr) - return nullptr; - return make(Ty, Dimension); - } - - if (!consumeIf('_')) { + } else if (!consumeIf('_')) { Node *DimExpr = parseExpr(); if (DimExpr == nullptr) return nullptr; if (!consumeIf('_')) return nullptr; - Node *ElementType = parseType(); - if (ElementType == nullptr) - return nullptr; - return make(ElementType, DimExpr); + Dimension = DimExpr; } Node *Ty = parseType(); if (Ty == nullptr) return nullptr; - return make(Ty); + return make(Ty, Dimension); } // ::= M Index: unittests/Support/ItaniumManglingCanonicalizerTest.cpp =================================================================== --- unittests/Support/ItaniumManglingCanonicalizerTest.cpp +++ unittests/Support/ItaniumManglingCanonicalizerTest.cpp @@ -233,6 +233,23 @@ }, {} }, + + // Check that ctor and dtor variants are considered distinct. + { + {}, + {{"_ZN1XC1Ev"}, {"_ZN1XC2Ev"}, {"_ZN1XD1Ev"}, {"_ZN1XD2Ev"}} + }, + + // Ensure array types with and without bounds are handled properly. + { + { + {FragmentKind::Type, "A_i", "A1_f"}, + }, + { + {"_Z1fRA_i", "_Z1fRA_i", "_Z1fRA1_f"}, + {"_Z1fRA1_i"}, {"_Z1fRA_f"}, + } + }, }; }