mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:40:38 +00:00
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
This commit is contained in:
parent
708aeafa8b
commit
1bad4eeadf
@ -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!");
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user