From 2b77ba8bc7a842829ad9193816dc1d7d5e9c5be6 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 4 Apr 2009 20:47:02 +0000 Subject: Add some basic support for generating C++ member functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68425 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index b4cf533186..379ff9b424 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -820,18 +820,26 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { void CodeGenModule::EmitGlobalFunctionDefinition(const FunctionDecl *D) { - const llvm::FunctionType *Ty = - cast(getTypes().ConvertType(D->getType())); - - // As a special case, make sure that definitions of K&R function - // "type foo()" aren't declared as varargs (which forces the backend - // to do unnecessary work). - if (D->getType()->isFunctionNoProtoType()) { - assert(Ty->isVarArg() && "Didn't lower type as expected"); - // Due to stret, the lowered function could have arguments. Just create the - // same type as was lowered by ConvertType but strip off the varargs bit. - std::vector Args(Ty->param_begin(), Ty->param_end()); - Ty = llvm::FunctionType::get(Ty->getReturnType(), Args, false); + const llvm::FunctionType *Ty; + + if (const CXXMethodDecl *MD = dyn_cast(D)) { + bool isVariadic = D->getType()->getAsFunctionProtoType()->isVariadic(); + + Ty = getTypes().GetFunctionType(getTypes().getFunctionInfo(MD), isVariadic); + } else { + Ty = cast(getTypes().ConvertType(D->getType())); + + // As a special case, make sure that definitions of K&R function + // "type foo()" aren't declared as varargs (which forces the backend + // to do unnecessary work). + if (D->getType()->isFunctionNoProtoType()) { + assert(Ty->isVarArg() && "Didn't lower type as expected"); + // Due to stret, the lowered function could have arguments. + // Just create the same type as was lowered by ConvertType + // but strip off the varargs bit. + std::vector Args(Ty->param_begin(), Ty->param_end()); + Ty = llvm::FunctionType::get(Ty->getReturnType(), Args, false); + } } // Get or create the prototype for teh function. @@ -1305,6 +1313,7 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { return; switch (D->getKind()) { + case Decl::CXXMethod: case Decl::Function: case Decl::Var: EmitGlobal(cast(D)); -- cgit v1.2.3-18-g5258