[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:26:28 PDT 2018


craig.topper created this revision.
craig.topper added a reviewer: rnk.
Herald added a subscriber: javed.absar.

The code uses the index of the last element in the sorted array to determine the maximum size needed for the vector. But if the last index is a FunctionIndex(~0), attrIdxToArrayIdx will return 0 and the vector will have size 1. If there are any indices before FunctionIndex, those values would return a value larger than 0 from attrIdxToArrayIdx. So in this case we need to look in front of the FunctionIndex to get the true size needed.

This was found working in our internal fork so I don't have a test case. I'll look into creating a unit test.


https://reviews.llvm.org/D45632

Files:
  lib/IR/Attributes.cpp


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.142443.patch
Type: text/x-patch
Size: 608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180413/28fa2abd/attachment.bin>


More information about the llvm-commits mailing list