[cfe-commits] r83816 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/virtual-function-calls.cpp
Anders Carlsson
andersca at mac.com
Sun Oct 11 16:55:53 PDT 2009
Author: andersca
Date: Sun Oct 11 18:55:52 2009
New Revision: 83816
URL: http://llvm.org/viewvc/llvm-project?rev=83816&view=rev
Log:
If the base type of a member call is a record type we don't need to emit a virtual call.
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=83816&r1=83815&r2=83816&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Sun Oct 11 18:55:52 2009
@@ -230,10 +230,13 @@
// 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 @@
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);
Modified: cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp?rev=83816&r1=83815&r2=83816&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp Sun Oct 11 18:55:52 2009
@@ -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 @@
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
More information about the cfe-commits
mailing list