Author: Arthur Eubanks Date: 2021-08-17T21:05:40-07:00 New Revision: ad727ab7d9c21abe8b62df617d72e2c98d767561
URL: https://github.com/llvm/llvm-project/commit/ad727ab7d9c21abe8b62df617d72e2c98d767561 DIFF: https://github.com/llvm/llvm-project/commit/ad727ab7d9c21abe8b62df617d72e2c98d767561.diff LOG: [NFC] Migrate some callers away from Function/AttributeLists methods that take an index These methods can be confusing. Added: Modified: clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/TargetInfo.cpp llvm/include/llvm/CodeGen/IndirectThunks.h llvm/include/llvm/IR/Attributes.h llvm/include/llvm/IR/Function.h llvm/lib/IR/Attributes.cpp llvm/lib/IR/AutoUpgrade.cpp llvm/lib/IR/Function.cpp llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp llvm/lib/Target/Mips/Mips16HardFloat.cpp llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp llvm/lib/Transforms/Coroutines/CoroSplit.cpp llvm/lib/Transforms/IPO/FunctionAttrs.cpp llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp llvm/lib/Transforms/Scalar/SCCP.cpp llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp llvm/unittests/IR/AttributesTest.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 04ecfacf02c02..4b1524347aea2 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1885,7 +1885,7 @@ void CodeGenModule::addDefaultFunctionDefinitionAttributes(llvm::Function &F) { getDefaultFunctionAttributes(F.getName(), F.hasOptNone(), /* AttrOnCallSite = */ false, FuncAttrs); // TODO: call GetCPUAndFeaturesAttributes? - F.addAttributes(llvm::AttributeList::FunctionIndex, FuncAttrs); + F.addFnAttrs(FuncAttrs); } void CodeGenModule::addDefaultFunctionDefinitionAttributes( @@ -4526,9 +4526,7 @@ maybeRaiseRetAlignmentAttribute(llvm::LLVMContext &Ctx, if (CurAlign >= NewAlign) return Attrs; llvm::Attribute AlignAttr = llvm::Attribute::getWithAlignment(Ctx, NewAlign); - return Attrs - .removeAttribute(Ctx, llvm::AttributeList::ReturnIndex, - llvm::Attribute::AttrKind::Alignment) + return Attrs.removeRetAttribute(Ctx, llvm::Attribute::AttrKind::Alignment) .addAttribute(Ctx, llvm::AttributeList::ReturnIndex, AlignAttr); } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 0a660245a3c10..03ba909c08d71 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1781,7 +1781,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, CodeGenOpts.getInlining() == CodeGenOptions::OnlyAlwaysInlining) B.addAttribute(llvm::Attribute::NoInline); - F->addAttributes(llvm::AttributeList::FunctionIndex, B); + F->addFnAttrs(B); return; } @@ -1868,7 +1868,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, B.addAttribute(llvm::Attribute::MinSize); } - F->addAttributes(llvm::AttributeList::FunctionIndex, B); + F->addFnAttrs(B); unsigned alignment = D->getMaxAlignment() / Context.getCharWidth(); if (alignment) @@ -1918,7 +1918,7 @@ void CodeGenModule::setLLVMFunctionFEnvAttributes(const FunctionDecl *D, if (D->hasAttr<StrictFPAttr>()) { llvm::AttrBuilder FuncAttrs; FuncAttrs.addAttribute("strictfp"); - F->addAttributes(llvm::AttributeList::FunctionIndex, FuncAttrs); + F->addFnAttrs(FuncAttrs); } } @@ -2034,8 +2034,8 @@ void CodeGenModule::setNonAliasAttributes(GlobalDecl GD, RemoveAttrs.addAttribute("target-cpu"); RemoveAttrs.addAttribute("target-features"); RemoveAttrs.addAttribute("tune-cpu"); - F->removeAttributes(llvm::AttributeList::FunctionIndex, RemoveAttrs); - F->addAttributes(llvm::AttributeList::FunctionIndex, Attrs); + F->removeFnAttrs(RemoveAttrs); + F->addFnAttrs(Attrs); } } @@ -3613,7 +3613,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction( SetFunctionAttributes(GD, F, IsIncompleteFunction, IsThunk); if (ExtraAttrs.hasFnAttrs()) { llvm::AttrBuilder B(ExtraAttrs, llvm::AttributeList::FunctionIndex); - F->addAttributes(llvm::AttributeList::FunctionIndex, B); + F->addFnAttrs(B); } if (!DontDefer) { diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 0c1c1cf77f3a8..de9728a9c7d4a 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -827,19 +827,19 @@ class WebAssemblyTargetCodeGenInfo final : public TargetCodeGenInfo { llvm::Function *Fn = cast<llvm::Function>(GV); llvm::AttrBuilder B; B.addAttribute("wasm-import-module", Attr->getImportModule()); - Fn->addAttributes(llvm::AttributeList::FunctionIndex, B); + Fn->addFnAttrs(B); } if (const auto *Attr = FD->getAttr<WebAssemblyImportNameAttr>()) { llvm::Function *Fn = cast<llvm::Function>(GV); llvm::AttrBuilder B; B.addAttribute("wasm-import-name", Attr->getImportName()); - Fn->addAttributes(llvm::AttributeList::FunctionIndex, B); + Fn->addFnAttrs(B); } if (const auto *Attr = FD->getAttr<WebAssemblyExportNameAttr>()) { llvm::Function *Fn = cast<llvm::Function>(GV); llvm::AttrBuilder B; B.addAttribute("wasm-export-name", Attr->getExportName()); - Fn->addAttributes(llvm::AttributeList::FunctionIndex, B); + Fn->addFnAttrs(B); } } @@ -6401,7 +6401,7 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo { // the backend to perform a realignment as part of the function prologue. llvm::AttrBuilder B; B.addStackAlignmentAttr(8); - Fn->addAttributes(llvm::AttributeList::FunctionIndex, B); + Fn->addFnAttrs(B); } }; diff --git a/llvm/include/llvm/CodeGen/IndirectThunks.h b/llvm/include/llvm/CodeGen/IndirectThunks.h index 74973f38bc791..90f9912f0ee0f 100644 --- a/llvm/include/llvm/CodeGen/IndirectThunks.h +++ b/llvm/include/llvm/CodeGen/IndirectThunks.h @@ -62,7 +62,7 @@ void ThunkInserter<Derived>::createThunkFunction(MachineModuleInfo &MMI, AttrBuilder B; B.addAttribute(llvm::Attribute::NoUnwind); B.addAttribute(llvm::Attribute::Naked); - F->addAttributes(llvm::AttributeList::FunctionIndex, B); + F->addFnAttrs(B); // Populate our function a bit so that we can verify. BasicBlock *Entry = BasicBlock::Create(Ctx, "entry", F); diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h index 734279433c933..c9eee5b9eabaf 100644 --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -524,6 +524,48 @@ class AttributeList { LLVM_NODISCARD AttributeList removeAttributes(LLVMContext &C, unsigned Index) const; + /// Remove the specified attribute at the function index from this + /// attribute list. Returns a new list because attribute lists are immutable. + LLVM_NODISCARD AttributeList + removeFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const { + return removeAttribute(C, FunctionIndex, Kind); + } + + /// Remove the specified attribute at the function index from this + /// attribute list. Returns a new list because attribute lists are immutable. + LLVM_NODISCARD AttributeList removeFnAttribute(LLVMContext &C, + StringRef Kind) const { + return removeAttribute(C, FunctionIndex, Kind); + } + + /// Remove the specified attribute at the function index from this + /// attribute list. Returns a new list because attribute lists are immutable. + LLVM_NODISCARD AttributeList + removeFnAttributes(LLVMContext &C, const AttrBuilder &AttrsToRemove) const { + return removeAttributes(C, FunctionIndex, AttrsToRemove); + } + + /// Remove the specified attribute at the return value index from this + /// attribute list. Returns a new list because attribute lists are immutable. + LLVM_NODISCARD AttributeList + removeRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const { + return removeAttribute(C, ReturnIndex, Kind); + } + + /// Remove the specified attribute at the return value index from this + /// attribute list. Returns a new list because attribute lists are immutable. + LLVM_NODISCARD AttributeList removeRetAttribute(LLVMContext &C, + StringRef Kind) const { + return removeAttribute(C, ReturnIndex, Kind); + } + + /// Remove the specified attribute at the return value index from this + /// attribute list. Returns a new list because attribute lists are immutable. + LLVM_NODISCARD AttributeList + removeRetAttributes(LLVMContext &C, const AttrBuilder &AttrsToRemove) const { + return removeAttributes(C, ReturnIndex, AttrsToRemove); + } + /// Remove the specified attribute at the specified arg index from this /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeParamAttribute( diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h index 27a1d124a6426..69bcd0be8e38c 100644 --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -272,15 +272,26 @@ class Function : public GlobalObject, public ilist_node<Function> { addAttribute(AttributeList::FunctionIndex, Attr); } + /// Add function attributes to this function. + void addFnAttrs(const AttrBuilder &Attrs) { + addAttributes(AttributeList::FunctionIndex, Attrs); + } + + /// removes the attributes from the list of attributes. + void removeAttributes(unsigned i, const AttrBuilder &Attrs); + /// Remove function attributes from this function. void removeFnAttr(Attribute::AttrKind Kind) { - removeAttribute(AttributeList::FunctionIndex, Kind); + setAttributes(getAttributes().removeFnAttribute(getContext(), Kind)); } /// Remove function attribute from this function. void removeFnAttr(StringRef Kind) { - setAttributes(getAttributes().removeAttribute( - getContext(), AttributeList::FunctionIndex, Kind)); + setAttributes(getAttributes().removeFnAttribute(getContext(), Kind)); + } + + void removeFnAttrs(const AttrBuilder &Attrs) { + setAttributes(getAttributes().removeFnAttributes(getContext(), Attrs)); } /// A function will have the "coroutine.presplit" attribute if it's @@ -429,8 +440,13 @@ class Function : public GlobalObject, public ilist_node<Function> { /// removes the attribute from the list of attributes. void removeAttribute(unsigned i, StringRef Kind); - /// removes the attributes from the list of attributes. - void removeAttributes(unsigned i, const AttrBuilder &Attrs); + /// removes the attribute from the return value list of attributes. + void removeRetAttr(Attribute::AttrKind Kind); + + /// removes the attribute from the return value list of attributes. + void removeRetAttr(StringRef Kind); + + void removeRetAttrs(const AttrBuilder &Attrs); /// removes the attribute from the list of attributes. void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind); diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 9bdaa56bb1cd7..9f665b450f643 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -1961,11 +1961,11 @@ static void adjustCallerSSPLevel(Function &Caller, const Function &Callee) { .addAttribute(Attribute::StackProtectReq); if (Callee.hasFnAttribute(Attribute::StackProtectReq)) { - Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr); + Caller.removeFnAttrs(OldSSPAttr); Caller.addFnAttr(Attribute::StackProtectReq); } else if (Callee.hasFnAttribute(Attribute::StackProtectStrong) && !Caller.hasFnAttribute(Attribute::StackProtectReq)) { - Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr); + Caller.removeFnAttrs(OldSSPAttr); Caller.addFnAttr(Attribute::StackProtectStrong); } else if (Callee.hasFnAttribute(Attribute::StackProtect) && !Caller.hasFnAttribute(Attribute::StackProtectReq) && diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 6271385183eb9..95a776eab9e07 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -4383,8 +4383,7 @@ void llvm::UpgradeFunctionAttributes(Function &F) { } // Remove all incompatibile attributes from function. - F.removeAttributes(AttributeList::ReturnIndex, - AttributeFuncs::typeIncompatible(F.getReturnType())); + F.removeRetAttrs(AttributeFuncs::typeIncompatible(F.getReturnType())); for (auto &Arg : F.args()) Arg.removeAttrs(AttributeFuncs::typeIncompatible(Arg.getType())); } diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index da846dd55c5f3..f8558636ab53c 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -354,7 +354,7 @@ Function *Function::createWithDefaultAttr(FunctionType *Ty, B.addAttribute("frame-pointer", "all"); break; } - F->addAttributes(AttributeList::FunctionIndex, B); + F->addFnAttrs(B); return F; } @@ -577,9 +577,21 @@ void Function::removeAttribute(unsigned i, StringRef Kind) { setAttributes(PAL); } -void Function::removeAttributes(unsigned i, const AttrBuilder &Attrs) { +void Function::removeRetAttr(Attribute::AttrKind Kind) { AttributeList PAL = getAttributes(); - PAL = PAL.removeAttributes(getContext(), i, Attrs); + PAL = PAL.removeRetAttribute(getContext(), Kind); + setAttributes(PAL); +} + +void Function::removeRetAttr(StringRef Kind) { + AttributeList PAL = getAttributes(); + PAL = PAL.removeRetAttribute(getContext(), Kind); + setAttributes(PAL); +} + +void Function::removeRetAttrs(const AttrBuilder &Attrs) { + AttributeList PAL = getAttributes(); + PAL = PAL.removeRetAttributes(getContext(), Attrs); setAttributes(PAL); } diff --git a/llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp b/llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp index e2aafa25142e8..d8cdc8c381047 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp @@ -357,7 +357,7 @@ bool AMDGPURewriteOutArguments::runOnFunction(Function &F) { RetAttrs.addAttribute(Attribute::SExt); RetAttrs.addAttribute(Attribute::ZExt); RetAttrs.addAttribute(Attribute::NoAlias); - NewFunc->removeAttributes(AttributeList::ReturnIndex, RetAttrs); + NewFunc->removeRetAttrs(RetAttrs); // TODO: How to preserve metadata? // Move the body of the function into the new rewritten function, and replace diff --git a/llvm/lib/Target/Mips/Mips16HardFloat.cpp b/llvm/lib/Target/Mips/Mips16HardFloat.cpp index 6c5f63804d191..db0097aab39de 100644 --- a/llvm/lib/Target/Mips/Mips16HardFloat.cpp +++ b/llvm/lib/Target/Mips/Mips16HardFloat.cpp @@ -485,11 +485,11 @@ static void removeUseSoftFloat(Function &F) { AttrBuilder B; LLVM_DEBUG(errs() << "removing -use-soft-float\n"); B.addAttribute("use-soft-float", "false"); - F.removeAttributes(AttributeList::FunctionIndex, B); + F.removeFnAttrs(B); if (F.hasFnAttribute("use-soft-float")) { LLVM_DEBUG(errs() << "still has -use-soft-float\n"); } - F.addAttributes(AttributeList::FunctionIndex, B); + F.addFnAttrs(B); } // This pass only makes sense when the underlying chip has floating point but diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp index 746f01b51c9c0..c224c10b3f081 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp @@ -352,12 +352,12 @@ static Function *getEmscriptenFunction(FunctionType *Ty, const Twine &Name, if (!F->hasFnAttribute("wasm-import-module")) { llvm::AttrBuilder B; B.addAttribute("wasm-import-module", "env"); - F->addAttributes(llvm::AttributeList::FunctionIndex, B); + F->addFnAttrs(B); } if (!F->hasFnAttribute("wasm-import-name")) { llvm::AttrBuilder B; B.addAttribute("wasm-import-name", F->getName()); - F->addAttributes(llvm::AttributeList::FunctionIndex, B); + F->addFnAttrs(B); } return F; } diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp index 80f59945b6e57..f960d6475769f 100644 --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -1568,8 +1568,8 @@ static void splitAsyncCoroutine(Function &F, coro::Shape &Shape, // Reset various things that the optimizer might have decided it // "knows" about the coroutine function due to not seeing a return. F.removeFnAttr(Attribute::NoReturn); - F.removeAttribute(AttributeList::ReturnIndex, Attribute::NoAlias); - F.removeAttribute(AttributeList::ReturnIndex, Attribute::NonNull); + F.removeRetAttr(Attribute::NoAlias); + F.removeRetAttr(Attribute::NonNull); auto &Context = F.getContext(); auto *Int8PtrTy = Type::getInt8PtrTy(Context); @@ -1667,8 +1667,8 @@ static void splitRetconCoroutine(Function &F, coro::Shape &Shape, // Reset various things that the optimizer might have decided it // "knows" about the coroutine function due to not seeing a return. F.removeFnAttr(Attribute::NoReturn); - F.removeAttribute(AttributeList::ReturnIndex, Attribute::NoAlias); - F.removeAttribute(AttributeList::ReturnIndex, Attribute::NonNull); + F.removeRetAttr(Attribute::NoAlias); + F.removeRetAttr(Attribute::NonNull); // Allocate the frame. auto *Id = cast<AnyCoroIdRetconInst>(Shape.CoroBegin->getId()); diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp index c6d7d43004639..6814dca489fc5 100644 --- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp @@ -303,7 +303,7 @@ static bool addReadAttrs(const SCCNodeSet &SCCNodes, AARGetterT &&AARGetter) { AttrsToRemove.addAttribute(Attribute::InaccessibleMemOnly); AttrsToRemove.addAttribute(Attribute::InaccessibleMemOrArgMemOnly); } - F->removeAttributes(AttributeList::FunctionIndex, AttrsToRemove); + F->removeFnAttrs(AttrsToRemove); // Add in the new attribute. if (WritesMemory && !ReadsMemory) diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp index caa5b9908e456..afbf642b72c5b 100644 --- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -1154,14 +1154,12 @@ DataFlowSanitizer::buildWrapperFunction(Function *F, StringRef NewFName, Function *NewF = Function::Create(NewFT, NewFLink, F->getAddressSpace(), NewFName, F->getParent()); NewF->copyAttributesFrom(F); - NewF->removeAttributes( - AttributeList::ReturnIndex, + NewF->removeRetAttrs( AttributeFuncs::typeIncompatible(NewFT->getReturnType())); BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", NewF); if (F->isVarArg()) { - NewF->removeAttributes(AttributeList::FunctionIndex, - AttrBuilder().addAttribute("split-stack")); + NewF->removeFnAttrs(AttrBuilder().addAttribute("split-stack")); CallInst::Create(DFSanVarargWrapperFn, IRBuilder<>(BB).CreateGlobalStringPtr(F->getName()), "", BB); @@ -1464,8 +1462,7 @@ bool DataFlowSanitizer::runImpl(Module &M) { Function *NewF = Function::Create(NewFT, F.getLinkage(), F.getAddressSpace(), "", &M); NewF->copyAttributesFrom(&F); - NewF->removeAttributes( - AttributeList::ReturnIndex, + NewF->removeRetAttrs( AttributeFuncs::typeIncompatible(NewFT->getReturnType())); for (Function::arg_iterator FArg = F.arg_begin(), NewFArg = NewF->arg_begin(), @@ -1513,7 +1510,7 @@ bool DataFlowSanitizer::runImpl(Module &M) { std::string(F.getName()), WrapperLinkage, NewFT); if (getInstrumentedABI() == IA_TLS) - NewF->removeAttributes(AttributeList::FunctionIndex, ReadOnlyNoneAttrs); + NewF->removeFnAttrs(ReadOnlyNoneAttrs); Value *WrappedFnCst = ConstantExpr::getBitCast(NewF, PointerType::getUnqual(FT)); @@ -2953,8 +2950,7 @@ bool DFSanVisitor::visitWrappedCallBase(Function &F, CallBase &CB) { // Custom functions returning non-void will write to the return label. if (!FT->getReturnType()->isVoidTy()) { - CustomFn->removeAttributes(AttributeList::FunctionIndex, - DFSF.DFS.ReadOnlyNoneAttrs); + CustomFn->removeFnAttrs(DFSF.DFS.ReadOnlyNoneAttrs); } } @@ -3176,9 +3172,8 @@ void DFSanVisitor::visitCallBase(CallBase &CB) { NewCB = IRB.CreateCall(NewFT, Func, Args); } NewCB->setCallingConv(CB.getCallingConv()); - NewCB->setAttributes(CB.getAttributes().removeAttributes( - *DFSF.DFS.Ctx, AttributeList::ReturnIndex, - AttributeFuncs::typeIncompatible(NewCB->getType()))); + NewCB->setAttributes(CB.getAttributes().removeRetAttributes( + *DFSF.DFS.Ctx, AttributeFuncs::typeIncompatible(NewCB->getType()))); if (Next) { ExtractValueInst *ExVal = ExtractValueInst::Create(NewCB, 0, "", Next); diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index a727b76162d47..6fe330123d8c7 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -3655,7 +3655,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> { Call->removeAttributes(AttributeList::FunctionIndex, B); if (Function *Func = Call->getCalledFunction()) { - Func->removeAttributes(AttributeList::FunctionIndex, B); + Func->removeFnAttrs(B); } maybeMarkSanitizerLibraryCallNoBuiltin(Call, TLI); @@ -5339,7 +5339,7 @@ bool MemorySanitizer::sanitizeFunction(Function &F, TargetLibraryInfo &TLI) { .addAttribute(Attribute::WriteOnly) .addAttribute(Attribute::ArgMemOnly) .addAttribute(Attribute::Speculatable); - F.removeAttributes(AttributeList::FunctionIndex, B); + F.removeFnAttrs(B); return Visitor.runOnFunction(); } diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index b09f896d01577..402ebfb9da35a 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -490,7 +490,7 @@ bool llvm::runIPSCCP( AttrBuilder AttributesToRemove; AttributesToRemove.addAttribute(Attribute::ArgMemOnly); AttributesToRemove.addAttribute(Attribute::InaccessibleMemOrArgMemOnly); - F.removeAttributes(AttributeList::FunctionIndex, AttributesToRemove); + F.removeFnAttrs(AttributesToRemove); for (User *U : F.users()) { auto *CB = dyn_cast<CallBase>(U); diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp index 31d03e1e86af0..6674e9bdbc39e 100644 --- a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp +++ b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp @@ -89,7 +89,7 @@ static bool runOnFunction(Function &F, bool PostInlining) { insertCall(F, EntryFunc, &*F.begin()->getFirstInsertionPt(), DL); Changed = true; - F.removeAttribute(AttributeList::FunctionIndex, EntryAttr); + F.removeFnAttr(EntryAttr); } if (!ExitFunc.empty()) { @@ -111,7 +111,7 @@ static bool runOnFunction(Function &F, bool PostInlining) { insertCall(F, ExitFunc, T, DL); Changed = true; } - F.removeAttribute(AttributeList::FunctionIndex, ExitAttr); + F.removeFnAttr(ExitAttr); } return Changed; diff --git a/llvm/unittests/IR/AttributesTest.cpp b/llvm/unittests/IR/AttributesTest.cpp index 86e7389877266..4649b868d118d 100644 --- a/llvm/unittests/IR/AttributesTest.cpp +++ b/llvm/unittests/IR/AttributesTest.cpp @@ -54,7 +54,8 @@ TEST(Attributes, Ordering) { AttributeList::get(C, 1, Attribute::SExt)}; AttributeList SetA = AttributeList::get(C, ASs); - AttributeList SetB = SetA.removeAttributes(C, 1, ASs[1].getParamAttrs(0)); + AttributeList SetB = + SetA.removeParamAttributes(C, 0, ASs[1].getParamAttrs(0)); EXPECT_NE(SetA, SetB); } @@ -118,7 +119,7 @@ TEST(Attributes, RemoveAlign) { EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone)); EXPECT_TRUE(AL.getStackAlignment(0) == 32); - AL = AL.removeAttribute(C, 0, Attribute::StackAlignment); + AL = AL.removeRetAttribute(C, Attribute::StackAlignment); EXPECT_FALSE(AL.hasParamAttr(0, Attribute::Alignment)); EXPECT_TRUE(AL.hasParamAttr(0, Attribute::ReadOnly)); EXPECT_FALSE(AL.hasRetAttr(Attribute::StackAlignment)); @@ -135,7 +136,7 @@ TEST(Attributes, RemoveAlign) { EXPECT_TRUE(AL2.hasRetAttr(Attribute::OptimizeNone)); EXPECT_TRUE(AL2.getStackAlignment(0) == 32); - AL2 = AL2.removeAttributes(C, 0, B_stackalign); + AL2 = AL2.removeRetAttributes(C, B_stackalign); EXPECT_FALSE(AL2.hasParamAttr(0, Attribute::Alignment)); EXPECT_TRUE(AL2.hasParamAttr(0, Attribute::ReadOnly)); EXPECT_FALSE(AL2.hasRetAttr(Attribute::StackAlignment)); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits