llvm-undname: Correctly demangle vararg parameters

FunctionSignatureNode already had an IsVariadic field,
but it wasn't used anywhere yet. Set it and use it.

llvm-svn: 362541
This commit is contained in:
Nico Weber 2019-06-04 19:10:08 +00:00
parent 4638548468
commit 1dce82636c
5 changed files with 17 additions and 9 deletions

View File

@ -177,8 +177,9 @@ private:
ArrayTypeNode *demangleArrayType(StringView &MangledName);
NodeArrayNode *demangleFunctionParameterList(StringView &MangledName,
bool &IsVariadic);
NodeArrayNode *demangleTemplateParameterList(StringView &MangledName);
NodeArrayNode *demangleFunctionParameterList(StringView &MangledName);
std::pair<uint64_t, bool> demangleNumber(StringView &MangledName);
uint64_t demangleUnsigned(StringView &MangledName);

View File

@ -344,7 +344,7 @@ struct FunctionSignatureNode : public TypeNode {
// Function parameters
NodeArrayNode *Params = nullptr;
// True if the function type is noexcept
// True if the function type is noexcept.
bool IsNoexcept = false;
};

View File

@ -1826,7 +1826,7 @@ FunctionSignatureNode *Demangler::demangleFunctionType(StringView &MangledName,
if (!IsStructor)
FTy->ReturnType = demangleType(MangledName, QualifierMangleMode::Result);
FTy->Params = demangleFunctionParameterList(MangledName);
FTy->Params = demangleFunctionParameterList(MangledName, FTy->IsVariadic);
FTy->IsNoexcept = demangleThrowSpecification(MangledName);
@ -2094,8 +2094,8 @@ ArrayTypeNode *Demangler::demangleArrayType(StringView &MangledName) {
}
// Reads a function's parameters.
NodeArrayNode *
Demangler::demangleFunctionParameterList(StringView &MangledName) {
NodeArrayNode *Demangler::demangleFunctionParameterList(StringView &MangledName,
bool &IsVariadic) {
// Empty parameter list.
if (MangledName.consumeFront('X'))
return nullptr;
@ -2152,8 +2152,7 @@ Demangler::demangleFunctionParameterList(StringView &MangledName) {
return NA;
if (MangledName.consumeFront('Z')) {
// This is a variadic parameter list. We probably need a variadic node to
// append to the end.
IsVariadic = true;
return NA;
}

View File

@ -414,6 +414,12 @@ void FunctionSignatureNode::outputPost(OutputStream &OS,
Params->output(OS, Flags);
else
OS << "void";
if (IsVariadic) {
if (OS.back() != '(')
OS << ", ";
OS << "...";
}
OS << ")";
}

View File

@ -39,8 +39,10 @@
; CHECK: void __cdecl x(float, int)
?x@@YAXMHZZ
; FIXME: This should be `(float, int, ...)`
; CHECK: void __cdecl x(float, int)
; CHECK: void __cdecl x(float, int, ...)
?x@@YAXZZ
; CHECK: void __cdecl x(...)
?x@@3P6AHMNH@ZEA
; CHECK: int (__cdecl *x)(float, double, int)