return Attrs;
llvm::Attribute AlignAttr = llvm::Attribute::getWithAlignment(Ctx, NewAlign);
return Attrs.removeRetAttribute(Ctx, llvm::Attribute::AttrKind::Alignment)
- .addAttribute(Ctx, llvm::AttributeList::ReturnIndex, AlignAttr);
+ .addRetAttribute(Ctx, AlignAttr);
}
template <typename AlignedAttrTy> class AbstractAssumeAlignedAttrEmitter {
if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurFuncDecl))
if (FD->hasAttr<StrictFPAttr>())
// All calls within a strictfp function are marked strictfp
- Attrs =
- Attrs.addAttribute(getLLVMContext(), llvm::AttributeList::FunctionIndex,
- llvm::Attribute::StrictFP);
+ Attrs = Attrs.addFnAttribute(getLLVMContext(), llvm::Attribute::StrictFP);
// Add call-site nomerge attribute if exists.
if (InNoMergeAttributedStmt)
- Attrs =
- Attrs.addAttribute(getLLVMContext(), llvm::AttributeList::FunctionIndex,
- llvm::Attribute::NoMerge);
+ Attrs = Attrs.addFnAttribute(getLLVMContext(), llvm::Attribute::NoMerge);
// Apply some call-site-specific attributes.
// TODO: work this into building the attribute set.
if (CurCodeDecl && CurCodeDecl->hasAttr<FlattenAttr>() &&
!(TargetDecl && TargetDecl->hasAttr<NoInlineAttr>())) {
Attrs =
- Attrs.addAttribute(getLLVMContext(), llvm::AttributeList::FunctionIndex,
- llvm::Attribute::AlwaysInline);
+ Attrs.addFnAttribute(getLLVMContext(), llvm::Attribute::AlwaysInline);
}
// Disable inlining inside SEH __try blocks.
if (isSEHTryScope()) {
- Attrs =
- Attrs.addAttribute(getLLVMContext(), llvm::AttributeList::FunctionIndex,
- llvm::Attribute::NoInline);
+ Attrs = Attrs.addFnAttribute(getLLVMContext(), llvm::Attribute::NoInline);
}
// Decide whether to use a call or an invoke.
if (const auto *FD = dyn_cast_or_null<FunctionDecl>(CurFuncDecl)) {
if (const auto *A = FD->getAttr<CFGuardAttr>()) {
if (A->getGuard() == CFGuardAttr::GuardArg::nocf && !CI->getCalledFunction())
- Attrs = Attrs.addAttribute(
- getLLVMContext(), llvm::AttributeList::FunctionIndex, "guard_nocf");
+ Attrs = Attrs.addFnAttribute(getLLVMContext(), "guard_nocf");
}
}
bool AssumeConvergent) {
if (AssumeConvergent) {
ExtraAttrs =
- ExtraAttrs.addAttribute(VMContext, llvm::AttributeList::FunctionIndex,
- llvm::Attribute::Convergent);
+ ExtraAttrs.addFnAttribute(VMContext, llvm::Attribute::Convergent);
}
llvm::Constant *C =
return addAttribute(C, ReturnIndex, Kind);
}
+ /// Add a return value attribute to the list. Returns a new list because
+ /// attribute lists are immutable.
+ LLVM_NODISCARD AttributeList addRetAttribute(LLVMContext &C,
+ Attribute Attr) const {
+ return addAttribute(C, ReturnIndex, Attr);
+ }
+
+ /// Add a return value attribute to the list. Returns a new list because
+ /// attribute lists are immutable.
+ LLVM_NODISCARD AttributeList addRetAttributes(LLVMContext &C,
+ const AttrBuilder &B) const {
+ return addAttributes(C, ReturnIndex, B);
+ }
+
/// Add an argument attribute to the list. Returns a new list because
/// attribute lists are immutable.
LLVM_NODISCARD AttributeList addParamAttribute(
FnAttrs.removeAttribute(Attribute::Alignment);
}
- AS = AS.addAttributes(Context, AttributeList::FunctionIndex,
- AttributeSet::get(Context, FnAttrs));
+ AS = AS.addFnAttributes(Context, AttributeSet::get(Context, FnAttrs));
Fn->setAttributes(AS);
} else if (CallInst *CI = dyn_cast<CallInst>(V)) {
AttributeList AS = CI->getAttributes();
AttrBuilder FnAttrs(AS.getFnAttrs());
AS = AS.removeAttributes(Context, AttributeList::FunctionIndex);
FnAttrs.merge(B);
- AS = AS.addAttributes(Context, AttributeList::FunctionIndex,
- AttributeSet::get(Context, FnAttrs));
+ AS = AS.addFnAttributes(Context, AttributeSet::get(Context, FnAttrs));
CI->setAttributes(AS);
} else if (InvokeInst *II = dyn_cast<InvokeInst>(V)) {
AttributeList AS = II->getAttributes();
AttrBuilder FnAttrs(AS.getFnAttrs());
AS = AS.removeAttributes(Context, AttributeList::FunctionIndex);
FnAttrs.merge(B);
- AS = AS.addAttributes(Context, AttributeList::FunctionIndex,
- AttributeSet::get(Context, FnAttrs));
+ AS = AS.addFnAttributes(Context, AttributeSet::get(Context, FnAttrs));
II->setAttributes(AS);
} else if (CallBrInst *CBI = dyn_cast<CallBrInst>(V)) {
AttributeList AS = CBI->getAttributes();
AttrBuilder FnAttrs(AS.getFnAttrs());
AS = AS.removeAttributes(Context, AttributeList::FunctionIndex);
FnAttrs.merge(B);
- AS = AS.addAttributes(Context, AttributeList::FunctionIndex,
- AttributeSet::get(Context, FnAttrs));
+ AS = AS.addFnAttributes(Context, AttributeSet::get(Context, FnAttrs));
CBI->setAttributes(AS);
} else if (auto *GV = dyn_cast<GlobalVariable>(V)) {
AttrBuilder Attrs(GV->getAttributes());
// Now, the return type.
if (CASExpected) {
ResultTy = Type::getInt1Ty(Ctx);
- Attr = Attr.addAttribute(Ctx, AttributeList::ReturnIndex, Attribute::ZExt);
+ Attr = Attr.addRetAttribute(Ctx, Attribute::ZExt);
} else if (HasResult && UseSizedLibcall)
ResultTy = SizedIntTy;
else
Attribute::get(Ctx, "trap-func-name", getTrapFuncName()));
// Let NewAttrs override Attrs.
- F.setAttributes(
- Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs));
+ F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs));
}
/// Set function attributes of functions in Module M based on CPU,
for (auto &F : *Mod) {
auto Attrs = F.getAttributes();
StringRef Value = options.NoFramePointerElim ? "all" : "none";
- Attrs = Attrs.addAttribute(F.getContext(), AttributeList::FunctionIndex,
- "frame-pointer", Value);
+ Attrs = Attrs.addFnAttribute(F.getContext(), "frame-pointer", Value);
F.setAttributes(Attrs);
}
} else {
AttributeList Attr;
LLVMContext &Ctx = M->getContext();
- Attr = Attr.addAttribute(Ctx, AttributeList::FunctionIndex,
- Attribute::ReadOnly);
- Attr = Attr.addAttribute(Ctx, AttributeList::FunctionIndex,
- Attribute::NoUnwind);
+ Attr = Attr.addFnAttribute(Ctx, Attribute::ReadOnly);
+ Attr = Attr.addFnAttribute(Ctx, Attribute::NoUnwind);
C = M->getOrInsertFunction(FuncName, FuncTy, Attr);
}
// during call setup, the proper call lowering to the helper
// functions will take place.
//
- A = A.addAttribute(C, AttributeList::FunctionIndex,
- "__Mips16RetHelper");
- A = A.addAttribute(C, AttributeList::FunctionIndex,
- Attribute::ReadNone);
- A = A.addAttribute(C, AttributeList::FunctionIndex,
- Attribute::NoInline);
+ A = A.addFnAttribute(C, "__Mips16RetHelper");
+ A = A.addFnAttribute(C, Attribute::ReadNone);
+ A = A.addFnAttribute(C, Attribute::NoInline);
FunctionCallee F = (M->getOrInsertFunction(Name, A, MyVoid, T));
CallInst::Create(F, Params, "", &I);
} else if (const CallInst *CI = dyn_cast<CallInst>(&I)) {
case coro::ABI::Switch:
// Bootstrap attributes by copying function attributes from the
// original function. This should include optimization settings and so on.
- NewAttrs = NewAttrs.addAttributes(Context, AttributeList::FunctionIndex,
- OrigAttrs.getFnAttrs());
+ NewAttrs = NewAttrs.addFnAttributes(Context, OrigAttrs.getFnAttrs());
addFramePointerAttrs(NewAttrs, Context, 0,
Shape.FrameSize, Shape.FrameAlign);
// Transfer the original function's attributes.
auto FnAttrs = OrigF.getAttributes().getFnAttrs();
- NewAttrs =
- NewAttrs.addAttributes(Context, AttributeList::FunctionIndex, FnAttrs);
+ NewAttrs = NewAttrs.addFnAttributes(Context, FnAttrs);
break;
}
case coro::ABI::Retcon:
void DataFlowSanitizer::initializeRuntimeFunctions(Module &M) {
{
AttributeList AL;
- AL = AL.addAttribute(M.getContext(), AttributeList::FunctionIndex,
- Attribute::NoUnwind);
- AL = AL.addAttribute(M.getContext(), AttributeList::FunctionIndex,
- Attribute::ReadOnly);
- AL = AL.addAttribute(M.getContext(), AttributeList::ReturnIndex,
- Attribute::ZExt);
+ AL = AL.addFnAttribute(M.getContext(), Attribute::NoUnwind);
+ AL = AL.addFnAttribute(M.getContext(), Attribute::ReadOnly);
+ AL = AL.addRetAttribute(M.getContext(), Attribute::ZExt);
DFSanUnionLoadFn =
Mod->getOrInsertFunction("__dfsan_union_load", DFSanUnionLoadFnTy, AL);
}
{
AttributeList AL;
- AL = AL.addAttribute(M.getContext(), AttributeList::FunctionIndex,
- Attribute::NoUnwind);
- AL = AL.addAttribute(M.getContext(), AttributeList::FunctionIndex,
- Attribute::ReadOnly);
- AL = AL.addAttribute(M.getContext(), AttributeList::ReturnIndex,
- Attribute::ZExt);
+ AL = AL.addFnAttribute(M.getContext(), Attribute::NoUnwind);
+ AL = AL.addFnAttribute(M.getContext(), Attribute::ReadOnly);
+ AL = AL.addRetAttribute(M.getContext(), Attribute::ZExt);
DFSanLoadLabelAndOriginFn = Mod->getOrInsertFunction(
"__dfsan_load_label_and_origin", DFSanLoadLabelAndOriginFnTy, AL);
}
{
AttributeList AL;
AL = AL.addParamAttribute(M.getContext(), 0, Attribute::ZExt);
- AL = AL.addAttribute(M.getContext(), AttributeList::ReturnIndex,
- Attribute::ZExt);
+ AL = AL.addRetAttribute(M.getContext(), Attribute::ZExt);
DFSanChainOriginFn = Mod->getOrInsertFunction("__dfsan_chain_origin",
DFSanChainOriginFnTy, AL);
}
AttributeList AL;
AL = AL.addParamAttribute(M.getContext(), 0, Attribute::ZExt);
AL = AL.addParamAttribute(M.getContext(), 1, Attribute::ZExt);
- AL = AL.addAttribute(M.getContext(), AttributeList::ReturnIndex,
- Attribute::ZExt);
+ AL = AL.addRetAttribute(M.getContext(), Attribute::ZExt);
DFSanChainOriginIfTaintedFn = Mod->getOrInsertFunction(
"__dfsan_chain_origin_if_tainted", DFSanChainOriginIfTaintedFnTy, AL);
}
IRBuilder<> IRB(M.getContext());
AttributeList Attr;
- Attr = Attr.addAttribute(M.getContext(), AttributeList::FunctionIndex,
- Attribute::NoUnwind);
+ Attr = Attr.addFnAttribute(M.getContext(), Attribute::NoUnwind);
// Initialize the callbacks.
TsanFuncEntry = M.getOrInsertFunction("__tsan_func_entry", Attr,
IRB.getVoidTy(), IRB.getInt8PtrTy());
// existing attribute value (i.e. attributes such as dereferenceable,
// dereferenceable_or_null etc). See AttrBuilder::merge for more details.
AttributeList AL = NewRetVal->getAttributes();
- AttributeList NewAL =
- AL.addAttributes(Context, AttributeList::ReturnIndex, Valid);
+ AttributeList NewAL = AL.addRetAttributes(Context, Valid);
NewRetVal->setAttributes(NewAL);
}
}
for (auto A : Attrs)
AB.addAttribute(A);
AttributeList NewAttrs;
- NewAttrs =
- NewAttrs.addAttributes(BD.getContext(), AttributeList::FunctionIndex, AB);
+ NewAttrs = NewAttrs.addFnAttributes(BD.getContext(), AB);
// Set this new list of attributes on the function.
F->setAttributes(NewAttrs);
AttributeList AL;
AttrBuilder B;
B.addAttribute(Attribute::NoReturn);
- AL = AL.addAttributes(C, AttributeList::FunctionIndex, AttributeSet::get(C, B));
+ AL = AL.addFnAttributes(C, AttributeSet::get(C, B));
EXPECT_TRUE(AL.hasFnAttr(Attribute::NoReturn));
B.clear();
B.addAttribute(Attribute::SExt);
- AL = AL.addAttributes(C, AttributeList::ReturnIndex, B);
+ AL = AL.addRetAttributes(C, B);
EXPECT_TRUE(AL.hasRetAttr(Attribute::SExt));
EXPECT_TRUE(AL.hasFnAttr(Attribute::NoReturn));
}
AttributeList AL;
AL = AL.addParamAttributes(C, 0, B_align_readonly);
- AL = AL.addAttributes(C, 0, B_stackalign_optnone);
+ AL = AL.addRetAttributes(C, B_stackalign_optnone);
EXPECT_TRUE(AL.hasRetAttrs());
EXPECT_TRUE(AL.hasRetAttr(Attribute::StackAlignment));
EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone));
AttributeList AL2;
AL2 = AL2.addParamAttributes(C, 0, B_align_readonly);
- AL2 = AL2.addAttributes(C, 0, B_stackalign_optnone);
+ AL2 = AL2.addRetAttributes(C, B_stackalign_optnone);
AL2 = AL2.removeParamAttributes(C, 0, B_align);
EXPECT_FALSE(AL2.hasParamAttr(0, Attribute::Alignment));
TEST(Attributes, AddMatchingAlignAttr) {
LLVMContext C;
AttributeList AL;
- AL = AL.addAttribute(C, AttributeList::FirstArgIndex,
- Attribute::getWithAlignment(C, Align(8)));
- AL = AL.addAttribute(C, AttributeList::FirstArgIndex + 1,
- Attribute::getWithAlignment(C, Align(32)));
+ AL = AL.addParamAttribute(C, 0, Attribute::getWithAlignment(C, Align(8)));
+ AL = AL.addParamAttribute(C, 1, Attribute::getWithAlignment(C, Align(32)));
EXPECT_EQ(Align(8), AL.getParamAlignment(0));
EXPECT_EQ(Align(32), AL.getParamAlignment(1));
AttrBuilder B;
B.addAttribute(Attribute::NonNull);
B.addAlignmentAttr(8);
- AL = AL.addAttributes(C, AttributeList::FirstArgIndex, B);
+ AL = AL.addParamAttributes(C, 0, B);
EXPECT_EQ(Align(8), AL.getParamAlignment(0));
EXPECT_EQ(Align(32), AL.getParamAlignment(1));
EXPECT_TRUE(AL.hasParamAttr(0, Attribute::NonNull));
std::string S;
raw_string_ostream OS(S);
AttributeList AL;
- AL.addAttribute(C, AttributeList::FunctionIndex, Attribute::AlwaysInline)
- .print(OS);
+ AL.addFnAttribute(C, Attribute::AlwaysInline).print(OS);
EXPECT_EQ(S, "AttributeList[\n"
" { function => alwaysinline }\n"
"]\n");
std::string S;
raw_string_ostream OS(S);
AttributeList AL;
- AL.addAttribute(C, AttributeList::ReturnIndex, Attribute::SExt).print(OS);
+ AL.addRetAttribute(C, Attribute::SExt).print(OS);
EXPECT_EQ(S, "AttributeList[\n"
" { return => signext }\n"
"]\n");
FunctionType *FTy = FunctionType::get(Type::getInt32Ty(C), /*isVarArg=*/false);
Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", M);
AttributeList AS = F->getAttributes();
- F->setAttributes(
- AS.addAttribute(C, AttributeList::ReturnIndex, Attribute::UWTable));
+ F->setAttributes(AS.addRetAttribute(C, Attribute::UWTable));
std::string Error;
raw_string_ostream ErrorOS(Error);