From f1c94e3241a5bcc1f54e6c87c58e4640aa3823a0 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 1 Feb 2013 00:13:50 +0000 Subject: [PATCH] Use iterators instead of relying upon a bitmask of attributes to remove attributes from an AttrBuilder. llvm-svn: 174123 --- llvm/lib/IR/Attributes.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 9d5f53b..01e0235 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -749,7 +749,7 @@ AttributeSet::iterator AttributeSet::begin(unsigned Idx) { AttributeSet::iterator AttributeSet::end(unsigned Idx) { if (!pImpl) return ArrayRef().end(); - return pImpl->begin(Idx); + return pImpl->end(Idx); } //===----------------------------------------------------------------------===// @@ -852,18 +852,24 @@ AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { } AttrBuilder &AttrBuilder::removeAttributes(AttributeSet A, uint64_t Index) { - uint64_t Mask = A.Raw(Index); + unsigned Idx = ~0U; + for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I) + if (A.getSlotIndex(I) == Index) { + Idx = I; + break; + } - for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds; - I = Attribute::AttrKind(I + 1)) { - if (Mask & AttributeImpl::getAttrMask(I)) { - Attrs.erase(I); + assert(Idx != ~0U && "Couldn't find index in AttributeSet!"); - if (I == Attribute::Alignment) - Alignment = 0; - else if (I == Attribute::StackAlignment) - StackAlignment = 0; - } + for (AttributeSet::iterator I = A.begin(Idx), E = A.end(Idx); I != E; ++I) { + ConstantInt *CI = cast(I->getAttributeKind()); + Attribute::AttrKind Kind = Attribute::AttrKind(CI->getZExtValue()); + Attrs.erase(Kind); + + if (Kind == Attribute::Alignment) + Alignment = 0; + else if (Kind == Attribute::StackAlignment) + StackAlignment = 0; } return *this; -- 2.7.4