[PATCH] D25040: [Coverage] Do not emit coverage mappings for functions marked 'unused'

Vedant Kumar via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 28 13:02:46 PDT 2016


vsk created this revision.
vsk added a reviewer: arphaman.
vsk added a subscriber: cfe-commits.

This lets us suppress coverage reporting for ~30 functions across llvm and clang.

I passed the test case through llvm-cov and verified that 'unused' functions are skipped, e.g:

```
    3|       |void __attribute__((unused)) f1() {}
```

https://reviews.llvm.org/D25040

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/skip_unused_function.cpp

Index: test/CoverageMapping/skip_unused_function.cpp
===================================================================
--- /dev/null
+++ test/CoverageMapping/skip_unused_function.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s | count 0
+
+void __attribute__((unused)) f1() {}
+
+template<typename T>
+class C1 {
+public:
+  void __attribute__((unused)) m1() {}
+
+  static void __attribute__((unused)) m2(T x) {}
+
+  void __attribute__((unused)) m3();
+};
+
+template <typename T>
+void C1<T>::m3() {
+  C1<int> v1;
+  v1.m1();
+  C1<float>::m2(0.0);
+}
Index: lib/CodeGen/CoverageMappingGen.cpp
===================================================================
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -645,6 +645,11 @@
   }
 
   void VisitDecl(const Decl *D) {
+    // Do not visit unused functions.
+    if (const auto *FD = dyn_cast<FunctionDecl>(D))
+      if (FD->hasAttr<UnusedAttr>())
+        return;
+
     Stmt *Body = D->getBody();
 
     // Do not propagate region counts into system headers.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25040.72882.patch
Type: text/x-patch
Size: 1144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160928/85ef5f88/attachment.bin>


More information about the cfe-commits mailing list