[llvm] r303458 - Fix off-by-one bug in AttributeList::addAttributes index handling
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Fri May 19 15:23:48 PDT 2017
Author: rnk
Date: Fri May 19 17:23:47 2017
New Revision: 303458
URL: http://llvm.org/viewvc/llvm-project?rev=303458&view=rev
Log:
Fix off-by-one bug in AttributeList::addAttributes index handling
getParamAlignment expects an argument number, not an AttributeList
index.
Johan Englan, who works on LDC, found this bug and told me about it off
list.
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=303458&r1=303457&r2=303458&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Fri May 19 17:23:47 2017
@@ -1058,7 +1058,7 @@ AttributeList AttributeList::addAttribut
#ifndef NDEBUG
// FIXME it is not obvious how this should work for alignment. For now, say
// we can't change a known alignment.
- unsigned OldAlign = getParamAlignment(Index);
+ unsigned OldAlign = getAttributes(Index).getAlignment();
unsigned NewAlign = B.getAlignment();
assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
"Attempt to change alignment!");
Modified: llvm/trunk/unittests/IR/AttributesTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/AttributesTest.cpp?rev=303458&r1=303457&r2=303458&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/AttributesTest.cpp (original)
+++ llvm/trunk/unittests/IR/AttributesTest.cpp Fri May 19 17:23:47 2017
@@ -63,4 +63,23 @@ TEST(Attributes, AddAttributes) {
EXPECT_TRUE(AL.hasFnAttribute(Attribute::NoReturn));
}
+TEST(Attributes, AddMatchingAlignAttr) {
+ LLVMContext C;
+ AttributeList AL;
+ AL = AL.addAttribute(C, AttributeList::FirstArgIndex,
+ Attribute::getWithAlignment(C, 8));
+ AL = AL.addAttribute(C, AttributeList::FirstArgIndex + 1,
+ Attribute::getWithAlignment(C, 32));
+ EXPECT_EQ(8U, AL.getParamAlignment(0));
+ EXPECT_EQ(32U, AL.getParamAlignment(1));
+
+ AttrBuilder B;
+ B.addAttribute(Attribute::NonNull);
+ B.addAlignmentAttr(8);
+ AL = AL.addAttributes(C, AttributeList::FirstArgIndex, B);
+ EXPECT_EQ(8U, AL.getParamAlignment(0));
+ EXPECT_EQ(32U, AL.getParamAlignment(1));
+ EXPECT_TRUE(AL.hasParamAttribute(0, Attribute::NonNull));
+}
+
} // end anonymous namespace
More information about the llvm-commits
mailing list