[PATCH] D50340: [Local] Add dbg location on unreachable inst in changeToUnreachable

Anastasis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 7 12:29:33 PDT 2018


gramanas updated this revision to Diff 159572.
gramanas marked 4 inline comments as done.
gramanas added a comment.

- update according to comments


Repository:
  rL LLVM

https://reviews.llvm.org/D50340

Files:
  lib/Transforms/Utils/Local.cpp
  unittests/Transforms/Utils/Local.cpp


Index: unittests/Transforms/Utils/Local.cpp
===================================================================
--- unittests/Transforms/Utils/Local.cpp
+++ unittests/Transforms/Utils/Local.cpp
@@ -581,6 +581,55 @@
   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));
+  ASSERT_TRUE(B.hasMetadata());
+
+  DebugLoc DLB = B.getDebugLoc();
+  EXPECT_EQ(DLA, DLB);
+}
+
 TEST(Local, ReplaceAllDbgUsesWith) {
   using namespace llvm::dwarf;
 
@@ -863,4 +912,4 @@
   };
 
   runWithDomTree(*M, "f", checkRUBlocksRetVal);
-}
\ No newline at end of file
+}
Index: lib/Transforms/Utils/Local.cpp
===================================================================
--- lib/Transforms/Utils/Local.cpp
+++ lib/Transforms/Utils/Local.cpp
@@ -1930,7 +1930,8 @@
     CallInst *CallTrap = CallInst::Create(TrapFn, "", I);
     CallTrap->setDebugLoc(I->getDebugLoc());
   }
-  new UnreachableInst(I->getContext(), I);
+  auto *UI = new UnreachableInst(I->getContext(), I);
+  UI->setDebugLoc(I->getDebugLoc());
 
   // All instructions after this are dead.
   unsigned NumInstrsRemoved = 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50340.159572.patch
Type: text/x-patch
Size: 2562 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180807/2bd5a67b/attachment.bin>


More information about the llvm-commits mailing list