aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-04-04 20:47:02 +0000
committerAnders Carlsson <andersca@mac.com>2009-04-04 20:47:02 +0000
commit2b77ba8bc7a842829ad9193816dc1d7d5e9c5be6 (patch)
tree0ff8712562e6dc4c001354842f66513342bb0991 /lib/CodeGen/CodeGenModule.cpp
parent348f28ab6a574df6501ff8b76f9fc6753c155bad (diff)
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
Diffstat (limited to 'lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--lib/CodeGen/CodeGenModule.cpp33
1 files changed, 21 insertions, 12 deletions
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<llvm::FunctionType>(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<const llvm::Type*> 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<CXXMethodDecl>(D)) {
+ bool isVariadic = D->getType()->getAsFunctionProtoType()->isVariadic();
+
+ Ty = getTypes().GetFunctionType(getTypes().getFunctionInfo(MD), isVariadic);
+ } else {
+ Ty = cast<llvm::FunctionType>(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<const llvm::Type*> 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<ValueDecl>(D));