Index: llvm/trunk/lib/IR/Attributes.cpp =================================================================== --- llvm/trunk/lib/IR/Attributes.cpp +++ llvm/trunk/lib/IR/Attributes.cpp @@ -922,6 +922,10 @@ "Pointless attribute!"); unsigned MaxIndex = Attrs.back().first; + // If the MaxIndex is FunctionIndex and there are other indices in front + // of it, we need to use the largest of those to get the right size. + if (MaxIndex == FunctionIndex && Attrs.size() > 1) + MaxIndex = Attrs[Attrs.size() - 2].first; SmallVector AttrVec(attrIdxToArrayIdx(MaxIndex) + 1); for (const auto Pair : Attrs) Index: llvm/trunk/unittests/IR/AttributesTest.cpp =================================================================== --- llvm/trunk/unittests/IR/AttributesTest.cpp +++ llvm/trunk/unittests/IR/AttributesTest.cpp @@ -159,4 +159,12 @@ EXPECT_TRUE(AL.isEmpty()); } +TEST(Attributes, OverflowGet) { + LLVMContext C; + std::pair Attrs[] = { { AttributeList::ReturnIndex, Attribute::get(C, Attribute::SExt) }, + { AttributeList::FunctionIndex, Attribute::get(C, Attribute::ReadOnly) } }; + AttributeList AL = AttributeList::get(C, Attrs); + EXPECT_EQ(2U, AL.getNumAttrSets()); +} + } // end anonymous namespace