Skip to content

Commit 8280651

Browse files
authored
[llvm] [Demangle] Fix MSVC demangling for placeholder return types (#106178)
Properly demangle `_T` and `_P` return type manglings for MSVC 1920+. Also added a unit test for `@` return type that is used when mangling non-template auto placeholder return type function. Tested the output against the undname shipped with MSVC 19.40.
1 parent 0f77bdd commit 8280651

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ enum class PrimitiveKind {
104104
Double,
105105
Ldouble,
106106
Nullptr,
107+
Auto,
108+
DecltypeAuto,
107109
};
108110

109111
enum class CharKind {

llvm/lib/Demangle/MicrosoftDemangle.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,10 @@ Demangler::demanglePrimitiveType(std::string_view &MangledName) {
20352035
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Char16);
20362036
case 'U':
20372037
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Char32);
2038+
case 'P':
2039+
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Auto);
2040+
case 'T':
2041+
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::DecltypeAuto);
20382042
}
20392043
break;
20402044
}

llvm/lib/Demangle/MicrosoftDemangleNodes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ void PrimitiveTypeNode::outputPre(OutputBuffer &OB, OutputFlags Flags) const {
149149
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Double, "double");
150150
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Ldouble, "long double");
151151
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Nullptr, "std::nullptr_t");
152+
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Auto, "auto");
153+
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, DecltypeAuto, "decltype(auto)");
152154
}
153155
outputQualifiers(OB, Quals, true, false);
154156
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: llvm-undname < %s | FileCheck %s
2+
3+
; CHECK-NOT: Invalid mangled name
4+
5+
?TestNonTemplateAuto@@YA@XZ
6+
; CHECK: __cdecl TestNonTemplateAuto(void)
7+
8+
??$AutoT@X@@YA?A_PXZ
9+
; CHECK: auto __cdecl AutoT<void>(void)
10+
11+
??$AutoT@X@@YA?B_PXZ
12+
; CHECK: auto const __cdecl AutoT<void>(void)
13+
14+
??$AutoT@X@@YA?A_TXZ
15+
; CHECK: decltype(auto) __cdecl AutoT<void>(void)
16+
17+
??$AutoT@X@@YA?B_TXZ
18+
; CHECK: decltype(auto) const __cdecl AutoT<void>(void)

0 commit comments

Comments
 (0)