[PATCH] D45632: [Attributes] Fix a bug in AttributeList::get so it can handle a mix FunctionIndex and ReturnIndex/arg indices at the same time

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 13 11:54:27 PDT 2018


craig.topper updated this revision to Diff 142452.
craig.topper added a comment.

Added unittest


https://reviews.llvm.org/D45632

Files:
  lib/IR/Attributes.cpp
  unittests/IR/AttributesTest.cpp


Index: unittests/IR/AttributesTest.cpp
===================================================================
--- unittests/IR/AttributesTest.cpp
+++ unittests/IR/AttributesTest.cpp
@@ -159,4 +159,12 @@
   EXPECT_TRUE(AL.isEmpty());
 }
 
+TEST(Attributes, OverflowGet) {
+  LLVMContext C;
+  std::pair<unsigned, Attribute> 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
Index: lib/IR/Attributes.cpp
===================================================================
--- lib/IR/Attributes.cpp
+++ 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<AttributeSet, 4> AttrVec(attrIdxToArrayIdx(MaxIndex) + 1);
   for (const auto Pair : Attrs)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45632.142452.patch
Type: text/x-patch
Size: 1256 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180413/68149ec7/attachment.bin>


More information about the llvm-commits mailing list