Skip to content

Commit 30ed5de

Browse files
author
Mikhail Gudim
committed
addressed review comments.
1 parent 29bf5cd commit 30ed5de

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

llvm/include/llvm/CodeGen/Register.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class Register {
4949

5050
/// Convert a non-negative frame index to a stack slot register value.
5151
static Register index2StackSlot(int FI) {
52-
unsigned FIMasked = FI & Register::StackSlotMask;
53-
assert(isUInt<MaxFrameIndexBitwidth>(FIMasked) &&
52+
assert(isInt<MaxFrameIndexBitwidth>(FI) &&
5453
"Frame index must be at most 30 bit as an unsigned integer");
54+
unsigned FIMasked = FI & Register::StackSlotMask;
5555
return Register(FIMasked | Register::StackSlotZero);
5656
}
5757

llvm/unittests/CodeGen/RegisterTest.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ using namespace llvm;
1313

1414
namespace {
1515
TEST(RegisterTest, Idx2StackSlot) {
16-
ASSERT_EQ(Register::index2StackSlot(0), Register::StackSlotZero);
17-
ASSERT_EQ(Register::index2StackSlot(-1),
18-
Register::StackSlotZero | Register::StackSlotMask);
19-
ASSERT_EQ(Register::index2StackSlot(Register::StackSlotMask),
20-
Register::StackSlotZero | Register::StackSlotMask);
21-
ASSERT_EQ(Register::index2StackSlot(1), Register::StackSlotZero | 1);
16+
EXPECT_EQ(Register::index2StackSlot(0), Register::StackSlotZero);
17+
EXPECT_EQ(Register::index2StackSlot(1), Register::StackSlotZero | 1);
18+
EXPECT_EQ(Register::index2StackSlot(-1), Register::StackSlotZero | Register::StackSlotMask);
19+
// check that we do not crash on the highest possible value of frame index.
20+
EXPECT_NO_FATAL_FAILURE(Register::index2StackSlot((1 << 29) - 1));
21+
// check that we do not crash on the lowest possible value of frame index.
22+
EXPECT_NO_FATAL_FAILURE(Register::index2StackSlot(-(1 << 29)));
2223
}
2324

2425
TEST(RegisterTest, StackSlotIndex) {
25-
Register Reg;
2626
std::vector<int64_t> FIs = {0, 1 - 1, (1 << 29) - 1, -(1 << 29)};
2727

2828
for (int64_t FI : FIs) {
29-
Reg = Register::index2StackSlot(FI);
30-
ASSERT_EQ(Reg.stackSlotIndex(), FI);
29+
Register Reg = Register::index2StackSlot(FI);
30+
EXPECT_EQ(Reg.stackSlotIndex(), FI);
3131
}
3232
}
3333
} // end namespace

0 commit comments

Comments
 (0)