diff options
author | Reid Kleckner <rnk@google.com> | 2017-05-31 14:24:06 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2017-05-31 14:24:06 +0000 |
commit | 1d7cbdfc3d28d5db078b4a214f73b5bc633bdfbb (patch) | |
tree | 5c4010f291a7a989905b8347a1f9ff928493dcb4 | |
parent | 7c70fddba6b967acd547eeed86b1e60710345c48 (diff) | |
download | bcm5719-llvm-1d7cbdfc3d28d5db078b4a214f73b5bc633bdfbb.tar.gz bcm5719-llvm-1d7cbdfc3d28d5db078b4a214f73b5bc633bdfbb.zip |
Fix assertion when merging multiple empty AttributeLists
Patch by Nicholas Wilson!
Differential Revision: https://reviews.llvm.org/D33627
llvm-svn: 304300
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 4 | ||||
-rw-r--r-- | llvm/unittests/IR/AttributesTest.cpp | 7 |
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 |