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; } 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)