Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 941c219

Browse files
dcciadrian-prantl
authored andcommitted
[opt] Strip coverage if debug info is not present.
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) -> crash. When we strip debug info, so, check if there's coverage data, and strip it as well, in order to avoid pending metadata left around. Differential Revision: https://reviews.llvm.org/D25689 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284418 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit ac38a64)
1 parent 429bfc9 commit 941c219

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/IR/DebugInfo.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ bool llvm::StripDebugInfo(Module &M) {
272272
NME = M.named_metadata_end(); NMI != NME;) {
273273
NamedMDNode *NMD = &*NMI;
274274
++NMI;
275-
if (NMD->getName().startswith("llvm.dbg.")) {
275+
276+
// We're stripping debug info, and without them, coverage information
277+
// doesn't quite make sense.
278+
if (NMD->getName().startswith("llvm.dbg.") ||
279+
NMD->getName() == "llvm.gcov") {
276280
NMD->eraseFromParent();
277281
Changed = true;
278282
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: opt -S %s -strip -o - | FileCheck %s
2+
3+
; CHECK-NOT: !llvm.dbg.cu
4+
; CHECK-NOT: !llvm.gcov
5+
6+
; CHECK: !llvm.module.flags = !{!0}
7+
; CHECK: !0 = !{i32 2, !"Debug Info Version", i32 3}
8+
9+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
10+
target triple = "x86_64-unknown-linux-gnu"
11+
12+
!llvm.dbg.cu = !{!0}
13+
!llvm.module.flags = !{!3}
14+
!llvm.gcov = !{!4}
15+
16+
!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)
17+
!1 = !DIFile(filename: "/dev/null", directory: "/home/davide/work/llvm/build/bin")
18+
!2 = !{}
19+
!3 = !{i32 2, !"Debug Info Version", i32 3}
20+
!4 = !{!"/scratch/patatino/build/bin/null.gcno", !"/scratch/patatino/build/bin/null.gcda", !0}

0 commit comments

Comments
 (0)