diff options
Diffstat (limited to 'clang/lib/AST')
-rw-r--r-- | clang/lib/AST/ItaniumMangle.cpp | 16 | ||||
-rw-r--r-- | clang/lib/AST/MicrosoftMangle.cpp | 14 |
2 files changed, 25 insertions, 5 deletions
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index e51aad9ad83..1fcf466a1f6 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -2055,9 +2055,23 @@ void CXXNameMangler::mangleType(const FunctionProtoType *T) { Out << 'E'; } + void CXXNameMangler::mangleType(const FunctionNoProtoType *T) { - llvm_unreachable("Can't mangle K&R function prototypes"); + // Function types without prototypes can arise when mangling a function type + // within an overloadable function in C. We mangle these as the absence of any + // parameter types (not even an empty parameter list). + Out << 'F'; + + FunctionTypeDepthState saved = FunctionTypeDepth.push(); + + FunctionTypeDepth.enterResultType(); + mangleType(T->getReturnType()); + FunctionTypeDepth.leaveResultType(); + + FunctionTypeDepth.pop(saved); + Out << 'E'; } + void CXXNameMangler::mangleBareFunctionType(const FunctionType *T, bool MangleReturnType) { // We should never be mangling something without a prototype. diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index 5c2b68cd62a..a5f75ec0b17 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -1620,7 +1620,8 @@ void MicrosoftCXXNameMangler::mangleType(const FunctionProtoType *T, Qualifiers, } void MicrosoftCXXNameMangler::mangleType(const FunctionNoProtoType *T, Qualifiers, SourceRange) { - llvm_unreachable("Can't mangle K&R function prototypes"); + Out << "$$A6"; + mangleFunctionType(T); } void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T, @@ -1628,7 +1629,7 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T, bool ForceThisQuals) { // <function-type> ::= <this-cvr-qualifiers> <calling-convention> // <return-type> <argument-list> <throw-spec> - const FunctionProtoType *Proto = cast<FunctionProtoType>(T); + const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(T); SourceRange Range; if (D) Range = D->getSourceRange(); @@ -1699,7 +1700,7 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T, } Out << '@'; } else { - QualType ResultType = Proto->getReturnType(); + QualType ResultType = T->getReturnType(); if (const auto *AT = dyn_cast_or_null<AutoType>(ResultType->getContainedAutoType())) { Out << '?'; @@ -1717,7 +1718,12 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T, // <argument-list> ::= X # void // ::= <type>+ @ // ::= <type>* Z # varargs - if (Proto->getNumParams() == 0 && !Proto->isVariadic()) { + if (!Proto) { + // Function types without prototypes can arise when mangling a function type + // within an overloadable function in C. We mangle these as the absence of + // any parameter types (not even an empty parameter list). + Out << '@'; + } else if (Proto->getNumParams() == 0 && !Proto->isVariadic()) { Out << 'X'; } else { // Happens for function pointer type arguments for example. |