Skip to content

Commit

Permalink
[gcov] Make .gcno/.gcda paths absolute
Browse files Browse the repository at this point in the history
This restores 737a452 (2013) which was removed
by my a07b135.
This behavior turns out to be depended on by `bazel coverage`.

Add a `PWD=/proc/self/cwd %clang -### -c --coverage %s -o foo/bar.o` test.
  • Loading branch information
MaskRay committed May 18, 2023
1 parent e06dac0 commit f0303bd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,8 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
} else {
CoverageFilename = llvm::sys::path::filename(Output.getBaseInput());
}
if (llvm::sys::path::is_relative(CoverageFilename))
(void)D.getVFS().makeAbsolute(CoverageFilename);
llvm::sys::path::replace_extension(CoverageFilename, "gcno");
if (EmitCovNotes) {
CmdArgs.push_back("-coverage-notes-file");
Expand Down
25 changes: 15 additions & 10 deletions clang/test/Driver/coverage.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
// RUN: %clang -### -S -ftest-coverage %s 2>&1 | FileCheck --check-prefix=TEST-COVERAGE %s
// RUN: %clang -### -S -ftest-coverage -fno-test-coverage %s 2>&1 | FileCheck --check-prefix=NO-TEST-COVERAGE %s

// 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: "-coverage-data-file" "coverage.gcda"
// PROFILE-ARCS: "-coverage-data-file" "{{.*}}{{/|\\\\}}coverage.gcda"

// 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 -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"

/// GCC allows PWD to change the paths.
// RUN: %if system-linux %{ PWD=/proc/self/cwd %clang -### -c --coverage %s -o foo/bar.o 2>&1 | FileCheck --check-prefix=PWD %s %}
// PWD: "-coverage-notes-file" "/proc/self/cwd/foo/bar.gcno" "-coverage-data-file" "/proc/self/cwd/foo/bar.gcda"

/// Don't warn -Wunused-command-line-argument.
// RUN: %clang -E -Werror --coverage -ftest-coverage -fprofile-arcs %s
Expand All @@ -38,13 +42,14 @@
// 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"
// 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"
// 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"
/// GCC allows PWD to change the paths.
// RUN: %if system-linux %{ PWD=/proc/self/cwd %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" "/proc/self/cwd/e/x-a.gcno" "-coverage-data-file" "f/proc/self/cwd/e/x-a.gcda"
// LINK3: -cc1{{.*}} "-coverage-notes-file" "/proc/self/cwd/e/x-b.gcno" "-coverage-data-file" "f/proc/self/cwd/e/x-b.gcda"
2 changes: 1 addition & 1 deletion clang/test/Driver/working-directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

// CHECK_NO_FILE: no such file or directory: 'no_such_file.cpp'

// CHECK_WORKS: "-coverage-notes-file" "pchfile.gcno"
// CHECK_WORKS: "-coverage-notes-file" "{{[^"]+}}test{{/|\\\\}}Driver{{/|\\\\}}Inputs{{/|\\\\}}pchfile.gcno"
// CHECK_WORKS: "-working-directory" "{{[^"]+}}test{{/|\\\\}}Driver{{/|\\\\}}Inputs"
// CHECK_WORKS: "-fdebug-compilation-dir={{[^"]+}}test{{/|\\\\}}Driver{{/|\\\\}}Inputs"

0 comments on commit f0303bd

Please sign in to comment.