forked from OSchip/llvm-project
[llvm-cov] Fix a lifetime issue
This fixes an issue where a std::string was moved to a constructor which accepted a StringRef. llvm-svn: 312816
This commit is contained in:
parent
efcf41b528
commit
72c3a11488
|
@ -91,3 +91,7 @@ int main() { // ALL: [[@LINE]]| 1|int main() {
|
|||
// RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %S/Inputs/templateInstantiations.profdata -show-instantiations=false -path-equivalence=/tmp,%S %s | FileCheck -check-prefix=NO_INSTS %s
|
||||
// NO_INSTS-NOT: {{^ *}}| _Z4funcIbEiT_:
|
||||
// NO_INSTS-NOT: {{^ *}}| _Z4funcIiEiT_:
|
||||
|
||||
// RUN: llvm-cov report %S/Inputs/templateInstantiations.covmapping -dump -instr-profile %S/Inputs/templateInstantiations.profdata -path-equivalence=/tmp,%S %s | FileCheck -check-prefix=DUMP %s
|
||||
// DUMP: InstantiationGroup: Definition at line 7, column 30 with size = 2
|
||||
// DUMP: InstantiationGroup: main with size = 1
|
||||
|
|
|
@ -42,6 +42,7 @@ using namespace llvm;
|
|||
using namespace coverage;
|
||||
|
||||
void exportCoverageDataToJson(const coverage::CoverageMapping &CoverageMapping,
|
||||
const CoverageViewOptions &Options,
|
||||
raw_ostream &OS);
|
||||
|
||||
namespace {
|
||||
|
@ -932,7 +933,7 @@ int CodeCoverageTool::export_(int argc, const char **argv,
|
|||
return 1;
|
||||
}
|
||||
|
||||
exportCoverageDataToJson(*Coverage.get(), outs());
|
||||
exportCoverageDataToJson(*Coverage.get(), ViewOpts, outs());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,8 @@ using namespace llvm;
|
|||
using namespace coverage;
|
||||
|
||||
class CoverageExporterJson {
|
||||
const CoverageViewOptions &Options;
|
||||
|
||||
/// \brief Output stream to print JSON to.
|
||||
raw_ostream &OS;
|
||||
|
||||
|
@ -171,8 +173,8 @@ class CoverageExporterJson {
|
|||
std::vector<std::string> SourceFiles;
|
||||
for (StringRef SF : Coverage.getUniqueSourceFiles())
|
||||
SourceFiles.emplace_back(SF);
|
||||
auto FileReports =
|
||||
CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles);
|
||||
auto FileReports = CoverageReport::prepareFileReports(Coverage, Totals,
|
||||
SourceFiles, Options);
|
||||
renderFiles(SourceFiles, FileReports);
|
||||
|
||||
emitDictKey("functions");
|
||||
|
@ -403,8 +405,9 @@ class CoverageExporterJson {
|
|||
}
|
||||
|
||||
public:
|
||||
CoverageExporterJson(const CoverageMapping &CoverageMapping, raw_ostream &OS)
|
||||
: OS(OS), Coverage(CoverageMapping) {
|
||||
CoverageExporterJson(const CoverageMapping &CoverageMapping,
|
||||
const CoverageViewOptions &Options, raw_ostream &OS)
|
||||
: Options(Options), OS(OS), Coverage(CoverageMapping) {
|
||||
State.push(JsonState::None);
|
||||
}
|
||||
|
||||
|
@ -414,8 +417,9 @@ public:
|
|||
|
||||
/// \brief Export the given CoverageMapping to a JSON Format.
|
||||
void exportCoverageDataToJson(const CoverageMapping &CoverageMapping,
|
||||
const CoverageViewOptions &Options,
|
||||
raw_ostream &OS) {
|
||||
auto Exporter = CoverageExporterJson(CoverageMapping, OS);
|
||||
auto Exporter = CoverageExporterJson(CoverageMapping, Options, OS);
|
||||
|
||||
Exporter.print();
|
||||
}
|
||||
|
|
|
@ -307,10 +307,9 @@ void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<FileCoverageSummary>
|
||||
CoverageReport::prepareFileReports(const coverage::CoverageMapping &Coverage,
|
||||
FileCoverageSummary &Totals,
|
||||
ArrayRef<std::string> Files) {
|
||||
std::vector<FileCoverageSummary> CoverageReport::prepareFileReports(
|
||||
const coverage::CoverageMapping &Coverage, FileCoverageSummary &Totals,
|
||||
ArrayRef<std::string> Files, const CoverageViewOptions &Options) {
|
||||
std::vector<FileCoverageSummary> FileReports;
|
||||
unsigned LCP = getRedundantPrefixLen(Files);
|
||||
|
||||
|
@ -328,6 +327,11 @@ CoverageReport::prepareFileReports(const coverage::CoverageMapping &Coverage,
|
|||
|
||||
auto GroupSummary =
|
||||
FunctionCoverageSummary::get(Group, InstantiationSummaries);
|
||||
|
||||
if (Options.Debug)
|
||||
outs() << "InstantiationGroup: " << GroupSummary.Name << " with "
|
||||
<< "size = " << Group.size() << "\n";
|
||||
|
||||
Summary.addFunction(GroupSummary);
|
||||
Totals.addFunction(GroupSummary);
|
||||
}
|
||||
|
@ -348,7 +352,7 @@ void CoverageReport::renderFileReports(raw_ostream &OS) const {
|
|||
void CoverageReport::renderFileReports(raw_ostream &OS,
|
||||
ArrayRef<std::string> Files) const {
|
||||
FileCoverageSummary Totals("TOTAL");
|
||||
auto FileReports = prepareFileReports(Coverage, Totals, Files);
|
||||
auto FileReports = prepareFileReports(Coverage, Totals, Files, Options);
|
||||
|
||||
std::vector<StringRef> Filenames;
|
||||
for (const FileCoverageSummary &FCS : FileReports)
|
||||
|
|
|
@ -39,7 +39,8 @@ public:
|
|||
/// Prepare file reports for the files specified in \p Files.
|
||||
static std::vector<FileCoverageSummary>
|
||||
prepareFileReports(const coverage::CoverageMapping &Coverage,
|
||||
FileCoverageSummary &Totals, ArrayRef<std::string> Files);
|
||||
FileCoverageSummary &Totals, ArrayRef<std::string> Files,
|
||||
const CoverageViewOptions &Options);
|
||||
|
||||
/// Render file reports for every unique file in the coverage mapping.
|
||||
void renderFileReports(raw_ostream &OS) const;
|
||||
|
|
|
@ -82,7 +82,7 @@ FunctionCoverageSummary::get(const InstantiationGroup &Group,
|
|||
<< Group.getColumn();
|
||||
}
|
||||
|
||||
FunctionCoverageSummary Summary(std::move(Name));
|
||||
FunctionCoverageSummary Summary(Name);
|
||||
Summary.ExecutionCount = Group.getTotalExecutionCount();
|
||||
Summary.RegionCoverage = Summaries[0].RegionCoverage;
|
||||
Summary.LineCoverage = Summaries[0].LineCoverage;
|
||||
|
|
|
@ -120,14 +120,14 @@ struct FunctionCoverageSummary {
|
|||
RegionCoverageInfo RegionCoverage;
|
||||
LineCoverageInfo LineCoverage;
|
||||
|
||||
FunctionCoverageSummary(StringRef Name) : Name(Name), ExecutionCount(0) {}
|
||||
FunctionCoverageSummary(const std::string &Name)
|
||||
: Name(Name), ExecutionCount(0) {}
|
||||
|
||||
FunctionCoverageSummary(StringRef Name, uint64_t ExecutionCount,
|
||||
FunctionCoverageSummary(const std::string &Name, uint64_t ExecutionCount,
|
||||
const RegionCoverageInfo &RegionCoverage,
|
||||
const LineCoverageInfo &LineCoverage)
|
||||
: Name(Name), ExecutionCount(ExecutionCount),
|
||||
RegionCoverage(RegionCoverage), LineCoverage(LineCoverage) {
|
||||
}
|
||||
RegionCoverage(RegionCoverage), LineCoverage(LineCoverage) {}
|
||||
|
||||
/// \brief Compute the code coverage summary for the given function coverage
|
||||
/// mapping record.
|
||||
|
|
|
@ -398,7 +398,7 @@ Error CoveragePrinterHTML::createIndexFile(
|
|||
emitColumnLabelsForIndex(OSRef);
|
||||
FileCoverageSummary Totals("TOTALS");
|
||||
auto FileReports =
|
||||
CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles);
|
||||
CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles, Opts);
|
||||
bool EmptyFiles = false;
|
||||
for (unsigned I = 0, E = FileReports.size(); I < E; ++I) {
|
||||
if (FileReports[I].FunctionCoverage.NumFunctions)
|
||||
|
|
Loading…
Reference in New Issue