summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/AttributesTest.cpp
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/unittests/IR/AttributesTest.cpp
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/unittests/IR/AttributesTest.cpp')
-rw-r--r--llvm/unittests/IR/AttributesTest.cpp19
1 files changed, 19 insertions, 0 deletions
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