summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-10-11 23:55:52 +0000
committerAnders Carlsson <andersca@mac.com>2009-10-11 23:55:52 +0000
commitb5296558f10cbc34544e9e2baa6e42524b826ed1 (patch)
treecc46316f3e5fef9512159541df136ff1af7c73e9
parent2caacfa7e10075583e86e21016b327a0027bbffc (diff)
downloadbcm5719-llvm-b5296558f10cbc34544e9e2baa6e42524b826ed1.tar.gz
bcm5719-llvm-b5296558f10cbc34544e9e2baa6e42524b826ed1.zip
If the base type of a member call is a record type we don't need to emit a virtual call.
llvm-svn: 83816
-rw-r--r--clang/lib/CodeGen/CGCXX.cpp11
-rw-r--r--clang/test/CodeGenCXX/virtual-function-calls.cpp9
2 files changed, 14 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp
index ceb6e4927f0..af499427387 100644
--- a/clang/lib/CodeGen/CGCXX.cpp
+++ b/clang/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);
diff --git a/clang/test/CodeGenCXX/virtual-function-calls.cpp b/clang/test/CodeGenCXX/virtual-function-calls.cpp
index e3a19a34a16..34ab1df6896 100644
--- a/clang/test/CodeGenCXX/virtual-function-calls.cpp
+++ b/clang/test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-cc -emit-llvm-only %s
+// RUN: clang-cc %s -emit-llvm -o - | FileCheck %s
// PR5021
struct A {
@@ -8,3 +8,10 @@ struct A {
void f(A *a) {
a->f('c');
}
+
+void f(A a) {
+ // This should not be a virtual function call.
+
+ // CHECK: call void @_ZN1A1fEc
+ a.f('c');
+} \ No newline at end of file
OpenPOWER on IntegriCloud