1 //===- TestStackOffset.cpp - StackOffset unit tests------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "AArch64StackOffset.h"
10 #include "gtest/gtest.h"
14 TEST(StackOffset
, MixedSize
) {
15 StackOffset
A(1, MVT::i8
);
16 EXPECT_EQ(1, A
.getBytes());
18 StackOffset
B(2, MVT::i32
);
19 EXPECT_EQ(8, B
.getBytes());
21 StackOffset
C(2, MVT::v4i64
);
22 EXPECT_EQ(64, C
.getBytes());
25 TEST(StackOffset
, Add
) {
26 StackOffset
A(1, MVT::i64
);
27 StackOffset
B(1, MVT::i32
);
28 StackOffset C
= A
+ B
;
29 EXPECT_EQ(12, C
.getBytes());
31 StackOffset
D(1, MVT::i32
);
33 EXPECT_EQ(12, D
.getBytes());
36 TEST(StackOffset
, Sub
) {
37 StackOffset
A(1, MVT::i64
);
38 StackOffset
B(1, MVT::i32
);
39 StackOffset C
= A
- B
;
40 EXPECT_EQ(4, C
.getBytes());
42 StackOffset
D(1, MVT::i64
);
44 EXPECT_EQ(0, D
.getBytes());
47 TEST(StackOffset
, isZero
) {
48 StackOffset
A(0, MVT::i64
);
49 StackOffset
B(0, MVT::i32
);
51 EXPECT_TRUE(!(A
+ B
));
54 TEST(StackOffset
, getForFrameOffset
) {
55 StackOffset
A(1, MVT::i64
);
56 StackOffset
B(1, MVT::i32
);
58 (A
+ B
).getForFrameOffset(ByteSized
);
59 EXPECT_EQ(12, ByteSized
);