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}}

compiler-rt/include/profile/InstrProfData.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
650650
/* Indexed profile format version (start from 1). */
651651
#define INSTR_PROF_INDEX_VERSION 7
652652
/* Coverage mapping format version (start from 0). */
653-
#define INSTR_PROF_COVMAP_VERSION 5
653+
#define INSTR_PROF_COVMAP_VERSION 4
654654

655655
/* Profile version is always of type uint64_t. Reserve the upper 8 bits in the
656656
* version for other variants of profile. We set the lowest bit of the upper 8

llvm/docs/CoverageMappingFormat.rst

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,7 @@ too deeply).
266266
[32 x i8] c"..." ; Encoded data (dissected later)
267267
}, section "__llvm_covmap", align 8
268268
269-
The current version of the format is version 6.
270-
271-
There is one difference between versions 6 and 5:
272-
273-
* The first entry in the filename list is the compilation directory. When the
274-
filename is relative, the compilation directory is combined with the relative
275-
path to get an absolute path. This can reduce size by omitting the duplicate
276-
prefix in filenames.
277-
278-
There is one difference between versions 5 and 4:
269+
The current version of the format is version 5. There is one difference from version 4:
279270

280271
* The notion of branch region has been introduced along with a corresponding
281272
region kind. Branch regions encode two counters, one to track how many

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,7 @@ enum CovMapVersion {
10031003
Version4 = 3,
10041004
// Branch regions referring to two counters are added
10051005
Version5 = 4,
1006-
// Compilation directory is stored separately and combined with relative
1007-
// filenames to produce an absolute file path.
1008-
Version6 = 5,
1009-
// The current version is Version6.
1006+
// The current version is Version5.
10101007
CurrentVersion = INSTR_PROF_COVMAP_VERSION
10111008
};
10121009

llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ class RawCoverageMappingDummyChecker : public RawCoverageReader {
130130

131131
/// Reader for the raw coverage mapping data.
132132
class RawCoverageMappingReader : public RawCoverageReader {
133-
ArrayRef<std::string> &TranslationUnitFilenames;
133+
ArrayRef<StringRef> TranslationUnitFilenames;
134134
std::vector<StringRef> &Filenames;
135135
std::vector<CounterExpression> &Expressions;
136136
std::vector<CounterMappingRegion> &MappingRegions;
137137

138138
public:
139139
RawCoverageMappingReader(StringRef MappingData,
140-
ArrayRef<std::string> &TranslationUnitFilenames,
140+
ArrayRef<StringRef> TranslationUnitFilenames,
141141
std::vector<StringRef> &Filenames,
142142
std::vector<CounterExpression> &Expressions,
143143
std::vector<CounterMappingRegion> &MappingRegions)
@@ -179,10 +179,12 @@ class BinaryCoverageReader : public CoverageMappingReader {
179179
FilenamesBegin(FilenamesBegin), FilenamesSize(FilenamesSize) {}
180180
};
181181

182+
using DecompressedData = std::vector<std::unique_ptr<SmallVector<char, 0>>>;
183+
182184
using FuncRecordsStorage = std::unique_ptr<MemoryBuffer>;
183185

184186
private:
185-
std::vector<std::string> Filenames;
187+
std::vector<StringRef> Filenames;
186188
std::vector<ProfileMappingRecord> MappingRecords;
187189
InstrProfSymtab ProfileNames;
188190
size_t CurrentRecord = 0;
@@ -195,6 +197,10 @@ class BinaryCoverageReader : public CoverageMappingReader {
195197
// D69471, which can split up function records into multiple sections on ELF.
196198
FuncRecordsStorage FuncRecords;
197199

200+
// Used to tie the lifetimes of decompressed strings to the lifetime of this
201+
// BinaryCoverageReader instance.
202+
DecompressedData Decompressed;
203+
198204
BinaryCoverageReader(FuncRecordsStorage &&FuncRecords)
199205
: FuncRecords(std::move(FuncRecords)) {}
200206

@@ -220,23 +226,20 @@ class BinaryCoverageReader : public CoverageMappingReader {
220226

221227
/// Reader for the raw coverage filenames.
222228
class RawCoverageFilenamesReader : public RawCoverageReader {
223-
std::vector<std::string> &Filenames;
224-
StringRef CompilationDir;
229+
std::vector<StringRef> &Filenames;
225230

226231
// Read an uncompressed sequence of filenames.
227-
Error readUncompressed(CovMapVersion Version, uint64_t NumFilenames);
232+
Error readUncompressed(uint64_t NumFilenames);
228233

229234
public:
230-
RawCoverageFilenamesReader(StringRef Data,
231-
std::vector<std::string> &Filenames,
232-
StringRef CompilationDir = "")
233-
: RawCoverageReader(Data), Filenames(Filenames),
234-
CompilationDir(CompilationDir) {}
235+
RawCoverageFilenamesReader(StringRef Data, std::vector<StringRef> &Filenames)
236+
: RawCoverageReader(Data), Filenames(Filenames) {}
235237
RawCoverageFilenamesReader(const RawCoverageFilenamesReader &) = delete;
236238
RawCoverageFilenamesReader &
237239
operator=(const RawCoverageFilenamesReader &) = delete;
238240

239-
Error read(CovMapVersion Version);
241+
Error read(CovMapVersion Version,
242+
BinaryCoverageReader::DecompressedData &Decompressed);
240243
};
241244

242245
} // end namespace coverage

llvm/include/llvm/ProfileData/Coverage/CoverageMappingWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ namespace coverage {
2727
/// Writer of the filenames section for the instrumentation
2828
/// based code coverage.
2929
class CoverageFilenamesSectionWriter {
30-
ArrayRef<std::string> Filenames;
30+
ArrayRef<StringRef> Filenames;
3131

3232
public:
33-
CoverageFilenamesSectionWriter(ArrayRef<std::string> Filenames);
33+
CoverageFilenamesSectionWriter(ArrayRef<StringRef> Filenames);
3434

3535
/// Write encoded filenames to the given output stream. If \p Compress is
3636
/// true, attempt to compress the filenames.

llvm/include/llvm/ProfileData/InstrProfData.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
650650
/* Indexed profile format version (start from 1). */
651651
#define INSTR_PROF_INDEX_VERSION 7
652652
/* Coverage mapping format version (start from 0). */
653-
#define INSTR_PROF_COVMAP_VERSION 5
653+
#define INSTR_PROF_COVMAP_VERSION 4
654654

655655
/* Profile version is always of type uint64_t. Reserve the upper 8 bits in the
656656
* version for other variants of profile. We set the lowest bit of the upper 8

0 commit comments

Comments
 (0)