We are not able to bitcast a pointer to an integral value.

Two return types are not equivalent if one is a pointer and the other is an
integral. This is because we cannot bitcast a pointer to an integral value.
PR15185


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179569 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp
index 892100f..ab31b1a 100644
--- a/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/lib/Transforms/IPO/MergeFunctions.cpp
@@ -185,7 +185,7 @@
   }
 
   /// Compare two Types, treating all pointer types as equal.
-  bool isEquivalentType(Type *Ty1, Type *Ty2) const;
+  bool isEquivalentType(Type *Ty1, Type *Ty2, bool isReturnType = false) const;
 
   // The two functions undergoing comparison.
   const Function *F1, *F2;
@@ -200,12 +200,12 @@
 
 // Any two pointers in the same address space are equivalent, intptr_t and
 // pointers are equivalent. Otherwise, standard type equivalence rules apply.
-bool FunctionComparator::isEquivalentType(Type *Ty1,
-                                          Type *Ty2) const {
+bool FunctionComparator::isEquivalentType(Type *Ty1, Type *Ty2,
+                                          bool isReturnType) const {
   if (Ty1 == Ty2)
     return true;
   if (Ty1->getTypeID() != Ty2->getTypeID()) {
-    if (TD) {
+    if (TD && !isReturnType) {
       LLVMContext &Ctx = Ty1->getContext();
       if (isa<PointerType>(Ty1) && Ty2 == TD->getIntPtrType(Ctx)) return true;
       if (isa<PointerType>(Ty2) && Ty1 == TD->getIntPtrType(Ctx)) return true;
@@ -261,7 +261,7 @@
         FTy1->isVarArg() != FTy2->isVarArg())
       return false;
 
-    if (!isEquivalentType(FTy1->getReturnType(), FTy2->getReturnType()))
+    if (!isEquivalentType(FTy1->getReturnType(), FTy2->getReturnType(), true))
       return false;
 
     for (unsigned i = 0, e = FTy1->getNumParams(); i != e; ++i) {