summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2017-05-19 22:23:47 +0000
committerReid Kleckner <rnk@google.com>2017-05-19 22:23:47 +0000
commitbf6b3b1564f1846c5c729b582b4bc3f97d946770 (patch)
treebe89cb95ed883c6a0f284d28a9624af2d5d8e66f /llvm
parent78706a3daebcac93517b1560a1092828b3505ea5 (diff)
downloadbcm5719-llvm-bf6b3b1564f1846c5c729b582b4bc3f97d946770.tar.gz
bcm5719-llvm-bf6b3b1564f1846c5c729b582b4bc3f97d946770.zip
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. llvm-svn: 303458
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/IR/Attributes.cpp2
-rw-r--r--llvm/unittests/IR/AttributesTest.cpp19
2 files changed, 20 insertions, 1 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index ce60367a6c8..adb31d127a2 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1058,7 +1058,7 @@ AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index,
#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!");
diff --git a/llvm/unittests/IR/AttributesTest.cpp b/llvm/unittests/IR/AttributesTest.cpp
index 0df7a847f8a..7af4aebd540 100644
--- a/llvm/unittests/IR/AttributesTest.cpp
+++ b/llvm/unittests/IR/AttributesTest.cpp
@@ -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
OpenPOWER on IntegriCloud