aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/CodeGen/LexicalScopesTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/CodeGen/LexicalScopesTest.cpp')
-rw-r--r--llvm/unittests/CodeGen/LexicalScopesTest.cpp43
1 files changed, 32 insertions, 11 deletions
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