From 9d1cf4c1663ccd3c6b6168973215fad0f297ca35 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 6 Apr 2015 23:18:49 +0000 Subject: IR: Stop using DIDescriptor::is*() and auto-casting `DIDescriptor`'s subclasses allow construction from incompatible pointers, and `DIDescriptor` defines a series of `isa<>`-like functions (e.g., `isCompileUnit()` instead of `isa()`) that clients tend to use like this: if (DICompileUnit(N).isCompileUnit()) foo(DICompileUnit(N)); These construction patterns work together to make `DIDescriptor` behave differently from normal pointers. Instead, use built-in `isa<>`, `dyn_cast<>`, etc., and only build `DIDescriptor`s from pointers that are valid for their type. I've split this into a few commits for different parts of LLVM and clang (to decrease the patch size and increase the chance of review). Generally the changes I made were NFC, but in a few places I made things stricter if it made sense from the surrounded code. Eventually a follow-up commit will remove the API for the "old" way. llvm-svn: 234255 --- llvm/unittests/Transforms/Utils/Cloning.cpp | 38 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'llvm/unittests/Transforms') diff --git a/llvm/unittests/Transforms/Utils/Cloning.cpp b/llvm/unittests/Transforms/Utils/Cloning.cpp index 185212bc4c8..4b2beb745d0 100644 --- a/llvm/unittests/Transforms/Utils/Cloning.cpp +++ b/llvm/unittests/Transforms/Utils/Cloning.cpp @@ -304,11 +304,9 @@ TEST_F(CloneFunc, Subprogram) { EXPECT_EQ(2U, SubprogramCount); auto Iter = Finder->subprograms().begin(); - DISubprogram Sub1(*Iter); - EXPECT_TRUE(Sub1.isSubprogram()); + DISubprogram Sub1 = cast(*Iter); Iter++; - DISubprogram Sub2(*Iter); - EXPECT_TRUE(Sub2.isSubprogram()); + DISubprogram Sub2 = cast(*Iter); EXPECT_TRUE((Sub1.getFunction() == OldFunc && Sub2.getFunction() == NewFunc) || (Sub1.getFunction() == NewFunc && Sub2.getFunction() == OldFunc)); @@ -322,11 +320,9 @@ TEST_F(CloneFunc, SubprogramInRightCU) { EXPECT_EQ(2U, Finder->compile_unit_count()); auto Iter = Finder->compile_units().begin(); - DICompileUnit CU1(*Iter); - EXPECT_TRUE(CU1.isCompileUnit()); + DICompileUnit CU1 = cast(*Iter); Iter++; - DICompileUnit CU2(*Iter); - EXPECT_TRUE(CU2.isCompileUnit()); + DICompileUnit CU2 = cast(*Iter); EXPECT_TRUE(CU1.getSubprograms().getNumElements() == 0 || CU2.getSubprograms().getNumElements() == 0); } @@ -355,10 +351,8 @@ TEST_F(CloneFunc, InstructionOwnership) { EXPECT_EQ(OldDL.getCol(), NewDL.getCol()); // But that they belong to different functions - DISubprogram OldSubprogram(OldDL.getScope()); - DISubprogram NewSubprogram(NewDL.getScope()); - EXPECT_TRUE(OldSubprogram.isSubprogram()); - EXPECT_TRUE(NewSubprogram.isSubprogram()); + DISubprogram OldSubprogram = cast(OldDL.getScope()); + DISubprogram NewSubprogram = cast(NewDL.getScope()); EXPECT_EQ(OldFunc, OldSubprogram.getFunction()); EXPECT_EQ(NewFunc, NewSubprogram.getFunction()); } @@ -394,21 +388,25 @@ TEST_F(CloneFunc, DebugIntrinsics) { getParent()->getParent()); // Old variable must belong to the old function - EXPECT_EQ(OldFunc, DISubprogram(DIVariable(OldIntrin->getVariable()) - .getContext()).getFunction()); + EXPECT_EQ(OldFunc, DISubprogram(cast( + OldIntrin->getVariable()->getScope())) + .getFunction()); // New variable must belong to the New function - EXPECT_EQ(NewFunc, DISubprogram(DIVariable(NewIntrin->getVariable()) - .getContext()).getFunction()); + EXPECT_EQ(NewFunc, DISubprogram(cast( + NewIntrin->getVariable()->getScope())) + .getFunction()); } else if (DbgValueInst* OldIntrin = dyn_cast(&OldI)) { DbgValueInst* NewIntrin = dyn_cast(&NewI); EXPECT_TRUE(NewIntrin); // Old variable must belong to the old function - EXPECT_EQ(OldFunc, DISubprogram(DIVariable(OldIntrin->getVariable()) - .getContext()).getFunction()); + EXPECT_EQ(OldFunc, DISubprogram(cast( + OldIntrin->getVariable()->getScope())) + .getFunction()); // New variable must belong to the New function - EXPECT_EQ(NewFunc, DISubprogram(DIVariable(NewIntrin->getVariable()) - .getContext()).getFunction()); + EXPECT_EQ(NewFunc, DISubprogram(cast( + NewIntrin->getVariable()->getScope())) + .getFunction()); } ++OldIter; -- cgit v1.2.3