aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests')
-rw-r--r--llvm/unittests/ADT/EquivalenceClassesTest.cpp23
-rw-r--r--llvm/unittests/CodeGen/InstrRefLDVTest.cpp2
-rw-r--r--llvm/unittests/CodeGen/LexicalScopesTest.cpp43
-rw-r--r--llvm/unittests/CodeGen/MFCommon.inc7
-rw-r--r--llvm/unittests/CodeGen/TypeTraitsTest.cpp2
-rw-r--r--llvm/unittests/Support/SipHashTest.cpp7
-rw-r--r--llvm/unittests/Support/VirtualFileSystemTest.cpp32
7 files changed, 98 insertions, 18 deletions
diff --git a/llvm/unittests/ADT/EquivalenceClassesTest.cpp b/llvm/unittests/ADT/EquivalenceClassesTest.cpp
index 3d5c48e..8172ff9 100644
--- a/llvm/unittests/ADT/EquivalenceClassesTest.cpp
+++ b/llvm/unittests/ADT/EquivalenceClassesTest.cpp
@@ -108,6 +108,29 @@ TEST(EquivalenceClassesTest, SimpleErase4) {
EXPECT_FALSE(EqClasses.erase(1));
}
+TEST(EquivalenceClassesTest, EraseKeepsLeaderBit) {
+ EquivalenceClasses<int> EC;
+
+ // Create a set {1, 2} where 1 is the leader.
+ EC.unionSets(1, 2);
+
+ // Verify initial state.
+ EXPECT_EQ(EC.getLeaderValue(2), 1);
+
+ // Erase 2, the non-leader member.
+ EXPECT_TRUE(EC.erase(2));
+
+ // Verify that we have exactly one equivalence class.
+ ASSERT_NE(EC.begin(), EC.end());
+ ASSERT_EQ(std::next(EC.begin()), EC.end());
+
+ // Verify that 1 is still a leader after erasing 2.
+ const auto *Elem = *EC.begin();
+ ASSERT_NE(Elem, nullptr);
+ EXPECT_EQ(Elem->getData(), 1);
+ EXPECT_TRUE(Elem->isLeader()) << "The leader bit was lost!";
+}
+
TEST(EquivalenceClassesTest, TwoSets) {
EquivalenceClasses<int> EqClasses;
// Form sets of odd and even numbers, check that we split them into these
diff --git a/llvm/unittests/CodeGen/InstrRefLDVTest.cpp b/llvm/unittests/CodeGen/InstrRefLDVTest.cpp
index 53bc024..3a625b2 100644
--- a/llvm/unittests/CodeGen/InstrRefLDVTest.cpp
+++ b/llvm/unittests/CodeGen/InstrRefLDVTest.cpp
@@ -159,7 +159,7 @@ public:
// Setup things like the artifical block map, and BlockNo <=> RPO Order
// mappings.
LDV->initialSetup(*MF);
- LDV->LS.initialize(*MF);
+ LDV->LS.scanFunction(*MF);
addMTracker(MF);
return &*LDV;
}
diff --git a/llvm/unittests/CodeGen/LexicalScopesTest.cpp b/llvm/unittests/CodeGen/LexicalScopesTest.cpp
index 563d496..34bd37a 100644
--- a/llvm/unittests/CodeGen/LexicalScopesTest.cpp
+++ b/llvm/unittests/CodeGen/LexicalScopesTest.cpp
@@ -44,6 +44,7 @@ public:
std::unique_ptr<MachineFunction> MF;
DICompileUnit *OurCU;
DIFile *OurFile;
+ DISubroutineType *OurSubT;
DISubprogram *OurFunc;
DILexicalBlock *OurBlock, *AnotherBlock;
DISubprogram *ToInlineFunc;
@@ -103,7 +104,7 @@ public:
OurFile = DIB.createFile("xyzzy.c", "/cave");
OurCU =
DIB.createCompileUnit(dwarf::DW_LANG_C99, OurFile, "nou", false, "", 0);
- auto OurSubT = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
+ OurSubT = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
OurFunc =
DIB.createFunction(OurCU, "bees", "", OurFile, 1, OurSubT, 1,
DINode::FlagZero, DISubprogram::SPFlagDefinition);
@@ -136,10 +137,10 @@ TEST_F(LexicalScopesTest, FlatLayout) {
LexicalScopes LS;
EXPECT_TRUE(LS.empty());
- LS.reset();
+ LS.resetFunction();
EXPECT_EQ(LS.getCurrentFunctionScope(), nullptr);
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
EXPECT_FALSE(LS.empty());
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
EXPECT_EQ(FuncScope->getParent(), nullptr);
@@ -182,7 +183,7 @@ TEST_F(LexicalScopesTest, BlockScopes) {
BuildMI(*MBB4, MBB4->end(), InBlockLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
EXPECT_EQ(FuncScope->getDesc(), OurFunc);
auto &Children = FuncScope->getChildren();
@@ -217,7 +218,7 @@ TEST_F(LexicalScopesTest, InlinedScopes) {
BuildMI(*MBB4, MBB4->end(), InlinedLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
auto &Children = FuncScope->getChildren();
ASSERT_EQ(Children.size(), 1u);
@@ -252,7 +253,7 @@ TEST_F(LexicalScopesTest, FuncWithEmptyGap) {
BuildMI(*MBB4, MBB4->end(), OutermostLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
// A gap in a range that contains no other location, is not actually a
@@ -273,7 +274,7 @@ TEST_F(LexicalScopesTest, FuncWithRealGap) {
MachineInstr *LastI = BuildMI(*MBB4, MBB4->end(), InBlockLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *BlockScope = LS.findLexicalScope(InBlockLoc.get());
ASSERT_NE(BlockScope, nullptr);
@@ -306,7 +307,7 @@ TEST_F(LexicalScopesTest, NotNested) {
MachineInstr *FourthI = BuildMI(*MBB4, MBB4->end(), InBlockLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
LexicalScope *BlockScope = LS.findLexicalScope(InBlockLoc.get());
LexicalScope *OtherBlockScope = LS.findLexicalScope(NotNestedBlockLoc.get());
@@ -344,7 +345,7 @@ TEST_F(LexicalScopesTest, TestDominates) {
BuildMI(*MBB4, MBB4->end(), InBlockLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
LexicalScope *BlockScope = LS.findLexicalScope(InBlockLoc.get());
LexicalScope *OtherBlockScope = LS.findLexicalScope(NotNestedBlockLoc.get());
@@ -386,7 +387,7 @@ TEST_F(LexicalScopesTest, TestGetBlocks) {
BuildMI(*MBB4, MBB4->end(), InBlockLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
LexicalScope *BlockScope = LS.findLexicalScope(InBlockLoc.get());
LexicalScope *OtherBlockScope = LS.findLexicalScope(NotNestedBlockLoc.get());
@@ -443,7 +444,7 @@ TEST_F(LexicalScopesTest, TestMetaInst) {
BuildMI(*MBB4, MBB4->end(), InBlockLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
LexicalScope *BlockScope = LS.findLexicalScope(InBlockLoc.get());
ASSERT_NE(FuncScope, nullptr);
@@ -459,4 +460,24 @@ TEST_F(LexicalScopesTest, TestMetaInst) {
EXPECT_TRUE(LS.dominates(InBlockLoc.get(), MBB4));
}
+// Test function map creation.
+TEST_F(LexicalScopesTest, TestFunctionScan) {
+ auto MF2 = createMachineFunction(Ctx, Mod, "Test2");
+ DIBuilder DIB(Mod, false, OurCU);
+ DISubprogram *Func2 =
+ DIB.createFunction(OurCU, "Func2", "", OurFile, 1, OurSubT, 1,
+ DINode::FlagZero, DISubprogram::SPFlagDefinition);
+ DISubprogram *UnattachedFunc =
+ DIB.createFunction(OurCU, "UnattachedFunc", "", OurFile, 1, OurSubT, 1,
+ DINode::FlagZero, DISubprogram::SPFlagDefinition);
+ MF2->getFunction().setSubprogram(Func2);
+ DIB.finalize();
+
+ LexicalScopes LS;
+ LS.initialize(Mod);
+ ASSERT_EQ(LS.getFunction(OurFunc), &MF->getFunction());
+ ASSERT_EQ(LS.getFunction(Func2), &MF2->getFunction());
+ ASSERT_EQ(LS.getFunction(UnattachedFunc), nullptr);
+}
+
} // anonymous namespace
diff --git a/llvm/unittests/CodeGen/MFCommon.inc b/llvm/unittests/CodeGen/MFCommon.inc
index cb4a241..a86a68c 100644
--- a/llvm/unittests/CodeGen/MFCommon.inc
+++ b/llvm/unittests/CodeGen/MFCommon.inc
@@ -132,10 +132,10 @@ BogusTargetMachine *createTargetMachine() {
return &BogusTM;
}
-std::unique_ptr<MachineFunction> createMachineFunction(LLVMContext &Ctx,
- Module &M) {
+std::unique_ptr<MachineFunction>
+createMachineFunction(LLVMContext &Ctx, Module &M, const Twine &Name = "Test") {
auto Type = FunctionType::get(Type::getVoidTy(Ctx), false);
- auto F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", &M);
+ auto F = Function::Create(Type, GlobalValue::ExternalLinkage, Name, &M);
auto TM = createTargetMachine();
unsigned FunctionNum = 42;
@@ -145,4 +145,3 @@ std::unique_ptr<MachineFunction> createMachineFunction(LLVMContext &Ctx,
return std::make_unique<MachineFunction>(*F, *TM, STI, MMI.getContext(),
FunctionNum);
}
-
diff --git a/llvm/unittests/CodeGen/TypeTraitsTest.cpp b/llvm/unittests/CodeGen/TypeTraitsTest.cpp
index 1c8852f..f0ed0e8 100644
--- a/llvm/unittests/CodeGen/TypeTraitsTest.cpp
+++ b/llvm/unittests/CodeGen/TypeTraitsTest.cpp
@@ -39,7 +39,7 @@ static_assert(std::is_trivially_copyable_v<IdentifyingPassPtr>,
template <class Fn> constexpr bool CheckStdCmpRequirements() {
// std::less and std::equal_to are literal, default constructible, and
// copyable classes.
- Fn f1;
+ Fn f1{};
auto f2 = f1;
auto f3 = std::move(f2);
f2 = f3;
diff --git a/llvm/unittests/Support/SipHashTest.cpp b/llvm/unittests/Support/SipHashTest.cpp
index 7c557eb..3037e64 100644
--- a/llvm/unittests/Support/SipHashTest.cpp
+++ b/llvm/unittests/Support/SipHashTest.cpp
@@ -50,6 +50,13 @@ TEST(SipHashTest, SipHash_2_4_128) {
}
}
+// Tests for the 64-bit stable SipHash wrapper.
+TEST(SipHashTest, StableSipHash) {
+ EXPECT_EQ(0xB2BB69BB0A2AC0F1UL, getStableSipHash(""));
+ EXPECT_EQ(0x9304ABFF427B72E8UL, getStableSipHash("strlen"));
+ EXPECT_EQ(0x55F45179A08AE51BUL, getStableSipHash("_ZN1 ind; f"));
+}
+
// Tests for the ptrauth-specific SipHash wrapper.
TEST(SipHashTest, PointerAuthSipHash) {
// Test some basic cases.
diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp
index 6228de8..d47a4ee 100644
--- a/llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -1941,7 +1941,7 @@ TEST_F(VFSFromYAMLTest, ReturnsExternalPathVFSHit) {
EXPECT_EQ(0, NumDiagnostics);
}
-TEST_F(VFSFromYAMLTest, RootRelativeTest) {
+TEST_F(VFSFromYAMLTest, RootRelativeToOverlayDirTest) {
auto Lower = makeIntrusiveRefCnt<DummyFileSystem>();
Lower->addDirectory("//root/foo/bar");
Lower->addRegularFile("//root/foo/bar/a");
@@ -2004,6 +2004,35 @@ TEST_F(VFSFromYAMLTest, RootRelativeTest) {
#endif
}
+TEST_F(VFSFromYAMLTest, RootRelativeToCWDTest) {
+ auto Lower = makeIntrusiveRefCnt<DummyFileSystem>();
+ Lower->addDirectory("//root/foo/bar");
+ Lower->addRegularFile("//root/foo/bar/a");
+ Lower->addDirectory("//root/foo/bar/cwd");
+ Lower->addRegularFile("//root/foo/bar/cwd/a");
+ Lower->setCurrentWorkingDirectory("//root/foo/bar/cwd");
+ IntrusiveRefCntPtr<vfs::FileSystem> FS =
+ getFromYAMLString("{\n"
+ " 'case-sensitive': false,\n"
+ " 'root-relative': 'cwd',\n"
+ " 'roots': [\n"
+ " { 'name': 'b', 'type': 'file',\n"
+ " 'external-contents': '//root/foo/bar/a'\n"
+ " }\n"
+ " ]\n"
+ "}",
+ Lower, "//root/foo/bar/overlay");
+
+ ASSERT_NE(FS.get(), nullptr);
+
+ ErrorOr<vfs::Status> S1 = FS->status("//root/foo/bar/b");
+ ASSERT_TRUE(S1.getError());
+
+ ErrorOr<vfs::Status> S2 = FS->status("//root/foo/bar/cwd/b");
+ ASSERT_FALSE(S2.getError());
+ EXPECT_EQ("//root/foo/bar/a", S2->getName());
+}
+
TEST_F(VFSFromYAMLTest, ReturnsInternalPathVFSHit) {
auto BaseFS = makeIntrusiveRefCnt<vfs::InMemoryFileSystem>();
BaseFS->addFile("//root/foo/realname", 0,
@@ -2489,6 +2518,7 @@ TEST_F(VFSFromYAMLTest, RelativePaths) {
SmallString<128> CWD;
EC = llvm::sys::fs::current_path(CWD);
ASSERT_FALSE(EC);
+ Lower->setCurrentWorkingDirectory(CWD);
// Filename at root level without a parent directory.
IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString(