diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-01-09 21:40:40 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-01-09 21:40:40 +0000 |
commit | 2f63d4612f6e689434f72497e11538fe9139ad28 (patch) | |
tree | c59069bebd0b57240045f7e0b5dedf5860078ab2 /clang/lib/AST/Expr.cpp | |
parent | ba7d95d425d62dc2c9245cf46592bdeaba1c3725 (diff) | |
download | bcm5719-llvm-2f63d4612f6e689434f72497e11538fe9139ad28.tar.gz bcm5719-llvm-2f63d4612f6e689434f72497e11538fe9139ad28.zip |
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
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r-- | clang/lib/AST/Expr.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 93f3ad5f2bd..edb218871ab 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -562,8 +562,7 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { 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 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { 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 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { 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()) |