PR31587: Fix handling of __FUNCSIG__ in C.
Fix crash if __FUNCSIG__ is used in a function without a prototype, and use
"(void)" as parameter list instead of "()" for a function with a no-parameters
prototype, matching MSVC's observed behavior.
llvm-svn: 291484
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 93f3ad5..edb2188 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -562,8 +562,7 @@
FT = dyn_cast<FunctionProtoType>(AFT);
if (IT == FuncSig) {
- assert(FT && "We must have a written prototype in this case.");
- switch (FT->getCallConv()) {
+ switch (AFT->getCallConv()) {
case CC_C: POut << "__cdecl "; break;
case CC_X86StdCall: POut << "__stdcall "; break;
case CC_X86FastCall: POut << "__fastcall "; break;
@@ -583,6 +582,8 @@
if (i) POut << ", ";
POut << Decl->getParamDecl(i)->getType().stream(Policy);
}
+ if (!Context.getLangOpts().CPlusPlus && !Decl->getNumParams())
+ POut << "void";
if (FT->isVariadic()) {
if (FD->getNumParams()) POut << ", ";
@@ -592,7 +593,7 @@
POut << ")";
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
- const FunctionType *FT = MD->getType()->castAs<FunctionType>();
+ assert(FT && "We must have a written prototype in this case.");
if (FT->isConst())
POut << " const";
if (FT->isVolatile())