[PATCH] D52034: [Clang] Add options -Xclang -coverage-filter and -Xclang -coverage-exclude to filter the files to instrument with gcov

2018-11-06 Thread calixte via Phabricator via cfe-commits
calixte updated this revision to Diff 172752.
calixte added a comment.

Change options names to -fprofile-exclude-files & -fprofile-filter-files and 
add some doc in UserManual.


Repository:
  rC Clang

https://reviews.llvm.org/D52034

Files:
  docs/UsersManual.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/code-coverage-filter1.h
  test/CodeGen/Inputs/code-coverage-filter2.h
  test/CodeGen/code-coverage-filter.c

Index: test/CodeGen/code-coverage-filter.c
===
--- /dev/null
+++ test/CodeGen/code-coverage-filter.c
@@ -0,0 +1,84 @@
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes %s -o - \
+// RUN:| FileCheck -check-prefix=ALL %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -fprofile-exclude-files=".*\.h$" %s -o - \
+// RUN:| FileCheck -check-prefix=NO-HEADER %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -fprofile-filter-files=".*\.c$" %s -o - \
+// RUN:| FileCheck -check-prefix=NO-HEADER %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -fprofile-filter-files=".*\.c$:.*1\.h$" %s -o - \
+// RUN:| FileCheck -check-prefix=NO-HEADER2 %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -fprofile-exclude-files=".*2\.h$:.*1\.h$" %s -o - \
+// RUN:| FileCheck -check-prefix=JUST-C %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -fprofile-exclude-files=".*code\-coverage\-filter\.c$" %s -o - \
+// RUN:| FileCheck -check-prefix=HEADER %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -fprofile-filter-files=".*\.c$" -fprofile-exclude-files=".*\.c$" %s -o - \
+// RUN:| FileCheck -check-prefix=NONE %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -fprofile-filter-files=".*\.c$" -fprofile-exclude-files=".*\.h$" %s -o - \
+// RUN:| FileCheck -check-prefix=JUST-C %s
+
+#include "Inputs/code-coverage-filter1.h"
+#include "Inputs/code-coverage-filter2.h"
+
+void test() {
+  test1();
+  test2();
+}
+
+// ALL: define void @test1() #0 {{.*}}
+// ALL: {{.*}}__llvm_gcov_ctr{{.*}}
+// ALL: ret void
+// ALL: define void @test2() #0 {{.*}}
+// ALL: {{.*}}__llvm_gcov_ctr{{.*}}
+// ALL: ret void
+// ALL: define void @test() #0 {{.*}}
+// ALL: {{.*}}__llvm_gcov_ctr{{.*}}
+// ALL: ret void
+
+// NO-HEADER: define void @test1() #0 {{.*}}
+// NO-HEADER-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NO-HEADER: ret void
+// NO-HEADER: define void @test2() #0 {{.*}}
+// NO-HEADER-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NO-HEADER: ret void
+// NO-HEADER: define void @test() #0 {{.*}}
+// NO-HEADER: {{.*}}__llvm_gcov_ctr{{.*}}
+// NO-HEADER: ret void
+
+// NO-HEADER2: define void @test1() #0 {{.*}}
+// NO-HEADER2: {{.*}}__llvm_gcov_ctr{{.*}}
+// NO-HEADER2: ret void
+// NO-HEADER2: define void @test2() #0 {{.*}}
+// NO-HEADER2-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NO-HEADER2: ret void
+// NO-HEADER2: define void @test() #0 {{.*}}
+// NO-HEADER2: {{.*}}__llvm_gcov_ctr{{.*}}
+// NO-HEADER2: ret void
+
+// JUST-C: define void @test1() #0 {{.*}}
+// JUST-C-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// JUST-C: ret void
+// JUST-C: define void @test2() #0 {{.*}}
+// JUST-C-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// JUST-C: ret void
+// JUST-C: define void @test() #0 {{.*}}
+// JUST-C: {{.*}}__llvm_gcov_ctr{{.*}}
+// JUST-C: ret void
+
+// HEADER: define void @test1() #0 {{.*}}
+// HEADER: {{.*}}__llvm_gcov_ctr{{.*}}
+// HEADER: ret void
+// HEADER: define void @test2() #0 {{.*}}
+// HEADER: {{.*}}__llvm_gcov_ctr{{.*}}
+// HEADER: ret void
+// HEADER: define void @test() #0 {{.*}}
+// HEADER-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// HEADER: ret void
+
+// NONE: define void @test1() #0 {{.*}}
+// NONE-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NONE: ret void
+// NONE: define void @test2() #0 {{.*}}
+// NONE-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NONE: ret void
+// NONE: define void @test() #0 {{.*}}
+// NONE-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NONE: ret void
Index: test/CodeGen/Inputs/code-coverage-filter2.h
===
--- /dev/null
+++ test/CodeGen/Inputs/code-coverage-filter2.h
@@ -0,0 +1 @@
+void test2() {}
Index: test/CodeGen/Inputs/code-coverage-filter1.h
===
--- /dev/null
+++ test/CodeGen/Inputs/code-coverage-filter1.h
@@ -0,0 +1 @@
+void test1() {}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -811,6 +811,10 @@
 Opts.CoverageExtraChecksum = Args.hasArg(OPT_coverage_cfg_checksum);
 Opts.CoverageNoFunctionNamesInData =
 

[PATCH] D52034: [Clang] Add options -Xclang -coverage-filter and -Xclang -coverage-exclude to filter the files to instrument with gcov

2018-10-25 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

In https://reviews.llvm.org/D52034#1246379, @calixte wrote:

> I reported a bug for gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87442


Thank you!

> @vsk I'd like to add documentation in Docs/UsersManual.rst, but I've no idea 
> on what's a good place for this (I look for option 
> -coverage-no-function-names-in-data, but I didn't get anything). So could you 
> give a me a clue please ?

That's the right file to edit. Please create a section for gcov-based 
profiling. I won't ask that you describe the entire gcov pipeline, but it would 
really help to have a description of the driver flags you're adding & some 
examples of how to use them.


Repository:
  rC Clang

https://reviews.llvm.org/D52034



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52034: [Clang] Add options -Xclang -coverage-filter and -Xclang -coverage-exclude to filter the files to instrument with gcov

2018-10-25 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

In https://reviews.llvm.org/D52034#1268277, @calixte wrote:

> @vsk, gcc guys are ok for -fprofile-filter-files and  
> -fprofile-exclude-files, are you ok with that ?


That sounds fine to me.

> Should these options prefixed by -Xclang or not ?

I don't think they should be. These options should be easy to surface to users.


Repository:
  rC Clang

https://reviews.llvm.org/D52034



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52034: [Clang] Add options -Xclang -coverage-filter and -Xclang -coverage-exclude to filter the files to instrument with gcov

2018-10-18 Thread calixte via Phabricator via cfe-commits
calixte added a comment.

@vsk, gcc guys are ok for -fprofile-filter-files and  -fprofile-exclude-files, 
are you ok with that ?
Should these options prefixed by -Xclang or not ?


Repository:
  rC Clang

https://reviews.llvm.org/D52034



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52034: [Clang] Add options -Xclang -coverage-filter and -Xclang -coverage-exclude to filter the files to instrument with gcov

2018-09-26 Thread calixte via Phabricator via cfe-commits
calixte added a comment.

I reported a bug for gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87442
@vsk I'd like to add documentation in Docs/UsersManual.rst, but I've no idea on 
what's a good place for this (I look for option 
-coverage-no-function-names-in-data, but I didn't get anything). So could you 
give a me a clue please ?


Repository:
  rC Clang

https://reviews.llvm.org/D52034



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52034: [Clang] Add options -Xclang -coverage-filter and -Xclang -coverage-exclude to filter the files to instrument with gcov

2018-09-26 Thread calixte via Phabricator via cfe-commits
calixte updated this revision to Diff 167101.
calixte added a comment.

Fix tests


Repository:
  rC Clang

https://reviews.llvm.org/D52034

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/code-coverage-filter1.h
  test/CodeGen/Inputs/code-coverage-filter2.h
  test/CodeGen/code-coverage-filter.c

Index: test/CodeGen/code-coverage-filter.c
===
--- /dev/null
+++ test/CodeGen/code-coverage-filter.c
@@ -0,0 +1,84 @@
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes %s -o - \
+// RUN:| FileCheck -check-prefix=ALL %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -coverage-exclude=".*\.h$" %s -o - \
+// RUN:| FileCheck -check-prefix=NO-HEADER %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -coverage-filter=".*\.c$" %s -o - \
+// RUN:| FileCheck -check-prefix=NO-HEADER %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -coverage-filter=".*\.c$:.*1\.h$" %s -o - \
+// RUN:| FileCheck -check-prefix=NO-HEADER2 %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -coverage-exclude=".*2\.h$:.*1\.h$" %s -o - \
+// RUN:| FileCheck -check-prefix=JUST-C %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -coverage-exclude=".*code\-coverage\-filter\.c$" %s -o - \
+// RUN:| FileCheck -check-prefix=HEADER %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -coverage-filter=".*\.c$" -coverage-exclude=".*\.c$" %s -o - \
+// RUN:| FileCheck -check-prefix=NONE %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -femit-coverage-notes -coverage-filter=".*\.c$" -coverage-exclude=".*\.h$" %s -o - \
+// RUN:| FileCheck -check-prefix=JUST-C %s
+
+#include "Inputs/code-coverage-filter1.h"
+#include "Inputs/code-coverage-filter2.h"
+
+void test() {
+test1();
+test2();
+}
+
+// ALL: define void @test1() #0 {{.*}}
+// ALL: {{.*}}__llvm_gcov_ctr{{.*}}
+// ALL: ret void
+// ALL: define void @test2() #0 {{.*}}
+// ALL: {{.*}}__llvm_gcov_ctr{{.*}}
+// ALL: ret void
+// ALL: define void @test() #0 {{.*}}
+// ALL: {{.*}}__llvm_gcov_ctr{{.*}}
+// ALL: ret void
+
+// NO-HEADER: define void @test1() #0 {{.*}}
+// NO-HEADER-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NO-HEADER: ret void
+// NO-HEADER: define void @test2() #0 {{.*}}
+// NO-HEADER-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NO-HEADER: ret void
+// NO-HEADER: define void @test() #0 {{.*}}
+// NO-HEADER: {{.*}}__llvm_gcov_ctr{{.*}}
+// NO-HEADER: ret void
+
+// NO-HEADER2: define void @test1() #0 {{.*}}
+// NO-HEADER2: {{.*}}__llvm_gcov_ctr{{.*}}
+// NO-HEADER2: ret void
+// NO-HEADER2: define void @test2() #0 {{.*}}
+// NO-HEADER2-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NO-HEADER2: ret void
+// NO-HEADER2: define void @test() #0 {{.*}}
+// NO-HEADER2: {{.*}}__llvm_gcov_ctr{{.*}}
+// NO-HEADER2: ret void
+
+// JUST-C: define void @test1() #0 {{.*}}
+// JUST-C-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// JUST-C: ret void
+// JUST-C: define void @test2() #0 {{.*}}
+// JUST-C-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// JUST-C: ret void
+// JUST-C: define void @test() #0 {{.*}}
+// JUST-C: {{.*}}__llvm_gcov_ctr{{.*}}
+// JUST-C: ret void
+
+// HEADER: define void @test1() #0 {{.*}}
+// HEADER: {{.*}}__llvm_gcov_ctr{{.*}}
+// HEADER: ret void
+// HEADER: define void @test2() #0 {{.*}}
+// HEADER: {{.*}}__llvm_gcov_ctr{{.*}}
+// HEADER: ret void
+// HEADER: define void @test() #0 {{.*}}
+// HEADER-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// HEADER: ret void
+
+// NONE: define void @test1() #0 {{.*}}
+// NONE-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NONE: ret void
+// NONE: define void @test2() #0 {{.*}}
+// NONE-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NONE: ret void
+// NONE: define void @test() #0 {{.*}}
+// NONE-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NONE: ret void
Index: test/CodeGen/Inputs/code-coverage-filter2.h
===
--- /dev/null
+++ test/CodeGen/Inputs/code-coverage-filter2.h
@@ -0,0 +1,2 @@
+void test2() {
+}
Index: test/CodeGen/Inputs/code-coverage-filter1.h
===
--- /dev/null
+++ test/CodeGen/Inputs/code-coverage-filter1.h
@@ -0,0 +1,2 @@
+void test1() {
+}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -801,6 +801,8 @@
 Opts.CoverageExtraChecksum = Args.hasArg(OPT_coverage_cfg_checksum);
 Opts.CoverageNoFunctionNamesInData =
 Args.hasArg(OPT_coverage_no_function_names_in_data);
+Opts.CoverageFilter = Args.getLastArgValue(OPT_coverage_filter);
+Opts.CoverageExclude = Args.getLastArgValue(OPT_coverage_exclude);
 

[PATCH] D52034: [Clang] Add options -Xclang -coverage-filter and -Xclang -coverage-exclude to filter the files to instrument with gcov

2018-09-20 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added inline comments.



Comment at: include/clang/Driver/CC1Options.td:236
+def coverage_exclude_EQ : Joined<["-"], "coverage-exclude=">,
+  Alias;
 def coverage_exit_block_before_body : Flag<["-"], 
"coverage-exit-block-before-body">,

marco-c wrote:
> calixte wrote:
> > vsk wrote:
> > > Have you checked whether gcc supports similar options? If so, it would be 
> > > great if we could match their name & behavior.
> > The only one I found -finstrument-functions-exclude-file-list 
> > (https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html).
> > But no regex and no way to include one file only.
> > I took the names from gcovr: 
> > https://manpages.debian.org/jessie/gcovr/gcovr.1.en.html
> We could file a bug in GCC's Bugzilla and agree with them about the options.
+ 1, I think it's a great idea to loop in some gcc developers.


Repository:
  rC Clang

https://reviews.llvm.org/D52034



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52034: [Clang] Add options -Xclang -coverage-filter and -Xclang -coverage-exclude to filter the files to instrument with gcov

2018-09-20 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added inline comments.



Comment at: test/CodeGen/code-coverage-filter.c:4
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -coverage-exclude=.*\\.h %s 
-o - \
+// RUN:| FileCheck -check-prefix=NOH %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -coverage-filter=.*\\.c %s 
-o - \

Could you use more descriptive check prefixes here, like 'NO-HEADERS'? Also, if 
it's possible to use fewer '\' escape tokens by wrapping the regex list in 
single-quotes, that would make things easier to read.



Comment at: test/CodeGen/code-coverage-filter.c:32
+
+// ALL: define i32 @test1(i32 %x) #0 {{.*}}
+// ALL: {{.*}}__llvm_gcov_ctr{{.*}}

1. This test will break on bots which use 16-bit ints. For simplicity, consider 
sticking to `void` and getting rid of unnecessary control flow.
2. Is there any need to check '#0'?


Repository:
  rC Clang

https://reviews.llvm.org/D52034



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52034: [Clang] Add options -Xclang -coverage-filter and -Xclang -coverage-exclude to filter the files to instrument with gcov

2018-09-20 Thread Marco Castelluccio via Phabricator via cfe-commits
marco-c added inline comments.



Comment at: include/clang/Driver/CC1Options.td:236
+def coverage_exclude_EQ : Joined<["-"], "coverage-exclude=">,
+  Alias;
 def coverage_exit_block_before_body : Flag<["-"], 
"coverage-exit-block-before-body">,

calixte wrote:
> vsk wrote:
> > Have you checked whether gcc supports similar options? If so, it would be 
> > great if we could match their name & behavior.
> The only one I found -finstrument-functions-exclude-file-list 
> (https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html).
> But no regex and no way to include one file only.
> I took the names from gcovr: 
> https://manpages.debian.org/jessie/gcovr/gcovr.1.en.html
We could file a bug in GCC's Bugzilla and agree with them about the options.


Repository:
  rC Clang

https://reviews.llvm.org/D52034



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52034: [Clang] Add options -Xclang -coverage-filter and -Xclang -coverage-exclude to filter the files to instrument with gcov

2018-09-13 Thread calixte via Phabricator via cfe-commits
calixte added inline comments.



Comment at: include/clang/Driver/CC1Options.td:236
+def coverage_exclude_EQ : Joined<["-"], "coverage-exclude=">,
+  Alias;
 def coverage_exit_block_before_body : Flag<["-"], 
"coverage-exit-block-before-body">,

vsk wrote:
> Have you checked whether gcc supports similar options? If so, it would be 
> great if we could match their name & behavior.
The only one I found -finstrument-functions-exclude-file-list 
(https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html).
But no regex and no way to include one file only.
I took the names from gcovr: 
https://manpages.debian.org/jessie/gcovr/gcovr.1.en.html


Repository:
  rC Clang

https://reviews.llvm.org/D52034



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52034: [Clang] Add options -Xclang -coverage-filter and -Xclang -coverage-exclude to filter the files to instrument with gcov

2018-09-13 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Please document the filter behavior (see docs/UsersManual.rst).




Comment at: include/clang/Driver/CC1Options.td:236
+def coverage_exclude_EQ : Joined<["-"], "coverage-exclude=">,
+  Alias;
 def coverage_exit_block_before_body : Flag<["-"], 
"coverage-exit-block-before-body">,

Have you checked whether gcc supports similar options? If so, it would be great 
if we could match their name & behavior.


Repository:
  rC Clang

https://reviews.llvm.org/D52034



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52034: [Clang] Add options -Xclang -coverage-filter and -Xclang -coverage-exclude to filter the files to instrument with gcov

2018-09-13 Thread calixte via Phabricator via cfe-commits
calixte created this revision.
calixte added reviewers: marco-c, vsk.
Herald added a subscriber: cfe-commits.

These options are taking regex separated by colons to filter files.

- if both are empty then all files are instrumented
- if -coverage-filter is empty then all the filenames matching any of the regex 
from exclude are not instrumented
- if -coverage-exclude is empty then all the filenames matching any of the 
regex from filter are instrumented
- if both aren't empty then all the filenames which match any of the regex in 
filter and which don't match all the regex in filter are instrumented
- this patch is a follow-up of https://reviews.llvm.org/D52033


Repository:
  rC Clang

https://reviews.llvm.org/D52034

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/code-coverage-filter1.h
  test/CodeGen/Inputs/code-coverage-filter2.h
  test/CodeGen/code-coverage-filter.c

Index: test/CodeGen/code-coverage-filter.c
===
--- /dev/null
+++ test/CodeGen/code-coverage-filter.c
@@ -0,0 +1,90 @@
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data %s -o - \
+// RUN:| FileCheck -check-prefix=ALL %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -coverage-exclude=.*\\.h %s -o - \
+// RUN:| FileCheck -check-prefix=NOH %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -coverage-filter=.*\\.c %s -o - \
+// RUN:| FileCheck -check-prefix=NOH %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -coverage-filter=.*\\.c %s -o - \
+// RUN:| FileCheck -check-prefix=NOH %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -coverage-filter=.*\\.c:.*1\\.h %s -o - \
+// RUN:| FileCheck -check-prefix=NOH2 %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -coverage-exclude=.*2\\.h:.*1\\.h %s -o - \
+// RUN:| FileCheck -check-prefix=C %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -coverage-exclude=.*code\\-coverage\\-filter\\.c %s -o - \
+// RUN:| FileCheck -check-prefix=H %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -coverage-filter=.*\\.c -coverage-exclude=.*\\.c %s -o - \
+// RUN:| FileCheck -check-prefix=NONE %s
+// RUN: %clang_cc1 -emit-llvm -femit-coverage-data -coverage-filter=.*\\.c -coverage-exclude=.*\\.h %s -o - \
+// RUN:| FileCheck -check-prefix=C %s
+
+#include "Inputs/code-coverage-filter1.h"
+#include "Inputs/code-coverage-filter2.h"
+
+int test(int a) {
+int x = 0;
+if (a == 1) {
+x = test1(a) + test2(a);
+}
+
+return x;
+}
+
+// ALL: define i32 @test1(i32 %x) #0 {{.*}}
+// ALL: {{.*}}__llvm_gcov_ctr{{.*}}
+// ALL: ret i32 {{.*}}
+// ALL: define i32 @test2(i32 %x) #0 {{.*}}
+// ALL: {{.*}}__llvm_gcov_ctr{{.*}}
+// ALL: ret i32 {{.*}}
+// ALL: define i32 @test(i32 %a) #0 {{.*}}
+// ALL: {{.*}}__llvm_gcov_ctr{{.*}}
+// ALL: ret i32 {{.*}}
+
+// NOH: define i32 @test1(i32 %x) #0 {{.*}}
+// NOH-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NOH: ret i32 {{.*}}
+// NOH: define i32 @test2(i32 %x) #0 {{.*}}
+// NOH-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NOH: ret i32 {{.*}}
+// NOH: define i32 @test(i32 %a) #0 {{.*}}
+// NOH: {{.*}}__llvm_gcov_ctr{{.*}}
+// NOH: ret i32 {{.*}}
+
+// NOH2: define i32 @test1(i32 %x) #0 {{.*}}
+// NOH2: {{.*}}__llvm_gcov_ctr{{.*}}
+// NOH2: ret i32 {{.*}}
+// NOH2: define i32 @test2(i32 %x) #0 {{.*}}
+// NOH2-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NOH2: ret i32 {{.*}}
+// NOH2: define i32 @test(i32 %a) #0 {{.*}}
+// NOH2: {{.*}}__llvm_gcov_ctr{{.*}}
+// NOH2: ret i32 {{.*}}
+
+// C: define i32 @test1(i32 %x) #0 {{.*}}
+// C-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// C: ret i32 {{.*}}
+// C: define i32 @test2(i32 %x) #0 {{.*}}
+// C-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// C: ret i32 {{.*}}
+// C: define i32 @test(i32 %a) #0 {{.*}}
+// C: {{.*}}__llvm_gcov_ctr{{.*}}
+// C: ret i32 {{.*}}
+
+// H: define i32 @test1(i32 %x) #0 {{.*}}
+// H: {{.*}}__llvm_gcov_ctr{{.*}}
+// H: ret i32 {{.*}}
+// H: define i32 @test2(i32 %x) #0 {{.*}}
+// H: {{.*}}__llvm_gcov_ctr{{.*}}
+// H: ret i32 {{.*}}
+// H: define i32 @test(i32 %a) #0 {{.*}}
+// H-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// H: ret i32 {{.*}}
+
+// NONE: define i32 @test1(i32 %x) #0 {{.*}}
+// NONE-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NONE: ret i32 {{.*}}
+// NONE: define i32 @test2(i32 %x) #0 {{.*}}
+// NONE-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NONE: ret i32 {{.*}}
+// NONE: define i32 @test(i32 %a) #0 {{.*}}
+// NONE-NOT: {{.*}}__llvm_gcov_ctr{{.*}}
+// NONE: ret i32 {{.*}}
Index: test/CodeGen/Inputs/code-coverage-filter2.h
===
--- /dev/null
+++ test/CodeGen/Inputs/code-coverage-filter2.h
@@ -0,0 +1,6 @@
+int test2(int x) {
+if (x >= 1) {
+return x + 1;
+}
+return x;
+}
Index: test/CodeGen/Inputs/code-coverage-filter1.h
===
--- /dev/null
+++