[cfe-commits] r117445 - in /cfe/trunk: lib/CodeGen/CGExprCXX.cpp test/CodeGenCXX/attr-final-devirtualize-virtual-function-calls.cpp
Anders Carlsson
andersca at mac.com
Wed Oct 27 06:34:43 PDT 2010
Author: andersca
Date: Wed Oct 27 08:34:43 2010
New Revision: 117445
URL: http://llvm.org/viewvc/llvm-project?rev=117445&view=rev
Log:
Also devirtualize calls to a member functions where the containing class has been marked final.
Modified:
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/test/CodeGenCXX/attr-final-devirtualize-virtual-function-calls.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=117445&r1=117444&r2=117445&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Wed Oct 27 08:34:43 2010
@@ -59,10 +59,15 @@
const CXXMethodDecl *MD) {
// If the member function has the "final" attribute, we know that it can't be
- // overridden and can therefor devirtualize it.
+ // overridden and can therefore devirtualize it.
if (MD->hasAttr<FinalAttr>())
return true;
-
+
+ // Similarly, if the class itself has the "final" attribute it can't be
+ // overridden and we can therefore devirtualize the member function call.
+ if (MD->getParent()->hasAttr<FinalAttr>())
+ return true;
+
if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Base)) {
if (const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
// This is a record decl. We know the type and can devirtualize it.
Modified: cfe/trunk/test/CodeGenCXX/attr-final-devirtualize-virtual-function-calls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/attr-final-devirtualize-virtual-function-calls.cpp?rev=117445&r1=117444&r2=117445&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/attr-final-devirtualize-virtual-function-calls.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/attr-final-devirtualize-virtual-function-calls.cpp Wed Oct 27 08:34:43 2010
@@ -6,7 +6,19 @@
};
// CHECK: define i32 @_ZN5Test11fEPNS_1AE
- int f(A* a) {
+ int f(A *a) {
+ // CHECK: ret i32 1
+ return a->f();
+ }
+}
+
+namespace Test2 {
+ struct __attribute__((final)) A {
+ virtual int f() { return 1; }
+ };
+
+ // CHECK: define i32 @_ZN5Test21fEPNS_1AE
+ int f(A *a) {
// CHECK: ret i32 1
return a->f();
}
More information about the cfe-commits
mailing list