mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 18:29:46 +00:00
Change CloneFunctionInto to always clone Argument attributes induvidually,
rather than checking if the source and destination have the same number of arguments and copying the attributes over directly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179169 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4d0e8a8a3e
commit
0f57a98a65
@ -87,29 +87,26 @@ 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
|
||||||
|
|
||||||
// Clone any attributes.
|
AttributeSet OldAttrs = OldFunc->getAttributes();
|
||||||
if (NewFunc->arg_size() == OldFunc->arg_size())
|
// Clone any argument attributes that are present in the VMap.
|
||||||
NewFunc->copyAttributesFrom(OldFunc);
|
for (Function::const_arg_iterator I = OldFunc->arg_begin(),
|
||||||
else {
|
E = OldFunc->arg_end();
|
||||||
//Some arguments were deleted with the VMap. Copy arguments one by one
|
I != E; ++I)
|
||||||
for (Function::const_arg_iterator I = OldFunc->arg_begin(),
|
if (Argument *Anew = dyn_cast<Argument>(VMap[I])) {
|
||||||
E = OldFunc->arg_end(); I != E; ++I)
|
AttributeSet attrs =
|
||||||
if (Argument* Anew = dyn_cast<Argument>(VMap[I])) {
|
OldAttrs.getParamAttributes(I->getArgNo() + 1);
|
||||||
AttributeSet attrs = OldFunc->getAttributes()
|
if (attrs.getNumSlots() > 0)
|
||||||
.getParamAttributes(I->getArgNo() + 1);
|
Anew->addAttr(attrs);
|
||||||
if (attrs.getNumSlots() > 0)
|
}
|
||||||
Anew->addAttr(attrs);
|
|
||||||
}
|
|
||||||
NewFunc->setAttributes(NewFunc->getAttributes()
|
|
||||||
.addAttributes(NewFunc->getContext(),
|
|
||||||
AttributeSet::ReturnIndex,
|
|
||||||
OldFunc->getAttributes()));
|
|
||||||
NewFunc->setAttributes(NewFunc->getAttributes()
|
|
||||||
.addAttributes(NewFunc->getContext(),
|
|
||||||
AttributeSet::FunctionIndex,
|
|
||||||
OldFunc->getAttributes()));
|
|
||||||
|
|
||||||
}
|
NewFunc->setAttributes(NewFunc->getAttributes()
|
||||||
|
.addAttributes(NewFunc->getContext(),
|
||||||
|
AttributeSet::ReturnIndex,
|
||||||
|
OldAttrs.getRetAttributes()));
|
||||||
|
NewFunc->setAttributes(NewFunc->getAttributes()
|
||||||
|
.addAttributes(NewFunc->getContext(),
|
||||||
|
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
|
||||||
|
@ -7,12 +7,15 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/IR/Instructions.h"
|
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/ADT/SmallPtrSet.h"
|
#include "llvm/ADT/SmallPtrSet.h"
|
||||||
#include "llvm/IR/Argument.h"
|
#include "llvm/IR/Argument.h"
|
||||||
#include "llvm/IR/Constant.h"
|
#include "llvm/IR/Constant.h"
|
||||||
|
#include "llvm/IR/Function.h"
|
||||||
|
#include "llvm/IR/Instructions.h"
|
||||||
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#include "llvm/IR/LLVMContext.h"
|
#include "llvm/IR/LLVMContext.h"
|
||||||
|
#include "llvm/Transforms/Utils/Cloning.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -143,4 +146,28 @@ TEST_F(CloneInstruction, Exact) {
|
|||||||
EXPECT_TRUE(this->clone(SDiv)->isExact());
|
EXPECT_TRUE(this->clone(SDiv)->isExact());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(CloneInstruction, Attributes) {
|
||||||
|
Type *ArgTy1[] = { Type::getInt32PtrTy(context) };
|
||||||
|
FunctionType *FT1 = FunctionType::get(Type::getVoidTy(context), ArgTy1, false);
|
||||||
|
|
||||||
|
Function *F1 = Function::Create(FT1, Function::ExternalLinkage);
|
||||||
|
BasicBlock *BB = BasicBlock::Create(context, "", F1);
|
||||||
|
IRBuilder<> Builder(BB);
|
||||||
|
Builder.CreateRetVoid();
|
||||||
|
|
||||||
|
Function *F2 = Function::Create(FT1, Function::ExternalLinkage);
|
||||||
|
|
||||||
|
Attribute::AttrKind AK[] = { Attribute::NoCapture };
|
||||||
|
AttributeSet AS = AttributeSet::get(context, 0, AK);
|
||||||
|
Argument *A = F1->arg_begin();
|
||||||
|
A->addAttr(AS);
|
||||||
|
|
||||||
|
SmallVector<ReturnInst*, 4> Returns;
|
||||||
|
ValueToValueMapTy VMap;
|
||||||
|
VMap[A] = UndefValue::get(A->getType());
|
||||||
|
|
||||||
|
CloneFunctionInto(F2, F1, VMap, false, Returns);
|
||||||
|
EXPECT_FALSE(F2->arg_begin()->hasNoCaptureAttr());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user