Use the AttributeSet's iterators.
authorBill Wendling <isanbard@gmail.com>
Sat, 2 Feb 2013 00:42:06 +0000 (00:42 +0000)
committerBill Wendling <isanbard@gmail.com>
Sat, 2 Feb 2013 00:42:06 +0000 (00:42 +0000)
Use the AttributeSet's iterators in AttrBuilder::hasAttributes() when
determining of the intersection of the AttrBuilder and AttributeSet is non-null.

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

lib/IR/AttributeImpl.h
lib/IR/Attributes.cpp

index 66001f73a00dcc301db14147896fe07044bb4eea..bf87562dd64ddc4dbdc133e91862f8564caaeb05 100644 (file)
@@ -153,7 +153,6 @@ public:
   /// \p Slot is an index into the AttrNodes list, not the index of the return /
   /// parameter/ function which the attributes apply to.
   AttributeSet getSlotAttributes(unsigned Slot) const {
-    // FIXME: This needs to use AttrNodes instead.
     return AttributeSet::get(Context, AttrNodes[Slot]);
   }
 
index f8ca9f1f0420ca51c1b5c4411ecff9d645ec01ff..d585843e90513a1a263b734dab82dabf7d76f99a 100644 (file)
@@ -42,9 +42,7 @@ Attribute Attribute::get(LLVMContext &Context, Constant *Kind, Constant *Val) {
   if (!PA) {
     // If we didn't find any existing attributes of the same shape then create a
     // new one and insert it.
-    PA = (!Val) ?
-      new AttributeImpl(Context, Kind) :
-      new AttributeImpl(Context, Kind, Val);
+    PA = new AttributeImpl(Context, Kind, Val);
     pImpl->AttrsSet.InsertNode(PA, InsertPoint);
   }
 
@@ -884,7 +882,27 @@ bool AttrBuilder::hasAttributes() const {
 }
 
 bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const {
-  return Raw() & A.Raw(Index);
+  unsigned Idx = ~0U;
+  for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I)
+    if (A.getSlotIndex(I) == Index) {
+      Idx = I;
+      break;
+    }
+
+  assert(Idx != ~0U && "Couldn't find the index!");
+
+  for (AttributeSet::iterator I = A.begin(Idx), E = A.end(Idx);
+       I != E; ++I) {
+    Attribute Attr = *I;
+    // FIXME: Support StringRefs.
+    Attribute::AttrKind Kind = Attribute::AttrKind(
+      cast<ConstantInt>(Attr.getAttributeKind())->getZExtValue());
+
+    if (Attrs.count(Kind))
+      return true;
+  }
+
+  return false;
 }
 
 bool AttrBuilder::hasAlignmentAttr() const {