diff options
author | Anders Carlsson <andersca@mac.com> | 2009-10-11 23:55:52 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-10-11 23:55:52 +0000 |
commit | 3b89f3fa61b65b73f58808c037826c8333830313 (patch) | |
tree | 8ea5139ea3de768ab4fdcc7b423487128c9c08e0 /lib/CodeGen/CGCXX.cpp | |
parent | 7a9474e0251127e0e7d706cfca252632eb68786d (diff) |
If the base type of a member call is a record type we don't need to emit a virtual call.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83816 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCXX.cpp')
-rw-r--r-- | lib/CodeGen/CGCXX.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index ceb6e4927f..af49942738 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -230,10 +230,13 @@ RValue CodeGenFunction::EmitCXXMemberCallExpr(const CXXMemberCallExpr *CE) { // C++ [class.virtual]p12: // Explicit qualification with the scope operator (5.1) suppresses the // virtual call mechanism. + // + // 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()) - // FIXME: push getCanonicalDecl as a conversion using the static type system (CanCXXMethodDecl). - Callee = BuildVirtualCall(MD->getCanonicalDecl(), This, Ty); + if (MD->isVirtual() && !ME->hasQualifier() && + !ME->getBase()->getType()->isRecordType()) + Callee = BuildVirtualCall(MD, This, Ty); else if (const CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(MD)) Callee = CGM.GetAddrOfFunction(GlobalDecl(Destructor, Dtor_Complete), Ty); @@ -795,8 +798,6 @@ CodeGenFunction::GetVirtualCXXBaseClassOffset(llvm::Value *This, llvm::Value * CodeGenFunction::BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *&This, const llvm::Type *Ty) { - // FIXME: If we know the dynamic type, we don't have to do a virtual dispatch. - int64_t Index = CGM.getVtableInfo().getMethodVtableIndex(MD); Ty = llvm::PointerType::get(Ty, 0); |