1 //===- CCStateTest.cpp ----------------------------------------------------===//
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 "llvm/CodeGen/CallingConvLower.h"
10 #include "llvm/CodeGen/CodeGenTargetMachineImpl.h"
11 #include "llvm/CodeGen/MachineFunction.h"
12 #include "llvm/CodeGen/MachineModuleInfo.h"
13 #include "llvm/CodeGen/TargetFrameLowering.h"
14 #include "llvm/CodeGen/TargetInstrInfo.h"
15 #include "llvm/CodeGen/TargetLowering.h"
16 #include "llvm/CodeGen/TargetRegisterInfo.h"
17 #include "llvm/CodeGen/TargetSubtargetInfo.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/MC/TargetRegistry.h"
20 #include "gtest/gtest.h"
26 #include "MFCommon.inc"
28 TEST(CCStateTest
, NegativeOffsets
) {
30 Module
Mod("Module", Ctx
);
31 auto MF
= createMachineFunction(Ctx
, Mod
);
33 SmallVector
<CCValAssign
, 8> Locs
;
34 CCState
Info(CallingConv::C
, /*IsVarArg=*/false, *MF
, Locs
, Ctx
,
35 /*NegativeOffsets=*/true);
37 ASSERT_EQ(Info
.AllocateStack(1, Align(1)), -1);
38 ASSERT_EQ(Info
.AllocateStack(1, Align(2)), -2);
39 ASSERT_EQ(Info
.AllocateStack(1, Align(2)), -4);
40 ASSERT_EQ(Info
.AllocateStack(1, Align(1)), -5);
41 ASSERT_EQ(Info
.AllocateStack(2, Align(2)), -8);
42 ASSERT_EQ(Info
.AllocateStack(2, Align(2)), -10);
43 ASSERT_EQ(Info
.AllocateStack(2, Align(1)), -12);
44 ASSERT_EQ(Info
.AllocateStack(1, Align(1)), -13);
45 ASSERT_EQ(Info
.getStackSize(), 13u);
46 ASSERT_EQ(Info
.getAlignedCallFrameSize(), 14u);