[AArch64] Fix SDNode type mismatches between *.td files and ISel (#116523)
[llvm-project.git] / llvm / unittests / CodeGen / DwarfStringPoolEntryRefTest.cpp
blob8e82d11732e2540e130f69a076c4ba96636ce026
1 //===- llvm/unittest/CodeGen/DwarfStringPoolEntryRefTest.cpp --------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/CodeGen/DwarfStringPoolEntry.h"
10 #include "llvm/Support/Allocator.h"
11 #include "llvm/Testing/Support/Error.h"
13 #include "gmock/gmock.h"
14 #include "gtest/gtest.h"
16 using namespace llvm;
18 TEST(DwarfStringPoolEntryRefTest, TestFullEntry) {
19 BumpPtrAllocator Allocator;
20 StringMapEntry<DwarfStringPoolEntry> *StringEntry1 =
21 StringMapEntry<DwarfStringPoolEntry>::create(
22 "Key1", Allocator, DwarfStringPoolEntry{nullptr, 0, 0});
24 EXPECT_TRUE(StringEntry1->getKey() == "Key1");
25 EXPECT_TRUE(StringEntry1->second.Symbol == nullptr);
26 EXPECT_TRUE(StringEntry1->second.Offset == 0);
27 EXPECT_TRUE(StringEntry1->second.Index == 0);
29 DwarfStringPoolEntryRef Ref1(*StringEntry1);
30 EXPECT_TRUE(Ref1.getString() == "Key1");
31 EXPECT_TRUE(Ref1.getOffset() == 0);
32 EXPECT_TRUE(Ref1.getIndex() == 0);
34 DwarfStringPoolEntryRef Ref2(*StringEntry1);
35 EXPECT_TRUE(Ref2.getString() == "Key1");
36 EXPECT_TRUE(Ref2.getOffset() == 0);
37 EXPECT_TRUE(Ref2.getIndex() == 0);
38 EXPECT_TRUE(Ref1 == Ref2);
39 EXPECT_FALSE(Ref1 != Ref2);
41 StringMapEntry<DwarfStringPoolEntry> *StringEntry2 =
42 StringMapEntry<DwarfStringPoolEntry>::create(
43 "Key2", Allocator, DwarfStringPoolEntry{nullptr, 0x1000, 1});
44 EXPECT_TRUE(StringEntry2->getKey() == "Key2");
45 EXPECT_TRUE(StringEntry2->second.Symbol == nullptr);
46 EXPECT_TRUE(StringEntry2->second.Offset == 0x1000);
47 EXPECT_TRUE(StringEntry2->second.Index == 1);
49 DwarfStringPoolEntryRef Ref3(*StringEntry2);
50 EXPECT_TRUE(Ref3.getString() == "Key2");
51 EXPECT_TRUE(Ref3.getOffset() == 0x1000);
52 EXPECT_TRUE(Ref3.getIndex() == 1);
53 EXPECT_TRUE(Ref1 != Ref3);
56 bool isEntryEqual(const DwarfStringPoolEntry &LHS,
57 const DwarfStringPoolEntry &RHS) {
58 return LHS.Symbol == RHS.Symbol && LHS.Offset == RHS.Offset &&
59 LHS.Index == RHS.Index;
62 TEST(DwarfStringPoolEntryRefTest, TestShortEntry) {
63 DwarfStringPoolEntryWithExtString DwarfEntry1 = {{nullptr, 0, 0}, "Key1"};
65 DwarfStringPoolEntryRef Ref1(DwarfEntry1);
66 EXPECT_TRUE(Ref1.getString() == "Key1");
67 EXPECT_TRUE(Ref1.getOffset() == 0);
68 EXPECT_TRUE(Ref1.getIndex() == 0);
69 EXPECT_TRUE(isEntryEqual(Ref1.getEntry(), DwarfEntry1));
71 DwarfStringPoolEntryRef Ref2(DwarfEntry1);
72 EXPECT_TRUE(Ref2.getString() == "Key1");
73 EXPECT_TRUE(Ref2.getOffset() == 0);
74 EXPECT_TRUE(isEntryEqual(Ref2.getEntry(), DwarfEntry1));
75 EXPECT_TRUE(Ref1 == Ref2);
76 EXPECT_FALSE(Ref1 != Ref2);
78 DwarfStringPoolEntryWithExtString DwarfEntry2 = {{nullptr, 0x1000, 1},
79 "Key2"};
81 DwarfStringPoolEntryRef Ref3(DwarfEntry2);
82 EXPECT_TRUE(Ref3.getString() == "Key2");
83 EXPECT_TRUE(Ref3.getOffset() == 0x1000);
84 EXPECT_TRUE(Ref3.getIndex() == 1);
85 EXPECT_TRUE(isEntryEqual(Ref3.getEntry(), DwarfEntry2));
86 EXPECT_TRUE(Ref1 != Ref3);
89 TEST(DwarfStringPoolEntryRefTest, CompareFullAndShort) {
90 BumpPtrAllocator Allocator;
92 DwarfStringPoolEntryWithExtString DwarfEntry1 = {{nullptr, 0, 0}, "Key1"};
93 DwarfStringPoolEntryRef Ref1(DwarfEntry1);
95 StringMapEntry<DwarfStringPoolEntry> *StringEntry2 =
96 StringMapEntry<DwarfStringPoolEntry>::create(
97 "Key1", Allocator, DwarfStringPoolEntry{nullptr, 0, 0});
98 DwarfStringPoolEntryRef Ref2(*StringEntry2);
100 EXPECT_FALSE(Ref1 == Ref2);