summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Transforms
diff options
context:
space:
mode:
authorAnastasis Grammenos <anastasis.gramm2@gmail.com>2018-08-07 20:21:56 +0000
committerAnastasis Grammenos <anastasis.gramm2@gmail.com>2018-08-07 20:21:56 +0000
commit52d5283483cb21c0512b432d9beea3c4dc1f45b3 (patch)
treed42892eb8b649177bf00d660e2738c9b5fe085b9 /llvm/unittests/Transforms
parent7fb68d267904f8de84d6b0a46de9ba15ffbd2bc1 (diff)
downloadbcm5719-llvm-52d5283483cb21c0512b432d9beea3c4dc1f45b3.tar.gz
bcm5719-llvm-52d5283483cb21c0512b432d9beea3c4dc1f45b3.zip
[Local] Add dbg location on unreachable inst in changeToUnreachable
As show in https://bugs.llvm.org/show_bug.cgi?id=37960 it would be desirable to have debug location in the unreachable instruction. Also adds a unti test for this function. Differential Revision: https://reviews.llvm.org/D50340 llvm-svn: 339173
Diffstat (limited to 'llvm/unittests/Transforms')
-rw-r--r--llvm/unittests/Transforms/Utils/Local.cpp50
1 files changed, 49 insertions, 1 deletions
diff --git a/llvm/unittests/Transforms/Utils/Local.cpp b/llvm/unittests/Transforms/Utils/Local.cpp
index e106c883274..bb36d013357 100644
--- a/llvm/unittests/Transforms/Utils/Local.cpp
+++ b/llvm/unittests/Transforms/Utils/Local.cpp
@@ -581,6 +581,54 @@ TEST_F(SalvageDebugInfoTest, RecursiveBlockSimplification) {
verifyDebugValuesAreSalvaged();
}
+TEST(Local, ChangeToUnreachable) {
+ LLVMContext Ctx;
+
+ std::unique_ptr<Module> M = parseIR(Ctx,
+ R"(
+ define internal void @foo() !dbg !6 {
+ entry:
+ ret void, !dbg !8
+ }
+
+ !llvm.dbg.cu = !{!0}
+ !llvm.debugify = !{!3, !4}
+ !llvm.module.flags = !{!5}
+
+ !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+ !1 = !DIFile(filename: "test.ll", directory: "/")
+ !2 = !{}
+ !3 = !{i32 1}
+ !4 = !{i32 0}
+ !5 = !{i32 2, !"Debug Info Version", i32 3}
+ !6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !1, line: 1, type: !7, isLocal: true, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !2)
+ !7 = !DISubroutineType(types: !2)
+ !8 = !DILocation(line: 1, column: 1, scope: !6)
+ )");
+
+ bool BrokenDebugInfo = true;
+ verifyModule(*M, &errs(), &BrokenDebugInfo);
+ ASSERT_FALSE(BrokenDebugInfo);
+
+ Function &F = *cast<Function>(M->getNamedValue("foo"));
+
+ BasicBlock &BB = F.front();
+ Instruction &A = BB.front();
+ DebugLoc DLA = A.getDebugLoc();
+
+ ASSERT_TRUE(isa<ReturnInst>(&A));
+ // One instruction should be affected.
+ EXPECT_EQ(changeToUnreachable(&A, /*UseLLVMTrap*/false), 1U);
+
+ Instruction &B = BB.front();
+
+ // There should be an uncreachable instruction.
+ ASSERT_TRUE(isa<UnreachableInst>(&B));
+
+ DebugLoc DLB = B.getDebugLoc();
+ EXPECT_EQ(DLA, DLB);
+}
+
TEST(Local, ReplaceAllDbgUsesWith) {
using namespace llvm::dwarf;
@@ -863,4 +911,4 @@ TEST(Local, RemoveUnreachableBlocks) {
};
runWithDomTree(*M, "f", checkRUBlocksRetVal);
-} \ No newline at end of file
+}
OpenPOWER on IntegriCloud