summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/IR/Attributes.cpp4
-rw-r--r--llvm/unittests/IR/AttributesTest.cpp7
2 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 19b7c302723..a6d1c9035af 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -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;
diff --git a/llvm/unittests/IR/AttributesTest.cpp b/llvm/unittests/IR/AttributesTest.cpp
index 7af4aebd540..ab018d84538 100644
--- a/llvm/unittests/IR/AttributesTest.cpp
+++ b/llvm/unittests/IR/AttributesTest.cpp
@@ -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
OpenPOWER on IntegriCloud