Fix assertion when merging multiple empty AttributeLists

Patch by Nicholas Wilson!

Differential Revision: https://reviews.llvm.org/D33627

llvm-svn: 304300
This commit is contained in:
Reid Kleckner 2017-05-31 14:24:06 +00:00
parent 11fda41d0b
commit ee913d8457
2 changed files with 11 additions and 0 deletions

View File

@ -1006,6 +1006,10 @@ AttributeList AttributeList::get(LLVMContext &C,
for (AttributeList List : Attrs)
MaxSize = std::max(MaxSize, List.getNumAttrSets());
// If every list was empty, there is no point in merging the lists.
if (MaxSize == 0)
return AttributeList();
SmallVector<AttributeSet, 8> NewAttrSets(MaxSize);
for (unsigned I = 0; I < MaxSize; ++I) {
AttrBuilder CurBuilder;

View File

@ -82,4 +82,11 @@ TEST(Attributes, AddMatchingAlignAttr) {
EXPECT_TRUE(AL.hasParamAttribute(0, Attribute::NonNull));
}
TEST(Attributes, EmptyGet) {
LLVMContext C;
AttributeList EmptyLists[] = {AttributeList(), AttributeList()};
AttributeList AL = AttributeList::get(C, EmptyLists);
EXPECT_TRUE(AL.isEmpty());
}
} // end anonymous namespace