[cfe-commits] r88891 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/virtual-operator-call.cpp test/CodeGenCXX/virtual-pseudo-destructor-call.cpp
Eli Friedman
eli.friedman at gmail.com
Sun Nov 15 21:31:29 PST 2009
Author: efriedma
Date: Sun Nov 15 23:31:29 2009
New Revision: 88891
URL: http://llvm.org/viewvc/llvm-project?rev=88891&view=rev
Log:
Fix a couple of cases where we weren't generating the right kind of call
for a call to a virtual function.
Added:
cfe/trunk/test/CodeGenCXX/virtual-operator-call.cpp
cfe/trunk/test/CodeGenCXX/virtual-pseudo-destructor-call.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=88891&r1=88890&r2=88891&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Sun Nov 15 23:31:29 2009
@@ -282,14 +282,20 @@
// We also don't emit a virtual call if the base expression has a record type
// because then we know what the type is.
llvm::Value *Callee;
- if (MD->isVirtual() && !ME->hasQualifier() &&
- !canDevirtualizeMemberFunctionCalls(ME->getBase()))
- Callee = BuildVirtualCall(MD, This, Ty);
- else if (const CXXDestructorDecl *Destructor
- = dyn_cast<CXXDestructorDecl>(MD))
- Callee = CGM.GetAddrOfFunction(GlobalDecl(Destructor, Dtor_Complete), Ty);
- else
+ if (const CXXDestructorDecl *Destructor
+ = dyn_cast<CXXDestructorDecl>(MD)) {
+ if (MD->isVirtual() && !ME->hasQualifier() &&
+ !canDevirtualizeMemberFunctionCalls(ME->getBase())) {
+ Callee = BuildVirtualCall(Destructor, Dtor_Complete, This, Ty);
+ } else {
+ Callee = CGM.GetAddrOfFunction(GlobalDecl(Destructor, Dtor_Complete), Ty);
+ }
+ } else if (MD->isVirtual() && !ME->hasQualifier() &&
+ !canDevirtualizeMemberFunctionCalls(ME->getBase())) {
+ Callee = BuildVirtualCall(MD, This, Ty);
+ } else {
Callee = CGM.GetAddrOfFunction(MD, Ty);
+ }
return EmitCXXMemberCall(MD, Callee, This,
CE->arg_begin(), CE->arg_end());
@@ -425,10 +431,15 @@
const llvm::Type *Ty =
CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD),
FPT->isVariadic());
- llvm::Constant *Callee = CGM.GetAddrOfFunction(MD, Ty);
llvm::Value *This = EmitLValue(E->getArg(0)).getAddress();
+ llvm::Value *Callee;
+ if (MD->isVirtual() && !canDevirtualizeMemberFunctionCalls(E->getArg(0)))
+ Callee = BuildVirtualCall(MD, This, Ty);
+ else
+ Callee = CGM.GetAddrOfFunction(MD, Ty);
+
return EmitCXXMemberCall(MD, Callee, This,
E->arg_begin() + 1, E->arg_end());
}
Added: cfe/trunk/test/CodeGenCXX/virtual-operator-call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-operator-call.cpp?rev=88891&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virtual-operator-call.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/virtual-operator-call.cpp Sun Nov 15 23:31:29 2009
@@ -0,0 +1,10 @@
+// RUN: clang-cc %s -emit-llvm -o - | FileCheck %s
+
+struct A {
+ virtual int operator-() = 0;
+};
+
+void f(A *a) {
+ // CHECK: call i32 %
+ -*a;
+}
Added: cfe/trunk/test/CodeGenCXX/virtual-pseudo-destructor-call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-pseudo-destructor-call.cpp?rev=88891&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virtual-pseudo-destructor-call.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/virtual-pseudo-destructor-call.cpp Sun Nov 15 23:31:29 2009
@@ -0,0 +1,10 @@
+// RUN: clang-cc %s -emit-llvm -o - | FileCheck %s
+
+struct A {
+ virtual ~A();
+};
+
+void f(A *a) {
+ // CHECK: call void %
+ a->~A();
+}
More information about the cfe-commits
mailing list