forked from OSchip/llvm-project
[NFC] Replace Function handling of attributes with less confusing calls
To avoid magic constants and confusing indexes.
This commit is contained in:
parent
b41bfb819d
commit
46cf82532c
|
@ -2118,7 +2118,7 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
|
|||
F->arg_begin()->getType()
|
||||
->canLosslesslyBitCastTo(F->getReturnType()) &&
|
||||
"unexpected this return");
|
||||
F->addAttribute(1, llvm::Attribute::Returned);
|
||||
F->addParamAttr(0, llvm::Attribute::Returned);
|
||||
}
|
||||
|
||||
// Only a few attributes are set on declarations; these may later be
|
||||
|
@ -2144,15 +2144,13 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
|
|||
assert(HasBody && "Inline builtin declarations should always have an "
|
||||
"available body!");
|
||||
if (shouldEmitFunction(FDBody))
|
||||
F->addAttribute(llvm::AttributeList::FunctionIndex,
|
||||
llvm::Attribute::NoBuiltin);
|
||||
F->addFnAttr(llvm::Attribute::NoBuiltin);
|
||||
}
|
||||
|
||||
if (FD->isReplaceableGlobalAllocationFunction()) {
|
||||
// A replaceable global allocation function does not act like a builtin by
|
||||
// default, only if it is invoked by a new-expression or delete-expression.
|
||||
F->addAttribute(llvm::AttributeList::FunctionIndex,
|
||||
llvm::Attribute::NoBuiltin);
|
||||
F->addFnAttr(llvm::Attribute::NoBuiltin);
|
||||
}
|
||||
|
||||
if (isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD))
|
||||
|
|
|
@ -251,6 +251,11 @@ public:
|
|||
/// Set the attribute list for this Function.
|
||||
void setAttributes(AttributeList Attrs) { AttributeSets = Attrs; }
|
||||
|
||||
/// Add return value attributes to this function.
|
||||
void addRetAttr(Attribute::AttrKind Kind) {
|
||||
addAttribute(AttributeList::ReturnIndex, Kind);
|
||||
}
|
||||
|
||||
/// Add function attributes to this function.
|
||||
void addFnAttr(Attribute::AttrKind Kind) {
|
||||
addAttribute(AttributeList::FunctionIndex, Kind);
|
||||
|
|
|
@ -2502,7 +2502,7 @@ void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
|
|||
const char *V) {
|
||||
Function *Func = unwrap<Function>(Fn);
|
||||
Attribute Attr = Attribute::get(Func->getContext(), A, V);
|
||||
Func->addAttribute(AttributeList::FunctionIndex, Attr);
|
||||
Func->addFnAttr(Attr);
|
||||
}
|
||||
|
||||
/*--.. Operations on parameters ............................................--*/
|
||||
|
|
|
@ -17744,7 +17744,7 @@ void AArch64TargetLowering::insertSSPDeclarations(Module &M) const {
|
|||
Type::getInt8PtrTy(M.getContext()));
|
||||
if (Function *F = dyn_cast<Function>(SecurityCheckCookie.getCallee())) {
|
||||
F->setCallingConv(CallingConv::Win64);
|
||||
F->addAttribute(1, Attribute::AttrKind::InReg);
|
||||
F->addParamAttr(0, Attribute::AttrKind::InReg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -20371,7 +20371,7 @@ void ARMTargetLowering::insertSSPDeclarations(Module &M) const {
|
|||
"__security_check_cookie", Type::getVoidTy(M.getContext()),
|
||||
Type::getInt8PtrTy(M.getContext()));
|
||||
if (Function *F = dyn_cast<Function>(SecurityCheckCookie.getCallee()))
|
||||
F->addAttribute(1, Attribute::AttrKind::InReg);
|
||||
F->addParamAttr(0, Attribute::AttrKind::InReg);
|
||||
}
|
||||
|
||||
Value *ARMTargetLowering::getSDagStackGuard(const Module &M) const {
|
||||
|
|
|
@ -2714,7 +2714,7 @@ void X86TargetLowering::insertSSPDeclarations(Module &M) const {
|
|||
Type::getInt8PtrTy(M.getContext()));
|
||||
if (Function *F = dyn_cast<Function>(SecurityCheckCookie.getCallee())) {
|
||||
F->setCallingConv(CallingConv::X86_FastCall);
|
||||
F->addAttribute(1, Attribute::AttrKind::InReg);
|
||||
F->addParamAttr(0, Attribute::AttrKind::InReg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1076,7 +1076,7 @@ static bool addNonNullAttrs(const SCCNodeSet &SCCNodes) {
|
|||
// which prevents us from speculating about the entire SCC
|
||||
LLVM_DEBUG(dbgs() << "Eagerly marking " << F->getName()
|
||||
<< " as nonnull\n");
|
||||
F->addAttribute(AttributeList::ReturnIndex, Attribute::NonNull);
|
||||
F->addRetAttr(Attribute::NonNull);
|
||||
++NumNonNullReturn;
|
||||
MadeChange = true;
|
||||
}
|
||||
|
@ -1094,7 +1094,7 @@ static bool addNonNullAttrs(const SCCNodeSet &SCCNodes) {
|
|||
continue;
|
||||
|
||||
LLVM_DEBUG(dbgs() << "SCC marking " << F->getName() << " as nonnull\n");
|
||||
F->addAttribute(AttributeList::ReturnIndex, Attribute::NonNull);
|
||||
F->addRetAttr(Attribute::NonNull);
|
||||
++NumNonNullReturn;
|
||||
MadeChange = true;
|
||||
}
|
||||
|
|
|
@ -1288,7 +1288,7 @@ void DevirtModule::tryICallBranchFunnel(
|
|||
M.getDataLayout().getProgramAddressSpace(),
|
||||
"branch_funnel", &M);
|
||||
}
|
||||
JT->addAttribute(1, Attribute::Nest);
|
||||
JT->addParamAttr(0, Attribute::Nest);
|
||||
|
||||
std::vector<Value *> JTArgs;
|
||||
JTArgs.push_back(JT->arg_begin());
|
||||
|
|
|
@ -2133,8 +2133,7 @@ Instruction *ModuleAddressSanitizer::CreateAsanModuleDtor(Module &M) {
|
|||
AsanDtorFunction = Function::createWithDefaultAttr(
|
||||
FunctionType::get(Type::getVoidTy(*C), false),
|
||||
GlobalValue::InternalLinkage, 0, kAsanModuleDtorName, &M);
|
||||
AsanDtorFunction->addAttribute(AttributeList::FunctionIndex,
|
||||
Attribute::NoUnwind);
|
||||
AsanDtorFunction->addFnAttr(Attribute::NoUnwind);
|
||||
// Ensure Dtor cannot be discarded, even if in a comdat.
|
||||
appendToUsed(M, {AsanDtorFunction});
|
||||
BasicBlock *AsanDtorBB = BasicBlock::Create(*C, "", AsanDtorFunction);
|
||||
|
|
|
@ -98,7 +98,7 @@ static bool setDoesNotThrow(Function &F) {
|
|||
static bool setRetDoesNotAlias(Function &F) {
|
||||
if (F.hasRetAttribute(Attribute::NoAlias))
|
||||
return false;
|
||||
F.addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
|
||||
F.addRetAttr(Attribute::NoAlias);
|
||||
++NumNoAlias;
|
||||
return true;
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ static bool setSignExtendedArg(Function &F, unsigned ArgNo) {
|
|||
static bool setRetNoUndef(Function &F) {
|
||||
if (!F.getReturnType()->isVoidTy() &&
|
||||
!F.hasRetAttribute(Attribute::NoUndef)) {
|
||||
F.addAttribute(AttributeList::ReturnIndex, Attribute::NoUndef);
|
||||
F.addRetAttr(Attribute::NoUndef);
|
||||
++NumNoUndef;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ Function *llvm::createSanitizerCtor(Module &M, StringRef CtorName) {
|
|||
Function *Ctor = Function::createWithDefaultAttr(
|
||||
FunctionType::get(Type::getVoidTy(M.getContext()), false),
|
||||
GlobalValue::InternalLinkage, 0, CtorName, &M);
|
||||
Ctor->addAttribute(AttributeList::FunctionIndex, Attribute::NoUnwind);
|
||||
Ctor->addFnAttr(Attribute::NoUnwind);
|
||||
BasicBlock *CtorBB = BasicBlock::Create(M.getContext(), "", Ctor);
|
||||
ReturnInst::Create(M.getContext(), CtorBB);
|
||||
// Ensure Ctor cannot be discarded, even if in a comdat.
|
||||
|
|
Loading…
Reference in New Issue