[compiler-rt] r339194 - [Coverage] Ignore 'unused' functions with non-zero execution counts

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 7 15:25:36 PDT 2018


Author: vedantk
Date: Tue Aug  7 15:25:36 2018
New Revision: 339194

URL: http://llvm.org/viewvc/llvm-project?rev=339194&view=rev
Log:
[Coverage] Ignore 'unused' functions with non-zero execution counts

Frontends emit 'unused' coverage mapping records for functions which are
provably unused in a TU. These unused records contain a single counter
with CounterKind::Zero. However, a function may be unused in one TU and
used in another. When this happens, prefer the records with a full set
of counters instead of arbitrarily picking the first loaded record.

There is no impact on the single-TU case. In the multiple-TU case, this
resolves issues causing a function to appear unused when it's not.

Testing: check-{llvm,clang,compiler-rt}

rdar://42981322

Added:
    compiler-rt/trunk/test/profile/instrprof-merging.cpp

Added: compiler-rt/trunk/test/profile/instrprof-merging.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-merging.cpp?rev=339194&view=auto
==============================================================================
--- compiler-rt/trunk/test/profile/instrprof-merging.cpp (added)
+++ compiler-rt/trunk/test/profile/instrprof-merging.cpp Tue Aug  7 15:25:36 2018
@@ -0,0 +1,53 @@
+// 1) Compile shared code into different object files and into an executable.
+
+// RUN: %clangxx_profgen -fcoverage-mapping %s -c -o %t.v1.o -D_VERSION_1
+// RUN: %clangxx_profgen -fcoverage-mapping %s -c -o %t.v2.o -D_VERSION_2
+// RUN: %clangxx_profgen -fcoverage-mapping %t.v1.o %t.v2.o -o %t.exe
+
+// 2) Collect profile data.
+
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.exe
+// RUN: llvm-profdata merge %t.profraw -o %t.profdata
+
+// 3) Generate coverage reports from the different object files and the exe.
+
+// RUN: llvm-cov show %t.v1.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V1-ONLY
+// RUN: llvm-cov show %t.v2.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V2,V2-ONLY
+// RUN: llvm-cov show %t.v1.o -object %t.v2.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V2
+// RUN: llvm-cov show %t.exe -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V2
+
+// 4) Verify that coverage reporting on the aggregate coverage mapping shows
+//    hits for all code. (We used to arbitrarily pick a mapping from one binary
+//    and prefer it over others.) When only limited coverage information is
+//    available (just from one binary), don't try to guess any region counts.
+
+struct A {
+  A() {}    // V1: [[@LINE]]{{ *}}|{{ *}}1
+            // V1-ONLY: [[@LINE+1]]{{ *}}|{{ *}}|
+  A(int) {} // V2-ONLY: [[@LINE-2]]{{ *}}|{{ *}}|
+            // V2: [[@LINE-1]]{{ *}}|{{ *}}1
+};
+
+#ifdef _VERSION_1
+
+void foo();
+
+void bar() {
+  A x;      // V1: [[@LINE]]{{ *}}|{{ *}}1
+}
+
+int main() {
+  foo();    // V1: [[@LINE]]{{ *}}|{{ *}}1
+  bar();
+  return 0;
+}
+
+#endif // _VERSION_1
+
+#ifdef _VERSION_2
+
+void foo() {
+  A x{0};   // V2: [[@LINE]]{{ *}}|{{ *}}1
+}
+
+#endif // _VERSION_2




More information about the llvm-commits mailing list