blob: 807a2f0315240cadf046bde56e32a9168fb06a01 [file] [log] [blame]
Nick Lewycky1f715782009-09-27 21:39:46 +00001//===- Cloning.cpp - Unit tests for the Cloner ----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Alon Mishne07d949f2014-03-12 14:42:51 +000010#include "llvm/Transforms/Utils/Cloning.h"
11#include "llvm/ADT/ArrayRef.h"
Chandler Carruth130cec22012-12-04 10:23:08 +000012#include "llvm/ADT/STLExtras.h"
Quentin Colombet4156c982014-04-22 02:17:11 +000013#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000014#include "llvm/IR/Argument.h"
15#include "llvm/IR/Constant.h"
Alon Mishne07d949f2014-03-12 14:42:51 +000016#include "llvm/IR/DIBuilder.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000017#include "llvm/IR/DebugInfo.h"
Joey Gouly81259292013-04-10 10:37:38 +000018#include "llvm/IR/Function.h"
Joey Gouly81259292013-04-10 10:37:38 +000019#include "llvm/IR/IRBuilder.h"
Alon Mishne07d949f2014-03-12 14:42:51 +000020#include "llvm/IR/InstIterator.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000021#include "llvm/IR/Instructions.h"
Alon Mishne07d949f2014-03-12 14:42:51 +000022#include "llvm/IR/IntrinsicInst.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000023#include "llvm/IR/LLVMContext.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000024#include "llvm/IR/Module.h"
Duncan P. N. Exon Smith4bd905e2015-03-30 21:35:14 +000025#include "llvm/IR/Verifier.h"
Chandler Carruth130cec22012-12-04 10:23:08 +000026#include "gtest/gtest.h"
Nick Lewycky1f715782009-09-27 21:39:46 +000027
28using namespace llvm;
29
David Blaikiea379b1812011-12-20 02:50:00 +000030namespace {
Chandler Carruth35e67062012-06-20 08:39:27 +000031
Nick Lewycky84189ab2010-03-13 19:58:26 +000032class CloneInstruction : public ::testing::Test {
33protected:
Alexander Kornienkof817c1c2015-04-11 02:11:45 +000034 void SetUp() override { V = nullptr; }
Nick Lewycky84189ab2010-03-13 19:58:26 +000035
36 template <typename T>
37 T *clone(T *V1) {
38 Value *V2 = V1->clone();
Quentin Colombet4156c982014-04-22 02:17:11 +000039 Orig.insert(V1);
40 Clones.insert(V2);
Nick Lewycky84189ab2010-03-13 19:58:26 +000041 return cast<T>(V2);
42 }
43
Quentin Colombet4156c982014-04-22 02:17:11 +000044 void eraseClones() {
45 DeleteContainerPointers(Clones);
46 }
Nick Lewycky84189ab2010-03-13 19:58:26 +000047
Alexander Kornienkof817c1c2015-04-11 02:11:45 +000048 void TearDown() override {
Nick Lewycky84189ab2010-03-13 19:58:26 +000049 eraseClones();
Quentin Colombet4156c982014-04-22 02:17:11 +000050 DeleteContainerPointers(Orig);
51 delete V;
Nick Lewycky84189ab2010-03-13 19:58:26 +000052 }
53
Quentin Colombet4156c982014-04-22 02:17:11 +000054 SmallPtrSet<Value *, 4> Orig; // Erase on exit
55 SmallPtrSet<Value *, 4> Clones; // Erase in eraseClones
Nick Lewycky84189ab2010-03-13 19:58:26 +000056
Nick Lewycky1f715782009-09-27 21:39:46 +000057 LLVMContext context;
Quentin Colombet4156c982014-04-22 02:17:11 +000058 Value *V;
Nick Lewycky84189ab2010-03-13 19:58:26 +000059};
60
61TEST_F(CloneInstruction, OverflowBits) {
Quentin Colombet4156c982014-04-22 02:17:11 +000062 V = new Argument(Type::getInt32Ty(context));
Nick Lewycky1f715782009-09-27 21:39:46 +000063
Quentin Colombet4156c982014-04-22 02:17:11 +000064 BinaryOperator *Add = BinaryOperator::Create(Instruction::Add, V, V);
65 BinaryOperator *Sub = BinaryOperator::Create(Instruction::Sub, V, V);
66 BinaryOperator *Mul = BinaryOperator::Create(Instruction::Mul, V, V);
Nick Lewycky1f715782009-09-27 21:39:46 +000067
Nick Lewycky84189ab2010-03-13 19:58:26 +000068 BinaryOperator *AddClone = this->clone(Add);
69 BinaryOperator *SubClone = this->clone(Sub);
70 BinaryOperator *MulClone = this->clone(Mul);
71
72 EXPECT_FALSE(AddClone->hasNoUnsignedWrap());
73 EXPECT_FALSE(AddClone->hasNoSignedWrap());
74 EXPECT_FALSE(SubClone->hasNoUnsignedWrap());
75 EXPECT_FALSE(SubClone->hasNoSignedWrap());
76 EXPECT_FALSE(MulClone->hasNoUnsignedWrap());
77 EXPECT_FALSE(MulClone->hasNoSignedWrap());
78
79 eraseClones();
Nick Lewycky1f715782009-09-27 21:39:46 +000080
81 Add->setHasNoUnsignedWrap();
82 Sub->setHasNoUnsignedWrap();
83 Mul->setHasNoUnsignedWrap();
84
Nick Lewycky84189ab2010-03-13 19:58:26 +000085 AddClone = this->clone(Add);
86 SubClone = this->clone(Sub);
87 MulClone = this->clone(Mul);
88
89 EXPECT_TRUE(AddClone->hasNoUnsignedWrap());
90 EXPECT_FALSE(AddClone->hasNoSignedWrap());
91 EXPECT_TRUE(SubClone->hasNoUnsignedWrap());
92 EXPECT_FALSE(SubClone->hasNoSignedWrap());
93 EXPECT_TRUE(MulClone->hasNoUnsignedWrap());
94 EXPECT_FALSE(MulClone->hasNoSignedWrap());
95
96 eraseClones();
Nick Lewycky1f715782009-09-27 21:39:46 +000097
98 Add->setHasNoSignedWrap();
99 Sub->setHasNoSignedWrap();
100 Mul->setHasNoSignedWrap();
101
Nick Lewycky84189ab2010-03-13 19:58:26 +0000102 AddClone = this->clone(Add);
103 SubClone = this->clone(Sub);
104 MulClone = this->clone(Mul);
105
106 EXPECT_TRUE(AddClone->hasNoUnsignedWrap());
107 EXPECT_TRUE(AddClone->hasNoSignedWrap());
108 EXPECT_TRUE(SubClone->hasNoUnsignedWrap());
109 EXPECT_TRUE(SubClone->hasNoSignedWrap());
110 EXPECT_TRUE(MulClone->hasNoUnsignedWrap());
111 EXPECT_TRUE(MulClone->hasNoSignedWrap());
112
113 eraseClones();
Nick Lewycky1f715782009-09-27 21:39:46 +0000114
115 Add->setHasNoUnsignedWrap(false);
116 Sub->setHasNoUnsignedWrap(false);
117 Mul->setHasNoUnsignedWrap(false);
118
Nick Lewycky84189ab2010-03-13 19:58:26 +0000119 AddClone = this->clone(Add);
120 SubClone = this->clone(Sub);
121 MulClone = this->clone(Mul);
122
123 EXPECT_FALSE(AddClone->hasNoUnsignedWrap());
124 EXPECT_TRUE(AddClone->hasNoSignedWrap());
125 EXPECT_FALSE(SubClone->hasNoUnsignedWrap());
126 EXPECT_TRUE(SubClone->hasNoSignedWrap());
127 EXPECT_FALSE(MulClone->hasNoUnsignedWrap());
128 EXPECT_TRUE(MulClone->hasNoSignedWrap());
Nick Lewycky1f715782009-09-27 21:39:46 +0000129}
130
Nick Lewycky84189ab2010-03-13 19:58:26 +0000131TEST_F(CloneInstruction, Inbounds) {
Quentin Colombet4156c982014-04-22 02:17:11 +0000132 V = new Argument(Type::getInt32PtrTy(context));
Nick Lewycky84189ab2010-03-13 19:58:26 +0000133
Nick Lewycky1f715782009-09-27 21:39:46 +0000134 Constant *Z = Constant::getNullValue(Type::getInt32Ty(context));
135 std::vector<Value *> ops;
136 ops.push_back(Z);
David Blaikieb3a39062015-03-14 21:40:10 +0000137 GetElementPtrInst *GEP =
138 GetElementPtrInst::Create(Type::getInt32Ty(context), V, ops);
Nick Lewycky84189ab2010-03-13 19:58:26 +0000139 EXPECT_FALSE(this->clone(GEP)->isInBounds());
Nick Lewycky1f715782009-09-27 21:39:46 +0000140
141 GEP->setIsInBounds();
Nick Lewycky84189ab2010-03-13 19:58:26 +0000142 EXPECT_TRUE(this->clone(GEP)->isInBounds());
Nick Lewycky1f715782009-09-27 21:39:46 +0000143}
144
Nick Lewycky84189ab2010-03-13 19:58:26 +0000145TEST_F(CloneInstruction, Exact) {
Quentin Colombet4156c982014-04-22 02:17:11 +0000146 V = new Argument(Type::getInt32Ty(context));
Nick Lewycky1f715782009-09-27 21:39:46 +0000147
Quentin Colombet4156c982014-04-22 02:17:11 +0000148 BinaryOperator *SDiv = BinaryOperator::Create(Instruction::SDiv, V, V);
Nick Lewycky84189ab2010-03-13 19:58:26 +0000149 EXPECT_FALSE(this->clone(SDiv)->isExact());
Nick Lewycky1f715782009-09-27 21:39:46 +0000150
151 SDiv->setIsExact(true);
Nick Lewycky84189ab2010-03-13 19:58:26 +0000152 EXPECT_TRUE(this->clone(SDiv)->isExact());
Nick Lewycky1f715782009-09-27 21:39:46 +0000153}
Chandler Carruth35e67062012-06-20 08:39:27 +0000154
Joey Gouly81259292013-04-10 10:37:38 +0000155TEST_F(CloneInstruction, Attributes) {
156 Type *ArgTy1[] = { Type::getInt32PtrTy(context) };
157 FunctionType *FT1 = FunctionType::get(Type::getVoidTy(context), ArgTy1, false);
158
159 Function *F1 = Function::Create(FT1, Function::ExternalLinkage);
160 BasicBlock *BB = BasicBlock::Create(context, "", F1);
161 IRBuilder<> Builder(BB);
162 Builder.CreateRetVoid();
163
164 Function *F2 = Function::Create(FT1, Function::ExternalLinkage);
165
166 Attribute::AttrKind AK[] = { Attribute::NoCapture };
167 AttributeSet AS = AttributeSet::get(context, 0, AK);
168 Argument *A = F1->arg_begin();
169 A->addAttr(AS);
170
171 SmallVector<ReturnInst*, 4> Returns;
172 ValueToValueMapTy VMap;
173 VMap[A] = UndefValue::get(A->getType());
174
175 CloneFunctionInto(F2, F1, VMap, false, Returns);
176 EXPECT_FALSE(F2->arg_begin()->hasNoCaptureAttr());
Joey Gouly51f6fb92013-04-10 23:21:26 +0000177
178 delete F1;
179 delete F2;
Joey Gouly81259292013-04-10 10:37:38 +0000180}
181
Reid Kleckner23798a92014-03-26 22:26:35 +0000182TEST_F(CloneInstruction, CallingConvention) {
183 Type *ArgTy1[] = { Type::getInt32PtrTy(context) };
184 FunctionType *FT1 = FunctionType::get(Type::getVoidTy(context), ArgTy1, false);
185
186 Function *F1 = Function::Create(FT1, Function::ExternalLinkage);
187 F1->setCallingConv(CallingConv::Cold);
188 BasicBlock *BB = BasicBlock::Create(context, "", F1);
189 IRBuilder<> Builder(BB);
190 Builder.CreateRetVoid();
191
192 Function *F2 = Function::Create(FT1, Function::ExternalLinkage);
193
194 SmallVector<ReturnInst*, 4> Returns;
195 ValueToValueMapTy VMap;
196 VMap[F1->arg_begin()] = F2->arg_begin();
197
198 CloneFunctionInto(F2, F1, VMap, false, Returns);
199 EXPECT_EQ(CallingConv::Cold, F2->getCallingConv());
200
201 delete F1;
202 delete F2;
203}
204
Alon Mishne07d949f2014-03-12 14:42:51 +0000205class CloneFunc : public ::testing::Test {
206protected:
Alexander Kornienkof817c1c2015-04-11 02:11:45 +0000207 void SetUp() override {
Alon Mishne07d949f2014-03-12 14:42:51 +0000208 SetupModule();
209 CreateOldFunc();
210 CreateNewFunc();
211 SetupFinder();
212 }
213
Alexander Kornienkof817c1c2015-04-11 02:11:45 +0000214 void TearDown() override { delete Finder; }
Alon Mishne07d949f2014-03-12 14:42:51 +0000215
216 void SetupModule() {
217 M = new Module("", C);
218 }
219
220 void CreateOldFunc() {
221 FunctionType* FuncType = FunctionType::get(Type::getVoidTy(C), false);
222 OldFunc = Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", M);
223 CreateOldFunctionBodyAndDI();
224 }
225
226 void CreateOldFunctionBodyAndDI() {
227 DIBuilder DBuilder(*M);
228 IRBuilder<> IBuilder(C);
229
230 // Function DI
231 DIFile File = DBuilder.createFile("filename.c", "/file/dir/");
Manman Renf8a19672014-07-28 22:24:06 +0000232 DITypeArray ParamTypes = DBuilder.getOrCreateTypeArray(None);
Alon Mishne07d949f2014-03-12 14:42:51 +0000233 DICompositeType FuncType = DBuilder.createSubroutineType(File, ParamTypes);
234 DICompileUnit CU = DBuilder.createCompileUnit(dwarf::DW_LANG_C99,
235 "filename.c", "/file/dir", "CloneFunc", false, "", 0);
236
237 DISubprogram Subprogram = DBuilder.createFunction(CU, "f", "f", File, 4,
238 FuncType, true, true, 3, 0, false, OldFunc);
239
240 // Function body
241 BasicBlock* Entry = BasicBlock::Create(C, "", OldFunc);
242 IBuilder.SetInsertPoint(Entry);
243 DebugLoc Loc = DebugLoc::get(3, 2, Subprogram);
244 IBuilder.SetCurrentDebugLocation(Loc);
245 AllocaInst* Alloca = IBuilder.CreateAlloca(IntegerType::getInt32Ty(C));
246 IBuilder.SetCurrentDebugLocation(DebugLoc::get(4, 2, Subprogram));
247 Value* AllocaContent = IBuilder.getInt32(1);
248 Instruction* Store = IBuilder.CreateStore(AllocaContent, Alloca);
249 IBuilder.SetCurrentDebugLocation(DebugLoc::get(5, 2, Subprogram));
250 Instruction* Terminator = IBuilder.CreateRetVoid();
251
252 // Create a local variable around the alloca
253 DIType IntType = DBuilder.createBasicType("int", 32, 0,
254 dwarf::DW_ATE_signed);
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000255 DIExpression E = DBuilder.createExpression();
Alon Mishne07d949f2014-03-12 14:42:51 +0000256 DIVariable Variable = DBuilder.createLocalVariable(
257 dwarf::DW_TAG_auto_variable, Subprogram, "x", File, 5, IntType, true);
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000258 DBuilder.insertDeclare(Alloca, Variable, E, Store);
259 DBuilder.insertDbgValueIntrinsic(AllocaContent, 0, Variable, E, Terminator);
Alon Mishne07d949f2014-03-12 14:42:51 +0000260 // Finalize the debug info
261 DBuilder.finalize();
262
263
264 // Create another, empty, compile unit
265 DIBuilder DBuilder2(*M);
266 DBuilder2.createCompileUnit(dwarf::DW_LANG_C99,
267 "extra.c", "/file/dir", "CloneFunc", false, "", 0);
268 DBuilder2.finalize();
269 }
270
271 void CreateNewFunc() {
272 ValueToValueMapTy VMap;
Craig Topper66f09ad2014-06-08 22:29:17 +0000273 NewFunc = CloneFunction(OldFunc, VMap, true, nullptr);
Alon Mishne07d949f2014-03-12 14:42:51 +0000274 M->getFunctionList().push_back(NewFunc);
275 }
276
277 void SetupFinder() {
278 Finder = new DebugInfoFinder();
279 Finder->processModule(*M);
280 }
281
282 LLVMContext C;
283 Function* OldFunc;
284 Function* NewFunc;
285 Module* M;
286 DebugInfoFinder* Finder;
287};
288
289// Test that a new, distinct function was created.
290TEST_F(CloneFunc, NewFunctionCreated) {
291 EXPECT_NE(OldFunc, NewFunc);
292}
293
294// Test that a new subprogram entry was added and is pointing to the new
295// function, while the original subprogram still points to the old one.
296TEST_F(CloneFunc, Subprogram) {
Duncan P. N. Exon Smith4bd905e2015-03-30 21:35:14 +0000297 EXPECT_FALSE(verifyModule(*M));
298
Alon Mishne07d949f2014-03-12 14:42:51 +0000299 unsigned SubprogramCount = Finder->subprogram_count();
Justin Bognerf404b932014-03-12 17:00:52 +0000300 EXPECT_EQ(2U, SubprogramCount);
Alon Mishne07d949f2014-03-12 14:42:51 +0000301
Alon Mishnead312152014-03-18 09:41:07 +0000302 auto Iter = Finder->subprograms().begin();
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000303 DISubprogram Sub1 = cast<MDSubprogram>(*Iter);
Alon Mishne07d949f2014-03-12 14:42:51 +0000304 Iter++;
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000305 DISubprogram Sub2 = cast<MDSubprogram>(*Iter);
Alon Mishne07d949f2014-03-12 14:42:51 +0000306
Duncan P. N. Exon Smith537b4a82015-04-14 03:40:37 +0000307 EXPECT_TRUE(
308 (Sub1->getFunction() == OldFunc && Sub2->getFunction() == NewFunc) ||
309 (Sub1->getFunction() == NewFunc && Sub2->getFunction() == OldFunc));
Alon Mishne07d949f2014-03-12 14:42:51 +0000310}
311
312// Test that the new subprogram entry was not added to the CU which doesn't
313// contain the old subprogram entry.
314TEST_F(CloneFunc, SubprogramInRightCU) {
Duncan P. N. Exon Smith4bd905e2015-03-30 21:35:14 +0000315 EXPECT_FALSE(verifyModule(*M));
316
Justin Bognerf404b932014-03-12 17:00:52 +0000317 EXPECT_EQ(2U, Finder->compile_unit_count());
Alon Mishne07d949f2014-03-12 14:42:51 +0000318
Alon Mishnead312152014-03-18 09:41:07 +0000319 auto Iter = Finder->compile_units().begin();
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000320 DICompileUnit CU1 = cast<MDCompileUnit>(*Iter);
Alon Mishne07d949f2014-03-12 14:42:51 +0000321 Iter++;
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000322 DICompileUnit CU2 = cast<MDCompileUnit>(*Iter);
Duncan P. N. Exon Smith000fa2c2015-04-07 04:14:33 +0000323 EXPECT_TRUE(CU1.getSubprograms().size() == 0 ||
324 CU2.getSubprograms().size() == 0);
Alon Mishne07d949f2014-03-12 14:42:51 +0000325}
326
327// Test that instructions in the old function still belong to it in the
328// metadata, while instruction in the new function belong to the new one.
329TEST_F(CloneFunc, InstructionOwnership) {
Duncan P. N. Exon Smith4bd905e2015-03-30 21:35:14 +0000330 EXPECT_FALSE(verifyModule(*M));
331
Alon Mishne07d949f2014-03-12 14:42:51 +0000332 inst_iterator OldIter = inst_begin(OldFunc);
333 inst_iterator OldEnd = inst_end(OldFunc);
334 inst_iterator NewIter = inst_begin(NewFunc);
335 inst_iterator NewEnd = inst_end(NewFunc);
336 while (OldIter != OldEnd && NewIter != NewEnd) {
337 Instruction& OldI = *OldIter;
338 Instruction& NewI = *NewIter;
339 EXPECT_NE(&OldI, &NewI);
340
341 EXPECT_EQ(OldI.hasMetadata(), NewI.hasMetadata());
342 if (OldI.hasMetadata()) {
343 const DebugLoc& OldDL = OldI.getDebugLoc();
344 const DebugLoc& NewDL = NewI.getDebugLoc();
345
346 // Verify that the debug location data is the same
347 EXPECT_EQ(OldDL.getLine(), NewDL.getLine());
348 EXPECT_EQ(OldDL.getCol(), NewDL.getCol());
Duncan P. N. Exon Smith4fff3ec2015-03-30 21:05:29 +0000349
Alon Mishne07d949f2014-03-12 14:42:51 +0000350 // But that they belong to different functions
Duncan P. N. Exon Smith537b4a82015-04-14 03:40:37 +0000351 auto *OldSubprogram = cast<MDSubprogram>(OldDL.getScope());
352 auto *NewSubprogram = cast<MDSubprogram>(NewDL.getScope());
353 EXPECT_EQ(OldFunc, OldSubprogram->getFunction());
354 EXPECT_EQ(NewFunc, NewSubprogram->getFunction());
Alon Mishne07d949f2014-03-12 14:42:51 +0000355 }
356
357 ++OldIter;
358 ++NewIter;
359 }
360 EXPECT_EQ(OldEnd, OldIter);
361 EXPECT_EQ(NewEnd, NewIter);
362}
363
364// Test that the arguments for debug intrinsics in the new function were
365// properly cloned
366TEST_F(CloneFunc, DebugIntrinsics) {
Duncan P. N. Exon Smith4bd905e2015-03-30 21:35:14 +0000367 EXPECT_FALSE(verifyModule(*M));
368
Alon Mishne07d949f2014-03-12 14:42:51 +0000369 inst_iterator OldIter = inst_begin(OldFunc);
370 inst_iterator OldEnd = inst_end(OldFunc);
371 inst_iterator NewIter = inst_begin(NewFunc);
372 inst_iterator NewEnd = inst_end(NewFunc);
373 while (OldIter != OldEnd && NewIter != NewEnd) {
374 Instruction& OldI = *OldIter;
375 Instruction& NewI = *NewIter;
376 if (DbgDeclareInst* OldIntrin = dyn_cast<DbgDeclareInst>(&OldI)) {
377 DbgDeclareInst* NewIntrin = dyn_cast<DbgDeclareInst>(&NewI);
378 EXPECT_TRUE(NewIntrin);
379
380 // Old address must belong to the old function
381 EXPECT_EQ(OldFunc, cast<AllocaInst>(OldIntrin->getAddress())->
382 getParent()->getParent());
383 // New address must belong to the new function
384 EXPECT_EQ(NewFunc, cast<AllocaInst>(NewIntrin->getAddress())->
385 getParent()->getParent());
386
387 // Old variable must belong to the old function
Duncan P. N. Exon Smith537b4a82015-04-14 03:40:37 +0000388 EXPECT_EQ(OldFunc,
389 cast<MDSubprogram>(OldIntrin->getVariable()->getScope())
390 ->getFunction());
Alon Mishne07d949f2014-03-12 14:42:51 +0000391 // New variable must belong to the New function
Duncan P. N. Exon Smith537b4a82015-04-14 03:40:37 +0000392 EXPECT_EQ(NewFunc,
393 cast<MDSubprogram>(NewIntrin->getVariable()->getScope())
394 ->getFunction());
Alon Mishne07d949f2014-03-12 14:42:51 +0000395 } else if (DbgValueInst* OldIntrin = dyn_cast<DbgValueInst>(&OldI)) {
396 DbgValueInst* NewIntrin = dyn_cast<DbgValueInst>(&NewI);
397 EXPECT_TRUE(NewIntrin);
398
399 // Old variable must belong to the old function
Duncan P. N. Exon Smith537b4a82015-04-14 03:40:37 +0000400 EXPECT_EQ(OldFunc,
401 cast<MDSubprogram>(OldIntrin->getVariable()->getScope())
402 ->getFunction());
Alon Mishne07d949f2014-03-12 14:42:51 +0000403 // New variable must belong to the New function
Duncan P. N. Exon Smith537b4a82015-04-14 03:40:37 +0000404 EXPECT_EQ(NewFunc,
405 cast<MDSubprogram>(NewIntrin->getVariable()->getScope())
406 ->getFunction());
Alon Mishne07d949f2014-03-12 14:42:51 +0000407 }
408
409 ++OldIter;
410 ++NewIter;
411 }
412}
413
Chandler Carruth35e67062012-06-20 08:39:27 +0000414}