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.


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.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to