]> granicus.if.org Git - llvm/commitdiff
Remove buggy 'addAttributes(unsigned, AttrBuilder)' overload
authorReid Kleckner <rnk@google.com>
Wed, 19 Apr 2017 01:51:13 +0000 (01:51 +0000)
committerReid Kleckner <rnk@google.com>
Wed, 19 Apr 2017 01:51:13 +0000 (01:51 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300651 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Attributes.h
lib/IR/Attributes.cpp
unittests/IR/AttributesTest.cpp

index 121f57a433acb14e9d8105ba03fa89ae15ac69b5..b13f197d25fdc7d11a74a78104e2e46862122b4e 100644 (file)
@@ -356,9 +356,6 @@ public:
   AttributeList addAttributes(LLVMContext &C, unsigned Index,
                               AttributeList Attrs) const;
 
-  AttributeList addAttributes(LLVMContext &C, unsigned Index,
-                              AttributeSet AS) const;
-
   AttributeList addAttributes(LLVMContext &C, unsigned Index,
                               const AttrBuilder &B) const;
 
index 3da00ad6fd4a51dc1f3b546e51d6d7c3504a40fb..47ca5e4062349cdf5e873c560ec97be6f68e5087 100644 (file)
@@ -984,23 +984,23 @@ AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index,
 }
 
 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::addAttributes(LLVMContext &C, unsigned Index,
   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,
index c9c8cb75ebf89dcebf599808bd161509f3b84bf2..7c3df2e19e8f91c9504060614e07fa4223d5e2c1 100644 (file)
@@ -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