Don't assume that the LHS and RHS of a member pointer expression is a DeclRefExpr. Fixes PR5177.

llvm-svn: 83986
This commit is contained in:
Anders Carlsson 2009-10-13 17:41:28 +00:00
parent faa0320f27
commit 6bfee8f3e3
2 changed files with 23 additions and 5 deletions

View File

@ -278,10 +278,11 @@ RValue CodeGenFunction::EmitCXXMemberCallExpr(const CXXMemberCallExpr *CE) {
RValue
CodeGenFunction::EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E) {
const BinaryOperator *BO = cast<BinaryOperator>(E->getCallee());
const DeclRefExpr *BaseExpr = cast<DeclRefExpr>(BO->getLHS());
const DeclRefExpr *MemFn = cast<DeclRefExpr>(BO->getRHS());
const Expr *BaseExpr = BO->getLHS();
const Expr *MemFnExpr = BO->getRHS();
const MemberPointerType *MPT = MemFn->getType()->getAs<MemberPointerType>();
const MemberPointerType *MPT =
MemFnExpr->getType()->getAs<MemberPointerType>();
const FunctionProtoType *FPT =
MPT->getPointeeType()->getAs<FunctionProtoType>();
const CXXRecordDecl *RD =
@ -296,8 +297,8 @@ CodeGenFunction::EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E) {
// Get the member function pointer.
llvm::Value *MemFnPtr =
CreateTempAlloca(ConvertType(MemFn->getType()), "mem.fn");
EmitAggExpr(MemFn, MemFnPtr, /*VolatileDest=*/false);
CreateTempAlloca(ConvertType(MemFnExpr->getType()), "mem.fn");
EmitAggExpr(MemFnExpr, MemFnPtr, /*VolatileDest=*/false);
// Emit the 'this' pointer.
llvm::Value *This;

View File

@ -54,3 +54,20 @@ void f3(A *a, A &ar) {
(a->*pa)();
(ar.*pa)();
}
// PR5177
namespace PR5177 {
struct A {
bool foo(int*) const;
} a;
struct B1 {
bool (A::*pmf)(int*) const;
const A* pa;
B1() : pmf(&A::foo), pa(&a) {}
bool operator()() const { return (pa->*pmf)(new int); }
};
void bar(B1 b2) { while (b2()) ; }
}