Skip to content

Commit 703a0ea

Browse files
committed
Revert "[Coverage] Store compilation dir separately in coverage mapping"
This reverts commit 5fbd1a3. See: rdar://82543962 (Revert coverage changes from clang-1316 to make coverage format in clang-1316 identical to clang-1300) Testing: * check-profile passed before and after this revert. * check-clang reported 4 failing tests prior to this revert; that remains unchanged. Driver/clang_f_opts.c required a workaround. The coverage-compilation-dir.c test was xfailed. * check-llvm passed before and after this revert. The llvm-cov/compilation_dir.c test is now xfailed. Coverage unit tests pass with the exception of non_code_region_counters, which was disabled because https://reviews.llvm.org/D101780 was folded into this revert. Conflicts: clang/include/clang/Basic/CodeGenOptions.h clang/include/clang/Driver/Options.td clang/lib/CodeGen/CoverageMappingGen.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/Profile/profile-prefix-map.c llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp llvm/unittests/ProfileData/CoverageMappingTest.cpp
1 parent 335c3bc commit 703a0ea

File tree

22 files changed

+140
-199
lines changed

22 files changed

+140
-199
lines changed

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@ class CodeGenOptions : public CodeGenOptionsBase {
158158
/// The string to embed in debug information as the current working directory.
159159
std::string DebugCompilationDir;
160160

161-
/// The string to embed in coverage mapping as the current working directory.
162-
std::string CoverageCompilationDir;
163-
164161
/// The string to embed in the debug information for the compile unit, if
165162
/// non-empty.
166163
std::string DwarfDebugFlags;

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,10 +1176,6 @@ def fdebug_compilation_dir_EQ : Joined<["-"], "fdebug-compilation-dir=">,
11761176
def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">,
11771177
Group<f_Group>, Flags<[CC1Option, CC1AsOption, CoreOption]>,
11781178
Alias<fdebug_compilation_dir_EQ>;
1179-
def fcoverage_compilation_dir_EQ : Joined<["-"], "fcoverage-compilation-dir=">,
1180-
Group<f_Group>, Flags<[CC1Option, CC1AsOption, CoreOption]>,
1181-
HelpText<"The compilation directory to embed in the coverage mapping.">,
1182-
MarshallingInfoString<CodeGenOpts<"CoverageCompilationDir">>;
11831179
def ffile_compilation_dir_EQ : Joined<["-"], "ffile-compilation-dir=">, Group<f_Group>,
11841180
Flags<[CoreOption]>,
11851181
HelpText<"The compilation directory to embed in the debug info and coverage mapping.">;

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,17 +1563,9 @@ CoverageMappingModuleGen::CoverageMappingModuleGen(
15631563
CoveragePrefixMap = CGM.getCodeGenOpts().CoveragePrefixMap;
15641564
}
15651565

1566-
std::string CoverageMappingModuleGen::getCurrentDirname() {
1567-
if (!CGM.getCodeGenOpts().CoverageCompilationDir.empty())
1568-
return CGM.getCodeGenOpts().CoverageCompilationDir;
1569-
1570-
SmallString<256> CWD;
1571-
llvm::sys::fs::current_path(CWD);
1572-
return CWD.str().str();
1573-
}
1574-
15751566
std::string CoverageMappingModuleGen::normalizeFilename(StringRef Filename) {
15761567
llvm::SmallString<256> Path(Filename);
1568+
llvm::sys::fs::make_absolute(Path);
15771569
llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
15781570
for (const auto &Entry : CoveragePrefixMap) {
15791571
if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))
@@ -1654,17 +1646,18 @@ void CoverageMappingModuleGen::addFunctionMappingRecord(
16541646
// also processed by the CoverageMappingWriter which performs
16551647
// additional minimization operations such as reducing the number of
16561648
// expressions.
1657-
llvm::SmallVector<std::string, 16> FilenameStrs;
16581649
std::vector<StringRef> Filenames;
16591650
std::vector<CounterExpression> Expressions;
16601651
std::vector<CounterMappingRegion> Regions;
1661-
FilenameStrs.resize(FileEntries.size() + 1);
1662-
FilenameStrs[0] = normalizeFilename(getCurrentDirname());
1652+
llvm::SmallVector<std::string, 16> FilenameStrs;
1653+
llvm::SmallVector<StringRef, 16> FilenameRefs;
1654+
FilenameStrs.resize(FileEntries.size());
1655+
FilenameRefs.resize(FileEntries.size());
16631656
for (const auto &Entry : FileEntries) {
16641657
auto I = Entry.second;
16651658
FilenameStrs[I] = normalizeFilename(Entry.first->getName());
1659+
FilenameRefs[I] = FilenameStrs[I];
16661660
}
1667-
ArrayRef<std::string> FilenameRefs = llvm::makeArrayRef(FilenameStrs);
16681661
RawCoverageMappingReader Reader(CoverageMapping, FilenameRefs, Filenames,
16691662
Expressions, Regions);
16701663
if (Reader.read())
@@ -1681,18 +1674,19 @@ void CoverageMappingModuleGen::emit() {
16811674

16821675
// Create the filenames and merge them with coverage mappings
16831676
llvm::SmallVector<std::string, 16> FilenameStrs;
1684-
FilenameStrs.resize(FileEntries.size() + 1);
1685-
// The first filename is the current working directory.
1686-
FilenameStrs[0] = normalizeFilename(getCurrentDirname());
1677+
llvm::SmallVector<StringRef, 16> FilenameRefs;
1678+
FilenameStrs.resize(FileEntries.size());
1679+
FilenameRefs.resize(FileEntries.size());
16871680
for (const auto &Entry : FileEntries) {
16881681
auto I = Entry.second;
16891682
FilenameStrs[I] = normalizeFilename(Entry.first->getName());
1683+
FilenameRefs[I] = FilenameStrs[I];
16901684
}
16911685

16921686
std::string Filenames;
16931687
{
16941688
llvm::raw_string_ostream OS(Filenames);
1695-
CoverageFilenamesSectionWriter(FilenameStrs).write(OS);
1689+
CoverageFilenamesSectionWriter(FilenameRefs).write(OS);
16961690
}
16971691
auto *FilenamesVal =
16981692
llvm::ConstantDataArray::getString(Ctx, Filenames, false);
@@ -1750,7 +1744,7 @@ unsigned CoverageMappingModuleGen::getFileID(const FileEntry *File) {
17501744
auto It = FileEntries.find(File);
17511745
if (It != FileEntries.end())
17521746
return It->second;
1753-
unsigned FileID = FileEntries.size() + 1;
1747+
unsigned FileID = FileEntries.size();
17541748
FileEntries.insert(std::make_pair(File, FileID));
17551749
return FileID;
17561750
}

clang/lib/CodeGen/CoverageMappingGen.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ class CoverageMappingModuleGen {
9595
std::vector<FunctionInfo> FunctionRecords;
9696
std::map<std::string, std::string> CoveragePrefixMap;
9797

98-
std::string getCurrentDirname();
9998
std::string normalizeFilename(StringRef Filename);
10099

101100
/// Emit a function record.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -885,18 +885,6 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
885885
CmdArgs.push_back("-fcoverage-mapping");
886886
}
887887

888-
if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
889-
options::OPT_fcoverage_compilation_dir_EQ)) {
890-
if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
891-
CmdArgs.push_back(Args.MakeArgString(
892-
Twine("-fcoverage-compilation-dir=") + A->getValue()));
893-
else
894-
A->render(Args, CmdArgs);
895-
} else if (llvm::ErrorOr<std::string> CWD =
896-
D.getVFS().getCurrentWorkingDirectory()) {
897-
CmdArgs.push_back(Args.MakeArgString("-fcoverage-compilation-dir=" + *CWD));
898-
}
899-
900888
if (Args.hasArg(options::OPT_fprofile_exclude_files_EQ)) {
901889
auto *Arg = Args.getLastArg(options::OPT_fprofile_exclude_files_EQ);
902890
if (!Args.hasArg(options::OPT_coverage))

clang/test/CodeGen/coverage-compilation-dir.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// XFAIL: *
2+
// See rdar://82543962.
3+
//
14
// RUN: mkdir -p %t.dir && cd %t.dir
25
// RUN: cp %s rel.c
36
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-compilation-dir=/nonsense -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false rel.c -o - | FileCheck -check-prefix=CHECK-NONSENSE %s
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -mllvm -enable-name-compression=false -emit-llvm -main-file-name abspath.cpp %S/Inputs/../abspath.cpp -o - | FileCheck -check-prefix=RMDOTS %s
22

3-
// RMDOTS: @__llvm_coverage_mapping = {{.*}}"\02
3+
// RMDOTS: @__llvm_coverage_mapping = {{.*}}"\01
44
// RMDOTS-NOT: Inputs
55
// RMDOTS: "
66

77
// RUN: mkdir -p %t/test && cd %t/test
88
// RUN: echo "void f1() {}" > f1.c
9-
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -mllvm -enable-name-compression=false -emit-llvm -main-file-name abspath.cpp %t/test/f1.c -o - | FileCheck -check-prefix=ABSPATH %s
9+
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -mllvm -enable-name-compression=false -emit-llvm -main-file-name abspath.cpp ../test/f1.c -o - | FileCheck -check-prefix=RELPATH %s
1010

11-
// RELPATH: @__llvm_coverage_mapping = {{.*}}"\02
12-
// RELPATH: {{..(/|\\\\)test(/|\\\\)f1}}.c
11+
// RELPATH: @__llvm_coverage_mapping = {{.*}}"\01
12+
// RELPATH: {{[/\\].*(/|\\\\)test(/|\\\\)f1}}.c
1313
// RELPATH: "
1414

15-
// ABSPATH: @__llvm_coverage_mapping = {{.*}}"\02
16-
// ABSPATH: {{[/\\].*(/|\\\\)test(/|\\\\)f1}}.c
17-
// ABSPATH: "
18-
1915
void f1() {}

clang/test/Driver/clang_f_opts.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,11 @@
524524
// CHECK-DEBUG-COMPILATION-DIR: "-fdebug-compilation-dir=."
525525
// CHECK-DEBUG-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
526526

527-
// RUN: %clang -### -S -fprofile-instr-generate -fcoverage-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-COVERAGE-COMPILATION-DIR %s
528-
// RUN: %clang -### -S -fprofile-instr-generate -ffile-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-COVERAGE-COMPILATION-DIR %s
529-
// CHECK-COVERAGE-COMPILATION-DIR: "-fcoverage-compilation-dir=."
530-
// CHECK-COVERAGE-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
527+
// See rdar://82543962.
528+
// XXX: %clang -### -S -fprofile-instr-generate -fcoverage-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-COVERAGE-COMPILATION-DIR %s
529+
// XXX: %clang -### -S -fprofile-instr-generate -ffile-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-COVERAGE-COMPILATION-DIR %s
530+
// XXX-COVERAGE-COMPILATION-DIR: "-fcoverage-compilation-dir=."
531+
// XXX-COVERAGE-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
531532

532533
// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s
533534
// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s

clang/test/Profile/coverage-prefix-map.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// XFAIL: *
2+
// See rdar://82543962.
3+
//
14
// %s expands to an absolute path, so to test relative paths we need to create a
25
// clean directory, put the source there, and cd into it.
36
// RUN: rm -rf %t
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// XFAIL: *
2+
// See rdar://82543962.
3+
//
4+
// %s expands to an absolute path, so to test relative paths we need to create a
5+
// clean directory, put the source there, and cd into it.
6+
// RUN: rm -rf %t
7+
// RUN: mkdir -p %t/root/nested
8+
// RUN: echo "void f1() {}" > %t/root/nested/profile-prefix-map.c
9+
// RUN: cd %t/root
10+
11+
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c nested/profile-prefix-map.c -o - | FileCheck --check-prefix=ABSOLUTE %s
12+
//
13+
// ABSOLUTE: @__llvm_coverage_mapping = {{.*"\\01.*root.*nested.*profile-prefix-map\.c}}
14+
15+
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c nested/profile-prefix-map.c -fprofile-prefix-map=%/t/root=. -o - | FileCheck --check-prefix=PROFILE-PREFIX-MAP %s --implicit-check-not=root
16+
//
17+
// PROFILE-PREFIX-MAP: @__llvm_coverage_mapping = {{.*"\\01[^/]*}}.{{/|\\+}}nested{{.*profile-prefix-map\.c}}

0 commit comments

Comments
 (0)