diff options
Diffstat (limited to 'unittests/Transforms/Utils/Cloning.cpp')
-rw-r--r-- | unittests/Transforms/Utils/Cloning.cpp | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp index 2f4ee8636530..83f146dca704 100644 --- a/unittests/Transforms/Utils/Cloning.cpp +++ b/unittests/Transforms/Utils/Cloning.cpp @@ -296,7 +296,6 @@ protected: Value* AllocaContent = IBuilder.getInt32(1); Instruction* Store = IBuilder.CreateStore(AllocaContent, Alloca); IBuilder.SetCurrentDebugLocation(DebugLoc::get(5, 2, Subprogram)); - Instruction* Terminator = IBuilder.CreateRetVoid(); // Create a local variable around the alloca auto *IntType = DBuilder.createBasicType("int", 32, dwarf::DW_ATE_signed); @@ -306,12 +305,25 @@ protected: auto *DL = DILocation::get(Subprogram->getContext(), 5, 0, Subprogram); DBuilder.insertDeclare(Alloca, Variable, E, DL, Store); DBuilder.insertDbgValueIntrinsic(AllocaContent, 0, Variable, E, DL, - Terminator); - // Finalize the debug info + Entry); + // Also create an inlined variable. + auto *InlinedSP = + DBuilder.createFunction(CU, "inlined", "inlined", File, 8, FuncType, + true, true, 9, DINode::FlagZero, false); + auto *InlinedVar = + DBuilder.createAutoVariable(InlinedSP, "inlined", File, 5, IntType, true); + auto *Scope = DBuilder.createLexicalBlock( + DBuilder.createLexicalBlockFile(InlinedSP, File), File, 1, 1); + auto InlinedDL = + DebugLoc::get(9, 4, Scope, DebugLoc::get(5, 2, Subprogram)); + IBuilder.SetCurrentDebugLocation(InlinedDL); + DBuilder.insertDeclare(Alloca, InlinedVar, E, InlinedDL, Store); + IBuilder.CreateStore(IBuilder.getInt32(2), Alloca); + // Finalize the debug info. DBuilder.finalize(); + IBuilder.CreateRetVoid(); - - // Create another, empty, compile unit + // Create another, empty, compile unit. DIBuilder DBuilder2(*M); DBuilder2.createCompileUnit(dwarf::DW_LANG_C99, DBuilder.createFile("extra.c", "/file/dir"), @@ -345,15 +357,8 @@ TEST_F(CloneFunc, NewFunctionCreated) { // function, while the original subprogram still points to the old one. TEST_F(CloneFunc, Subprogram) { EXPECT_FALSE(verifyModule(*M)); - - unsigned SubprogramCount = Finder->subprogram_count(); - EXPECT_EQ(1U, SubprogramCount); - - auto Iter = Finder->subprograms().begin(); - auto *Sub = cast<DISubprogram>(*Iter); - - EXPECT_TRUE(Sub == OldFunc->getSubprogram()); - EXPECT_TRUE(Sub == NewFunc->getSubprogram()); + EXPECT_EQ(3U, Finder->subprogram_count()); + EXPECT_NE(NewFunc->getSubprogram(), OldFunc->getSubprogram()); } // Test that instructions in the old function still belong to it in the @@ -380,8 +385,8 @@ TEST_F(CloneFunc, InstructionOwnership) { EXPECT_EQ(OldDL.getCol(), NewDL.getCol()); // But that they belong to different functions - auto *OldSubprogram = cast<DISubprogram>(OldDL.getScope()); - auto *NewSubprogram = cast<DISubprogram>(NewDL.getScope()); + auto *OldSubprogram = cast<DISubprogram>(OldDL.getInlinedAtScope()); + auto *NewSubprogram = cast<DISubprogram>(NewDL.getInlinedAtScope()); EXPECT_EQ(OldFunc->getSubprogram(), OldSubprogram); EXPECT_EQ(NewFunc->getSubprogram(), NewSubprogram); } @@ -416,22 +421,26 @@ TEST_F(CloneFunc, DebugIntrinsics) { EXPECT_EQ(NewFunc, cast<AllocaInst>(NewIntrin->getAddress())-> getParent()->getParent()); - // Old variable must belong to the old function - EXPECT_EQ(OldFunc->getSubprogram(), - cast<DISubprogram>(OldIntrin->getVariable()->getScope())); - // New variable must belong to the New function - EXPECT_EQ(NewFunc->getSubprogram(), - cast<DISubprogram>(NewIntrin->getVariable()->getScope())); + if (!OldIntrin->getDebugLoc()->getInlinedAt()) { + // Old variable must belong to the old function. + EXPECT_EQ(OldFunc->getSubprogram(), + cast<DISubprogram>(OldIntrin->getVariable()->getScope())); + // New variable must belong to the new function. + EXPECT_EQ(NewFunc->getSubprogram(), + cast<DISubprogram>(NewIntrin->getVariable()->getScope())); + } } else if (DbgValueInst* OldIntrin = dyn_cast<DbgValueInst>(&OldI)) { DbgValueInst* NewIntrin = dyn_cast<DbgValueInst>(&NewI); EXPECT_TRUE(NewIntrin); - // Old variable must belong to the old function - EXPECT_EQ(OldFunc->getSubprogram(), - cast<DISubprogram>(OldIntrin->getVariable()->getScope())); - // New variable must belong to the New function - EXPECT_EQ(NewFunc->getSubprogram(), - cast<DISubprogram>(NewIntrin->getVariable()->getScope())); + if (!OldIntrin->getDebugLoc()->getInlinedAt()) { + // Old variable must belong to the old function. + EXPECT_EQ(OldFunc->getSubprogram(), + cast<DISubprogram>(OldIntrin->getVariable()->getScope())); + // New variable must belong to the new function. + EXPECT_EQ(NewFunc->getSubprogram(), + cast<DISubprogram>(NewIntrin->getVariable()->getScope())); + } } ++OldIter; |