[cfe-commits] r83986 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/member-function-pointers.cpp

Anders Carlsson andersca at mac.com
Tue Oct 13 10:41:28 PDT 2009


Author: andersca
Date: Tue Oct 13 12:41:28 2009
New Revision: 83986

URL: http://llvm.org/viewvc/llvm-project?rev=83986&view=rev
Log:
Don't assume that the LHS and RHS of a member pointer expression is a DeclRefExpr. Fixes PR5177.

Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=83986&r1=83985&r2=83986&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Oct 13 12:41:28 2009
@@ -278,10 +278,11 @@
 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 @@
 
   // 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;

Modified: cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp?rev=83986&r1=83985&r2=83986&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp Tue Oct 13 12:41:28 2009
@@ -54,3 +54,20 @@
   (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()) ; }
+}





More information about the cfe-commits mailing list