[PATCH] D25689: [opt] Strip coverage if debug info is not present

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 17 12:03:39 PDT 2016


davide created this revision.
davide added reviewers: aprantl, vsk.
davide added a subscriber: llvm-commits.

This is reduced from: https://llvm.org/bugs/show_bug.cgi?id=30702
If -coverage is passed, but -g is not, clang populates the PassManager pipeline with StripSymbols(debugOnly = true).
The stripSymbol pass therefore scans the list of named metadata, drops !llvm.dbg.cu, but leaves !llvm.gcov and !0 (the compileUnit MD) around. The verifier runs, and finds out that there's a CU not listed in !llvm.dbg.cu (as it was previously dropped) -> assertion.
When we strip debug info, so, check if there's coverage data around, and strip it as well, in order to avoid pending metadata left around.


https://reviews.llvm.org/D25689

Files:
  lib/IR/DebugInfo.cpp
  test/Transforms/StripSymbols/strip-cov.ll


Index: test/Transforms/StripSymbols/strip-cov.ll
===================================================================
--- /dev/null
+++ test/Transforms/StripSymbols/strip-cov.ll
@@ -0,0 +1,20 @@
+; RUN: opt -S %s -strip -o - | FileCheck %s
+
+; CHECK-NOT: !llvm.dbg.cu
+; CHECK-NOT: !llvm.gcov
+
+; CHECK: !llvm.module.flags = !{!0}
+; CHECK: !0 = !{i32 2, !"Debug Info Version", i32 3}
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3}
+!llvm.gcov = !{!4}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 (trunk 284352) (llvm/trunk 284353)", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, enums: !2)
+!1 = !DIFile(filename: "/dev/null", directory: "/home/davide/work/llvm/build/bin")
+!2 = !{}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{!"/scratch/patatino/build/bin/null.gcno", !"/scratch/patatino/build/bin/null.gcda", !0}
Index: lib/IR/DebugInfo.cpp
===================================================================
--- lib/IR/DebugInfo.cpp
+++ lib/IR/DebugInfo.cpp
@@ -272,7 +272,11 @@
          NME = M.named_metadata_end(); NMI != NME;) {
     NamedMDNode *NMD = &*NMI;
     ++NMI;
-    if (NMD->getName().startswith("llvm.dbg.")) {
+
+    // We're stripping debug info, and without them, coverage information
+    // doesn't quite make sense.
+    if (NMD->getName().startswith("llvm.dbg.") ||
+        NMD->getName() == "llvm.gcov") {
       NMD->eraseFromParent();
       Changed = true;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25689.74879.patch
Type: text/x-patch
Size: 1587 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161017/219d5860/attachment.bin>


More information about the llvm-commits mailing list