]> granicus.if.org Git - clang/commitdiff
When emitting member function pointers, use the canonical decl if the member function...
authorAnders Carlsson <andersca@mac.com>
Tue, 5 Jan 2010 05:04:05 +0000 (05:04 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 5 Jan 2010 05:04:05 +0000 (05:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92680 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprAgg.cpp
lib/CodeGen/CGExprConstant.cpp
test/CodeGenCXX/member-function-pointers.cpp

index b95fd799010b232c5d35a09cc06f4e385ef0716f..c852d65b859f2867b42b6b6e2e797632530f8890 100644 (file)
@@ -313,7 +313,8 @@ void AggExprEmitter::VisitUnaryAddrOf(const UnaryOperator *E) {
          "Unexpected member pointer type!");
   
   const DeclRefExpr *DRE = cast<DeclRefExpr>(E->getSubExpr());
-  const CXXMethodDecl *MD = cast<CXXMethodDecl>(DRE->getDecl());
+  const CXXMethodDecl *MD = 
+    cast<CXXMethodDecl>(DRE->getDecl())->getCanonicalDecl();
 
   const llvm::Type *PtrDiffTy = 
     CGF.ConvertType(CGF.getContext().getPointerDiffType());
index 3236d3950e591db035a970a50b977927d87fa7b3..d1330e066ded74512d493488e4c73dbed87bf967 100644 (file)
@@ -408,6 +408,8 @@ public:
   llvm::Constant *EmitMemberFunctionPointer(CXXMethodDecl *MD) {
     assert(MD->isInstance() && "Member function must not be static!");
     
+    MD = MD->getCanonicalDecl();
+
     const llvm::Type *PtrDiffTy = 
       CGM.getTypes().ConvertType(CGM.getContext().getPointerDiffType());
     
index 149b5603ad7ce9d2739f7f0ea1ea4acfb147dc50..2454ddab774a44068f9c91596e22894627557382 100644 (file)
@@ -128,3 +128,14 @@ namespace BoolMemberPointer {
   }
 }
 
+// PR5940
+namespace PR5940 {
+  class foo {
+  public:
+    virtual void baz(void);
+  };
+
+  void foo::baz(void) {
+       void (foo::*ptr)(void) = &foo::baz;
+  }
+}