summaryrefslogtreecommitdiff
path: root/unittests/Transforms/Utils
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2017-05-08 21:17:08 +0000
committerAdrian Prantl <aprantl@apple.com>2017-05-08 21:17:08 +0000
commit28bd5d128ca5e6fe57c2ca4bf7d5c607debe9404 (patch)
tree5831283adc6ff27a2c33d51bacd7dff09f34e78e /unittests/Transforms/Utils
parentca58fab8c4dfa2f2d1bf680a00497bad260cdc76 (diff)
Make it illegal for two Functions to point to the same DISubprogram
As recently discussed on llvm-dev [1], this patch makes it illegal for two Functions to point to the same DISubprogram and updates FunctionCloner to also clone the debug info of a function to conform to the new requirement. To simplify the implementation it also factors out the creation of inlineAt locations from the Inliner into a general-purpose utility in DILocation. [1] http://lists.llvm.org/pipermail/llvm-dev/2017-May/112661.html <rdar://problem/31926379> Differential Revision: https://reviews.llvm.org/D32975 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302469 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Transforms/Utils')
-rw-r--r--unittests/Transforms/Utils/Cloning.cpp65
1 files changed, 37 insertions, 28 deletions
diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp
index 2f4ee863653..83f146dca70 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;