forked from OSchip/llvm-project
Also devirtualize calls to a member functions where the containing class has been marked final.
llvm-svn: 117445
This commit is contained in:
parent
a7911fa3d7
commit
b00c2144b3
|
@ -59,10 +59,15 @@ static bool canDevirtualizeMemberFunctionCalls(const Expr *Base,
|
|||
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.
|
||||
|
|
|
@ -6,7 +6,19 @@ namespace Test1 {
|
|||
};
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue