From 74d892433d617daa9728f2c52446b2cc2846553f Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 18 Apr 2013 23:34:17 +0000 Subject: Implement a better fix for PR15185. If the return type is a pointer and the call returns an integer, then do the inttoptr convertions. And vice versa. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179817 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/MergeFunctions.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp index ab31b1a96e7..05f68dbcabf 100644 --- a/lib/Transforms/IPO/MergeFunctions.cpp +++ b/lib/Transforms/IPO/MergeFunctions.cpp @@ -185,7 +185,7 @@ private: } /// Compare two Types, treating all pointer types as equal. - bool isEquivalentType(Type *Ty1, Type *Ty2, bool isReturnType = false) const; + bool isEquivalentType(Type *Ty1, Type *Ty2) const; // The two functions undergoing comparison. const Function *F1, *F2; @@ -200,12 +200,11 @@ private: // 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, - bool isReturnType) const { +bool FunctionComparator::isEquivalentType(Type *Ty1, Type *Ty2) const { if (Ty1 == Ty2) return true; if (Ty1->getTypeID() != Ty2->getTypeID()) { - if (TD && !isReturnType) { + if (TD) { LLVMContext &Ctx = Ty1->getContext(); if (isa(Ty1) && Ty2 == TD->getIntPtrType(Ctx)) return true; if (isa(Ty2) && Ty1 == TD->getIntPtrType(Ctx)) return true; @@ -261,7 +260,7 @@ bool FunctionComparator::isEquivalentType(Type *Ty1, Type *Ty2, FTy1->isVarArg() != FTy2->isVarArg()) return false; - if (!isEquivalentType(FTy1->getReturnType(), FTy2->getReturnType(), true)) + if (!isEquivalentType(FTy1->getReturnType(), FTy2->getReturnType())) return false; for (unsigned i = 0, e = FTy1->getNumParams(); i != e; ++i) { @@ -740,7 +739,13 @@ void MergeFunctions::writeThunk(Function *F, Function *G) { if (NewG->getReturnType()->isVoidTy()) { Builder.CreateRetVoid(); } else { - Builder.CreateRet(Builder.CreateBitCast(CI, NewG->getReturnType())); + Type *RetTy = NewG->getReturnType(); + if (CI->getType()->isIntegerTy() && RetTy->isPointerTy()) + Builder.CreateRet(Builder.CreateIntToPtr(CI, RetTy)); + else if (CI->getType()->isPointerTy() && RetTy->isIntegerTy()) + Builder.CreateRet(Builder.CreatePtrToInt(CI, RetTy)); + else + Builder.CreateRet(Builder.CreateBitCast(CI, RetTy)); } NewG->copyAttributesFrom(G); -- cgit v1.2.3