Pass the right type to GetAddrOfFunction when getting functions for the VTable. Fixes PR5021.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83395 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index 2d5c62e..a119c5a 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -891,7 +891,13 @@
            ++mi)
         if (mi->isVirtual()) {
           const CXXMethodDecl *MD = *mi;
-          llvm::Constant *m = wrap(CGM.GetAddrOfFunction(MD));
+          const FunctionProtoType *FPT = 
+            MD->getType()->getAs<FunctionProtoType>();
+          const llvm::Type *Ty =
+            CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD),
+                                           FPT->isVariadic());
+          
+          llvm::Constant *m = wrap(CGM.GetAddrOfFunction(MD, Ty));
           OverrideMethod(MD, m, MorallyVirtual, Offset);
         }
     }
@@ -901,9 +907,15 @@
     llvm::Constant *m = 0;
     if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(MD))
       m = wrap(CGM.GetAddrOfCXXDestructor(Dtor, Dtor_Complete));
-    else
-      m = wrap(CGM.GetAddrOfFunction(MD));
-
+    else {
+      const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
+      const llvm::Type *Ty =
+        CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD),
+                                       FPT->isVariadic());
+      
+      m = wrap(CGM.GetAddrOfFunction(MD, Ty));
+    }
+    
     // If we can find a previously allocated slot for this, reuse it.
     if (OverrideMethod(MD, m, MorallyVirtual, Offset))
       return;