When trying to get the most derived class, don't assume that we can ignore all casts. We can only ignore derived-to-base and no-op casts. Fixes selfhost.

llvm-svn: 124528
This commit is contained in:
Anders Carlsson 2011-01-29 05:04:11 +00:00
parent 73c29178ac
commit 6b3afd7df1
2 changed files with 29 additions and 1 deletions

View File

@ -54,7 +54,23 @@ RValue CodeGenFunction::EmitCXXMemberCall(const CXXMethodDecl *MD,
}
static const CXXRecordDecl *getMostDerivedClassDecl(const Expr *Base) {
QualType DerivedType = Base->IgnoreParenCasts()->getType();
const Expr *E = Base;
while (true) {
E = E->IgnoreParens();
if (const CastExpr *CE = dyn_cast<CastExpr>(E)) {
if (CE->getCastKind() == CK_DerivedToBase ||
CE->getCastKind() == CK_UncheckedDerivedToBase ||
CE->getCastKind() == CK_NoOp) {
E = CE->getSubExpr();
continue;
}
}
break;
}
QualType DerivedType = E->getType();
if (const PointerType *PTy = DerivedType->getAs<PointerType>())
DerivedType = PTy->getPointeeType();

View File

@ -36,4 +36,16 @@ namespace Test3 {
// CHECK: call i32 @_ZN5Test31A1fEv
return b->f();
}
// CHECK: define i32 @_ZN5Test31fERNS_1BE
int f(B &b) {
// CHECK: call i32 @_ZN5Test31A1fEv
return b.f();
}
// CHECK: define i32 @_ZN5Test31fEPv
int f(void *v) {
// CHECK: call i32 @_ZN5Test31A1fEv
return static_cast<B*>(v)->f();
}
}