[llvm] r304300 - Fix assertion when merging multiple empty AttributeLists
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Wed May 31 07:24:06 PDT 2017
Author: rnk
Date: Wed May 31 09:24:06 2017
New Revision: 304300
URL: http://llvm.org/viewvc/llvm-project?rev=304300&view=rev
Log:
Fix assertion when merging multiple empty AttributeLists
Patch by Nicholas Wilson!
Differential Revision: https://reviews.llvm.org/D33627
Modified:
llvm/trunk/lib/IR/Attributes.cpp
llvm/trunk/unittests/IR/AttributesTest.cpp
Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=304300&r1=304299&r2=304300&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Wed May 31 09:24:06 2017
@@ -1006,6 +1006,10 @@ AttributeList AttributeList::get(LLVMCon
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;
Modified: llvm/trunk/unittests/IR/AttributesTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/AttributesTest.cpp?rev=304300&r1=304299&r2=304300&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/AttributesTest.cpp (original)
+++ llvm/trunk/unittests/IR/AttributesTest.cpp Wed May 31 09:24:06 2017
@@ -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
More information about the llvm-commits
mailing list