aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2013-04-18 23:34:17 +0000
committerBill Wendling <isanbard@gmail.com>2013-04-18 23:34:17 +0000
commit74d892433d617daa9728f2c52446b2cc2846553f (patch)
tree614cf179cab8292beaca069230d450abcfdc8666 /lib/Transforms/IPO
parentfa2b25c57300dc9c518ea35bbc9dc8658fdbf454 (diff)
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
Diffstat (limited to 'lib/Transforms/IPO')
-rw-r--r--lib/Transforms/IPO/MergeFunctions.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp
index ab31b1a96e..05f68dbcab 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<PointerType>(Ty1) && Ty2 == TD->getIntPtrType(Ctx)) return true;
if (isa<PointerType>(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);