[llvm] r300651 - Remove buggy 'addAttributes(unsigned, AttrBuilder)' overload
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 18 18:51:13 PDT 2017
Author: rnk
Date: Tue Apr 18 20:51:13 2017
New Revision: 300651
URL: http://llvm.org/viewvc/llvm-project?rev=300651&view=rev
Log:
Remove buggy 'addAttributes(unsigned, AttrBuilder)' overload
The 'addAttributes(unsigned, AttrBuilder)' overload delegated to 'get'
instead of 'addAttributes'.
Since we can implicitly construct an AttrBuilder from an AttributeSet,
just standardize on AttrBuilder.
Modified:
llvm/trunk/include/llvm/IR/Attributes.h
llvm/trunk/lib/IR/Attributes.cpp
llvm/trunk/unittests/IR/AttributesTest.cpp
Modified: llvm/trunk/include/llvm/IR/Attributes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Attributes.h?rev=300651&r1=300650&r2=300651&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Attributes.h (original)
+++ llvm/trunk/include/llvm/IR/Attributes.h Tue Apr 18 20:51:13 2017
@@ -357,9 +357,6 @@ public:
AttributeList Attrs) const;
AttributeList addAttributes(LLVMContext &C, unsigned Index,
- AttributeSet AS) const;
-
- AttributeList addAttributes(LLVMContext &C, unsigned Index,
const AttrBuilder &B) const;
/// \brief Remove the specified attribute at the specified index from this
Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=300651&r1=300650&r2=300651&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Tue Apr 18 20:51:13 2017
@@ -984,23 +984,23 @@ AttributeList AttributeList::addAttribut
}
AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index,
- AttributeSet AS) const {
- if (!AS.hasAttributes())
+ const AttrBuilder &B) const {
+ if (!B.hasAttributes())
return *this;
if (!pImpl)
- return AttributeList::get(C, {{Index, AS}});
+ return AttributeList::get(C, {{Index, AttributeSet::get(C, B)}});
#ifndef NDEBUG
// FIXME it is not obvious how this should work for alignment. For now, say
// we can't change a known alignment.
unsigned OldAlign = getParamAlignment(Index);
- unsigned NewAlign = AS.getAlignment();
+ unsigned NewAlign = B.getAlignment();
assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
"Attempt to change alignment!");
#endif
- SmallVector<std::pair<unsigned, AttributeSet>, 4> AttrSet;
+ SmallVector<IndexAttrPair, 4> AttrVec;
uint64_t NumAttrs = pImpl->getNumSlots();
unsigned I;
@@ -1008,31 +1008,25 @@ AttributeList AttributeList::addAttribut
for (I = 0; I < NumAttrs; ++I) {
if (getSlotIndex(I) >= Index)
break;
- AttrSet.emplace_back(getSlotIndex(I), pImpl->getSlotNode(I));
+ AttrVec.emplace_back(getSlotIndex(I), pImpl->getSlotNode(I));
}
+ AttrBuilder NewAttrs;
if (I < NumAttrs && getSlotIndex(I) == Index) {
- // We need to merge two AttributeSets.
- AttributeSet Merged = AttributeSet::get(
- C, AttrBuilder(pImpl->getSlotNode(I)).merge(AttrBuilder(AS)));
- AttrSet.emplace_back(Index, Merged);
+ // We need to merge the attribute sets.
+ NewAttrs.merge(pImpl->getSlotNode(I));
++I;
- } else {
- // Otherwise, there were no attributes at this position in the original
- // list. Add the set as is.
- AttrSet.emplace_back(Index, AS);
}
+ NewAttrs.merge(B);
+
+ // Add the new or merged attribute set at this index.
+ AttrVec.emplace_back(Index, AttributeSet::get(C, NewAttrs));
// Add the remaining entries.
for (; I < NumAttrs; ++I)
- AttrSet.emplace_back(getSlotIndex(I), pImpl->getSlotNode(I));
-
- return get(C, AttrSet);
-}
+ AttrVec.emplace_back(getSlotIndex(I), pImpl->getSlotNode(I));
-AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index,
- const AttrBuilder &B) const {
- return get(C, Index, AttributeSet::get(C, B));
+ return get(C, AttrVec);
}
AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index,
Modified: llvm/trunk/unittests/IR/AttributesTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/AttributesTest.cpp?rev=300651&r1=300650&r2=300651&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/AttributesTest.cpp (original)
+++ llvm/trunk/unittests/IR/AttributesTest.cpp Tue Apr 18 20:51:13 2017
@@ -56,6 +56,11 @@ TEST(Attributes, AddAttributes) {
B.addAttribute(Attribute::NoReturn);
AL = AL.addAttributes(C, AttributeList::FunctionIndex, AttributeSet::get(C, B));
EXPECT_TRUE(AL.hasFnAttribute(Attribute::NoReturn));
+ B.clear();
+ B.addAttribute(Attribute::SExt);
+ AL = AL.addAttributes(C, AttributeList::ReturnIndex, B);
+ EXPECT_TRUE(AL.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt));
+ EXPECT_TRUE(AL.hasFnAttribute(Attribute::NoReturn));
}
} // end anonymous namespace
More information about the llvm-commits
mailing list