static Value *HandleByValArgument(Value *Arg, Instruction *TheCall,
const Function *CalledFunc,
InlineFunctionInfo &IFI,
- unsigned ByValAlignment) {
+ unsigned ByValAlignment,
+ bool &AddedNewAllocas) {
PointerType *ArgTy = cast<PointerType>(Arg->getType());
Type *AggTy = ArgTy->getElementType();
// Uses of the argument in the function should use our new alloca
// instead.
+ AddedNewAllocas = true;
return NewAlloca;
}
SmallVector<ReturnInst*, 8> Returns;
ClonedCodeInfo InlinedFunctionInfo;
Function::iterator FirstNewBlock;
+ bool AddedNewAllocas = false;
{ // Scope to destroy VMap after cloning.
ValueToValueMapTy VMap;
// modify the struct.
if (CS.isByValArgument(ArgNo)) {
ActualArg = HandleByValArgument(ActualArg, TheCall, CalledFunc, IFI,
- CalledFunc->getParamAlignment(ArgNo+1));
+ CalledFunc->getParamAlignment(ArgNo+1),
+ AddedNewAllocas);
if (ActualArg != *AI)
ByValInit.push_back(std::make_pair(ActualArg, (Value*) *AI));
}
// f -> musttail g -> tail f ==> f -> tail f
// f -> g -> musttail f ==> f -> f
// f -> g -> tail f ==> f -> f
+ //
+ // If an alloca was introduced in the frame due to a byval parameter
+ // being passed to a subsequent call, tail calls must have the tail
+ // stripped as they may not access variables in the caller's stack.
+ // A single alloca ripples through out as the alloca may be aliased by
+ // bitcasts or may escape and be mutated outside of the function.
CallInst::TailCallKind ChildTCK = CI->getTailCallKind();
ChildTCK = std::min(CallSiteTailKind, ChildTCK);
- CI->setTailCallKind(ChildTCK);
+ if (AddedNewAllocas)
+ CI->setTailCallKind(CallInst::TCK_None);
+ else
+ CI->setTailCallKind(ChildTCK);
InlinedMustTailCalls |= CI->isMustTailCall();
// Calls inlined through a 'nounwind' call site should be marked