summaryrefslogtreecommitdiff
path: root/clang/test/Driver/coverage.c
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2023-05-17 12:43:49 -0700
committerFangrui Song <i@maskray.me>2023-05-17 12:43:49 -0700
commita07b135ce0c0111bd83450b5dc29ef0381cdbc39 (patch)
tree4c632a0822a1b54c9a1d4e086d68de49403a539d /clang/test/Driver/coverage.c
parent286cefcf35d0f55c57184c4219b95e82c96f1420 (diff)
downloadllvm-a07b135ce0c0111bd83450b5dc29ef0381cdbc39.tar.gz
[Driver][gcov] Derive .gcno .gcda file names from -o and -dumpdir
Resolve a FIXME. When -ftest-profile, -fprofile-arcs, or --coverage is specified and the driver performs both compilation and linking phases, derive the .gcno & .gcda file names from -o and -dumpdir. `clang --coverage d/a.c d/b.c -o e/x && e/x` will now emit `e/x-[ab].gc{no,da}` like GCC. For -fprofile-dir=, we make the deliberate decision to not mangle the input filename if relative. The following script demonstrates the .gcno and .gcda filenames. ``` PATH=/tmp/Rel/bin:$PATH # adapt according to your build directory mkdir -p d e f echo 'int main() {}' > d/a.c echo > d/b.c a() { rm $@ || exit 1; } clang --coverage d/a.c d/b.c && ./a.out a a-[ab].gc{no,da} clang --coverage d/a.c d/b.c -o e/x && e/x a e/x-[ab].gc{no,da} clang --coverage d/a.c d/b.c -o e/x -dumpdir f/ && e/x a f/[ab].gc{no,da} clang --coverage -fprofile-dir=f d/a.c d/b.c -o e/x && e/x a e/x-[ab].gcno f/e/x-[ab].gcda clang -c --coverage d/a.c d/b.c && clang --coverage a.o b.o && ./a.out a [ab].gc{no,da} clang -c --coverage -fprofile-dir=f d/a.c d/b.c && clang --coverage a.o b.o && ./a.out a [ab].gcno f/[ab].gcda clang -c --coverage d/a.c -o e/xa.o && clang --coverage e/xa.o && ./a.out a e/xa.gc{no,da} clang -c --coverage d/a.c -o e/xa.o -dumpdir f/g && clang --coverage e/xa.o && ./a.out a f/ga.gc{no,da} ``` The gcov code accidentally claims -c and -S, so -fsyntax-only -c/-S and -E -c/-S don't lead to a -Wunused-command-line-argument warning. Keep the unintended code for now.
Diffstat (limited to 'clang/test/Driver/coverage.c')
-rw-r--r--clang/test/Driver/coverage.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/clang/test/Driver/coverage.c b/clang/test/Driver/coverage.c
index b1a0456e7152..bb0bf45b34a6 100644
--- a/clang/test/Driver/coverage.c
+++ b/clang/test/Driver/coverage.c
@@ -2,22 +2,22 @@
// RUN: %clang -### -S -ftest-coverage -fno-test-coverage %s 2>&1 | FileCheck --check-prefix=NO-TEST-COVERAGE %s
// TEST-COVERAGE: "-ftest-coverage"
-// TEST-COVERAGE: "-coverage-notes-file" "{{.*}}{{/|\\\\}}coverage.gcno"
+// TEST-COVERAGE: "-coverage-notes-file" "coverage.gcno"
// NO-TEST-COVERAGE-NOT: "-coverage-notes-file"
// RUN: %clang -### -S -fprofile-arcs %s 2>&1 | FileCheck --check-prefix=PROFILE-ARCS %s
// RUN: %clang -### -S -fprofile-arcs -fno-profile-arcs %s 2>&1 | FileCheck --check-prefix=NO-PROFILE-ARCS %s
+// NO-PROFILE-ARCS-NOT: "-coverage-notes-file"
// PROFILE-ARCS: "-fprofile-arcs"
-// PROFILE-ARCS: "-coverage-notes-file" "{{.*}}{{/|\\\\}}coverage.c"
-// NO-PROFILE-ARCS-NOT: "-ftest-coverage"
+// PROFILE-ARCS: "-coverage-data-file" "coverage.gcda"
-// RUN: %clang -### -S -fprofile-arcs %s -o /foo/bar.o 2>&1 | FileCheck --check-prefix=GCNO-LOCATION %s
+// RUN: %clang -### -S -ftest-coverage %s -o /foo/bar.o 2>&1 | FileCheck --check-prefix=GCNO-LOCATION %s
// RUN: %clang_cl -### /c --coverage /Fo/foo/bar.obj -- %s 2>&1 | FileCheck --check-prefix=GCNO-LOCATION %s
-// RUN: %clang -### -c -fprofile-arcs %s -o foo/bar.o 2>&1 | FileCheck --check-prefix=GCNO-LOCATION-REL %s
+// RUN: %clang -### -c -ftest-coverage %s -o foo/bar.o 2>&1 | FileCheck --check-prefix=GCNO-LOCATION-REL %s
// GCNO-LOCATION: "-coverage-notes-file" "{{.*}}/foo/bar.gcno"
-// GCNO-LOCATION-REL: "-coverage-notes-file" "{{.*}}{{/|\\\\}}foo/bar.gcno"
+// GCNO-LOCATION-REL: "-coverage-notes-file" "foo/bar.gcno"
/// Don't warn -Wunused-command-line-argument.
// RUN: %clang -E -Werror --coverage -ftest-coverage -fprofile-arcs %s
@@ -35,3 +35,18 @@
// RUN: %clang -### -c %s 2>&1 | FileCheck --check-prefix=NO-COV %s
// NO-COV-NOT: "-coverage-notes-file"
// NO-COV-NOT: "-coverage-data-file"
+
+// RUN: rm -rf %t && mkdir %t && cd %t
+// RUN: mkdir d e f && cp %s d/a.c && touch d/b.c
+
+// RUN: %clang -### --coverage d/a.c d/b.c -o e/x 2>&1 | FileCheck %s --check-prefix=LINK1
+// LINK1: -cc1{{.*}} "-coverage-notes-file" "e/x-a.gcno" "-coverage-data-file" "e/x-a.gcda"
+// LINK1: -cc1{{.*}} "-coverage-notes-file" "e/x-b.gcno" "-coverage-data-file" "e/x-b.gcda"
+
+// RUN: %clang -### --coverage d/a.c d/b.c -o e/x -dumpdir f/g 2>&1 | FileCheck %s --check-prefix=LINK2
+// LINK2: -cc1{{.*}} "-coverage-notes-file" "f/ga.gcno" "-coverage-data-file" "f/ga.gcda"
+// LINK2: -cc1{{.*}} "-coverage-notes-file" "f/gb.gcno" "-coverage-data-file" "f/gb.gcda"
+
+// RUN: %clang -### --coverage d/a.c d/b.c -o e/x -fprofile-dir=f 2>&1 | FileCheck %s --check-prefix=LINK3
+// LINK3: -cc1{{.*}} "-coverage-notes-file" "e/x-a.gcno" "-coverage-data-file" "f{{/|\\\\}}e/x-a.gcda"
+// LINK3: -cc1{{.*}} "-coverage-notes-file" "e/x-b.gcno" "-coverage-data-file" "f{{/|\\\\}}e/x-b.gcda"