summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/AutoUpgrade.cpp
diff options
context:
space:
mode:
authorAkira Hatanaka <ahatanaka@apple.com>2019-10-23 07:38:52 -0700
committerAkira Hatanaka <ahatanaka@apple.com>2019-10-24 13:08:50 -0700
commit31b752cbf0db5a022ec21a9db5bd217c46f5cf4a (patch)
tree76618234e9e11eeeff15dbf2052776316a4356dc /llvm/lib/IR/AutoUpgrade.cpp
parenta5376f6322132e3b0664de55348f6bbba1fabd00 (diff)
downloadbcm5719-llvm-31b752cbf0db5a022ec21a9db5bd217c46f5cf4a.tar.gz
bcm5719-llvm-31b752cbf0db5a022ec21a9db5bd217c46f5cf4a.zip
[ObjC][ARC] Check whether the return and parameter types of the old and
new functions are compatible before upgrading a function call to an intrinsic call. Sometimes users insert calls to ARC runtime functions that are not compatible with the corresponding intrinsic functions (for example, 'i8* @objc_storeStrong' instead of 'void @objc_storeStrong'). Don't upgrade those calls. rdar://problem/56447127
Diffstat (limited to 'llvm/lib/IR/AutoUpgrade.cpp')
-rw-r--r--llvm/lib/IR/AutoUpgrade.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 79f580d0e14..d2dd2a69bea 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -3877,15 +3877,36 @@ void llvm::UpgradeARCRuntime(Module &M) {
FunctionType *NewFuncTy = NewFn->getFunctionType();
SmallVector<Value *, 2> Args;
+ // Don't upgrade the intrinsic if it's not valid to bitcast the return
+ // value to the return type of the old function.
+ if (NewFuncTy->getReturnType() != CI->getType() &&
+ !CastInst::castIsValid(Instruction::BitCast, CI,
+ NewFuncTy->getReturnType()))
+ continue;
+
+ bool InvalidCast = false;
+
for (unsigned I = 0, E = CI->getNumArgOperands(); I != E; ++I) {
Value *Arg = CI->getArgOperand(I);
+
// Bitcast argument to the parameter type of the new function if it's
// not a variadic argument.
- if (I < NewFuncTy->getNumParams())
+ if (I < NewFuncTy->getNumParams()) {
+ // Don't upgrade the intrinsic if it's not valid to bitcast the argument
+ // to the parameter type of the new function.
+ if (!CastInst::castIsValid(Instruction::BitCast, Arg,
+ NewFuncTy->getParamType(I))) {
+ InvalidCast = true;
+ break;
+ }
Arg = Builder.CreateBitCast(Arg, NewFuncTy->getParamType(I));
+ }
Args.push_back(Arg);
}
+ if (InvalidCast)
+ continue;
+
// Create a call instruction that calls the new function.
CallInst *NewCall = Builder.CreateCall(NewFuncTy, NewFn, Args);
NewCall->setTailCallKind(cast<CallInst>(CI)->getTailCallKind());
OpenPOWER on IntegriCloud