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

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 16 10:08:50 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL330136: [Attributes] Fix a bug in AttributeList::get so it can handle a mix of… (authored by ctopper, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45632?vs=142452&id=142660#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45632

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


Index: llvm/trunk/lib/IR/Attributes.cpp
===================================================================
--- llvm/trunk/lib/IR/Attributes.cpp
+++ llvm/trunk/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)
Index: llvm/trunk/unittests/IR/AttributesTest.cpp
===================================================================
--- llvm/trunk/unittests/IR/AttributesTest.cpp
+++ llvm/trunk/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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45632.142660.patch
Type: text/x-patch
Size: 1322 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180416/381347e6/attachment.bin>


More information about the llvm-commits mailing list