mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-10-02 02:55:35 +00:00
CloneFunction: Clone all attributes, including the CC
Summary: Tested with a unit test because we don't appear to have any transforms that use this other than ASan, I think. Fixes PR17935. Reviewers: nicholas CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D3194 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204866 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
899a605fc1
commit
891835ae0f
@ -89,26 +89,28 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
|
|||||||
assert(VMap.count(I) && "No mapping from source argument specified!");
|
assert(VMap.count(I) && "No mapping from source argument specified!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Copy all attributes other than those stored in the AttributeSet. We need
|
||||||
|
// to remap the parameter indices of the AttributeSet.
|
||||||
|
AttributeSet NewAttrs = NewFunc->getAttributes();
|
||||||
|
NewFunc->copyAttributesFrom(OldFunc);
|
||||||
|
NewFunc->setAttributes(NewAttrs);
|
||||||
|
|
||||||
AttributeSet OldAttrs = OldFunc->getAttributes();
|
AttributeSet OldAttrs = OldFunc->getAttributes();
|
||||||
// Clone any argument attributes that are present in the VMap.
|
// Clone any argument attributes that are present in the VMap.
|
||||||
for (Function::const_arg_iterator I = OldFunc->arg_begin(),
|
for (const Argument &OldArg : OldFunc->args())
|
||||||
E = OldFunc->arg_end();
|
if (Argument *NewArg = dyn_cast<Argument>(VMap[&OldArg])) {
|
||||||
I != E; ++I)
|
|
||||||
if (Argument *Anew = dyn_cast<Argument>(VMap[I])) {
|
|
||||||
AttributeSet attrs =
|
AttributeSet attrs =
|
||||||
OldAttrs.getParamAttributes(I->getArgNo() + 1);
|
OldAttrs.getParamAttributes(OldArg.getArgNo() + 1);
|
||||||
if (attrs.getNumSlots() > 0)
|
if (attrs.getNumSlots() > 0)
|
||||||
Anew->addAttr(attrs);
|
NewArg->addAttr(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
NewFunc->setAttributes(NewFunc->getAttributes()
|
NewFunc->setAttributes(
|
||||||
.addAttributes(NewFunc->getContext(),
|
NewFunc->getAttributes()
|
||||||
AttributeSet::ReturnIndex,
|
.addAttributes(NewFunc->getContext(), AttributeSet::ReturnIndex,
|
||||||
OldAttrs.getRetAttributes()));
|
OldAttrs.getRetAttributes())
|
||||||
NewFunc->setAttributes(NewFunc->getAttributes()
|
.addAttributes(NewFunc->getContext(), AttributeSet::FunctionIndex,
|
||||||
.addAttributes(NewFunc->getContext(),
|
OldAttrs.getFnAttributes()));
|
||||||
AttributeSet::FunctionIndex,
|
|
||||||
OldAttrs.getFnAttributes()));
|
|
||||||
|
|
||||||
// Loop over all of the basic blocks in the function, cloning them as
|
// Loop over all of the basic blocks in the function, cloning them as
|
||||||
// appropriate. Note that we save BE this way in order to handle cloning of
|
// appropriate. Note that we save BE this way in order to handle cloning of
|
||||||
|
@ -180,6 +180,29 @@ TEST_F(CloneInstruction, Attributes) {
|
|||||||
delete F2;
|
delete F2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(CloneInstruction, CallingConvention) {
|
||||||
|
Type *ArgTy1[] = { Type::getInt32PtrTy(context) };
|
||||||
|
FunctionType *FT1 = FunctionType::get(Type::getVoidTy(context), ArgTy1, false);
|
||||||
|
|
||||||
|
Function *F1 = Function::Create(FT1, Function::ExternalLinkage);
|
||||||
|
F1->setCallingConv(CallingConv::Cold);
|
||||||
|
BasicBlock *BB = BasicBlock::Create(context, "", F1);
|
||||||
|
IRBuilder<> Builder(BB);
|
||||||
|
Builder.CreateRetVoid();
|
||||||
|
|
||||||
|
Function *F2 = Function::Create(FT1, Function::ExternalLinkage);
|
||||||
|
|
||||||
|
SmallVector<ReturnInst*, 4> Returns;
|
||||||
|
ValueToValueMapTy VMap;
|
||||||
|
VMap[F1->arg_begin()] = F2->arg_begin();
|
||||||
|
|
||||||
|
CloneFunctionInto(F2, F1, VMap, false, Returns);
|
||||||
|
EXPECT_EQ(CallingConv::Cold, F2->getCallingConv());
|
||||||
|
|
||||||
|
delete F1;
|
||||||
|
delete F2;
|
||||||
|
}
|
||||||
|
|
||||||
class CloneFunc : public ::testing::Test {
|
class CloneFunc : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
|
Loading…
Reference in New Issue
Block a user