[cfe-commits] r72458 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/member-functions.cpp
Anders Carlsson
andersca at mac.com
Tue May 26 21:18:27 PDT 2009
Author: andersca
Date: Tue May 26 23:18:27 2009
New Revision: 72458
URL: http://llvm.org/viewvc/llvm-project?rev=72458&view=rev
Log:
Handle operator call expressions where the callee is a member function.
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGenCXX/member-functions.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=72458&r1=72457&r2=72458&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue May 26 23:18:27 2009
@@ -124,6 +124,25 @@
CE->arg_begin(), CE->arg_end());
}
+RValue
+CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
+ const CXXMethodDecl *MD) {
+ assert(MD->isInstance() &&
+ "Trying to emit a member call expr on a static method!");
+
+
+ const FunctionProtoType *FPT = MD->getType()->getAsFunctionProtoType();
+ const llvm::Type *Ty =
+ CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD),
+ FPT->isVariadic());
+ llvm::Constant *Callee = CGM.GetAddrOfFunction(GlobalDecl(MD), Ty);
+
+ llvm::Value *This = EmitLValue(E->getArg(0)).getAddress();
+
+ return EmitCXXMemberCall(MD, Callee, This,
+ E->arg_begin() + 1, E->arg_end());
+}
+
llvm::Value *CodeGenFunction::LoadCXXThis() {
assert(isa<CXXMethodDecl>(CurFuncDecl) &&
"Must be in a C++ member function decl to load 'this'");
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=72458&r1=72457&r2=72458&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue May 26 23:18:27 2009
@@ -1136,6 +1136,11 @@
}
}
+ if (const CXXOperatorCallExpr *CE = dyn_cast<CXXOperatorCallExpr>(E)) {
+ if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(TargetDecl))
+ return EmitCXXOperatorMemberCallExpr(CE, MD);
+ }
+
llvm::Value *Callee = EmitScalarExpr(E->getCallee());
return EmitCall(Callee, E->getCallee()->getType(),
E->arg_begin(), E->arg_end(), TargetDecl);
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=72458&r1=72457&r2=72458&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue May 26 23:18:27 2009
@@ -686,6 +686,9 @@
CallExpr::const_arg_iterator ArgEnd);
RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E);
+ RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
+ const CXXMethodDecl *MD);
+
RValue EmitBuiltinExpr(const FunctionDecl *FD,
unsigned BuiltinID, const CallExpr *E);
Modified: cfe/trunk/test/CodeGenCXX/member-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/member-functions.cpp?rev=72458&r1=72457&r2=72458&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-functions.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/member-functions.cpp Tue May 26 23:18:27 2009
@@ -37,7 +37,7 @@
static void f();
};
-// RUN: grep "define void @_ZN1S1fEv" %t
+// RUN: grep "define void @_ZN1S1fEv" %t &&
void S::f() {
}
@@ -50,3 +50,14 @@
S::g();
}
+
+struct T {
+ T operator+(const T&);
+};
+
+void test3() {
+ T t1, t2;
+
+ // RUN: grep "call void @_ZN1TpsERK1T" %t
+ T result = t1 + t2;
+}
More information about the cfe-commits
mailing list