[PATCH] D46815: [DbgInfo] Fix StripDebugInfo

Son Tuan Vu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 13 16:00:01 PDT 2018


tyb0807 created this revision.
tyb0807 added a reviewer: vsk.
Herald added subscribers: llvm-commits, JDevlieghere.

Hello,

As discussed in https://reviews.llvm.org/D46525, here is my attempt to remove debug intrinsics in `StripDebugInfo`.


Repository:
  rL LLVM

https://reviews.llvm.org/D46815

Files:
  lib/IR/DebugInfo.cpp
  test/DebugInfo/strip-intrinsic-dbg.ll


Index: test/DebugInfo/strip-intrinsic-dbg.ll
===================================================================
--- test/DebugInfo/strip-intrinsic-dbg.ll
+++ test/DebugInfo/strip-intrinsic-dbg.ll
@@ -0,0 +1,39 @@
+; RUN: opt -S -strip-debug <%s | FileCheck %s
+
+; CHECK-LABEL: foo
+define dso_local i32 @foo(i8 signext %arg) local_unnamed_addr !dbg !7 {
+entry:
+  call void @llvm.dbg.value(metadata i8 %arg, metadata !13, metadata !DIExpression()), !dbg !15
+  call void @llvm.dbg.value(metadata i32 1, metadata !14, metadata !DIExpression()), !dbg !16
+  %conv = sext i8 %arg to i32, !dbg !17
+  %add = add nsw i32 %conv, 1, !dbg !18
+  ret i32 %add, !dbg !19
+}
+
+; CHECK-NOT: llvm.dbg.
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 (trunk 332201)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "strip-intrinsic-dbg.c", directory: "/dsk/l1/misc/vusontuan/Projects/llvm/tests/")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 7.0.0 (trunk 332201)"}
+!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 22, type: !8, isLocal: false, isDefinition: true, scopeLine: 23, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10, !11}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+!12 = !{!13, !14}
+!13 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 22, type: !11)
+!14 = !DILocalVariable(name: "x", scope: !7, file: !1, line: 24, type: !10)
+!15 = !DILocation(line: 22, column: 14, scope: !7)
+!16 = !DILocation(line: 24, column: 9, scope: !7)
+!17 = !DILocation(line: 26, column: 16, scope: !7)
+!18 = !DILocation(line: 26, column: 14, scope: !7)
+!19 = !DILocation(line: 26, column: 5, scope: !7)
Index: lib/IR/DebugInfo.cpp
===================================================================
--- lib/IR/DebugInfo.cpp
+++ lib/IR/DebugInfo.cpp
@@ -380,6 +380,14 @@
   if (GVMaterializer *Materializer = M.getMaterializer())
     Materializer->setStripDebugInfo();
 
+  for (auto FI = M.begin(), End = M.end(); FI != End;) {
+    Function &F = *FI++;
+    if (F.getName().startswith("llvm.dbg.")) {
+      F.eraseFromParent();
+      Changed = true;
+    }
+  }
+
   return Changed;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46815.146533.patch
Type: text/x-patch
Size: 2639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180513/9b4b276e/attachment.bin>


More information about the llvm-commits mailing list