[llvm-cov] Get rid of all invalid filename references
We used to append filenames into a vector of std::string, and then
append a reference to each string into a separate vector. This made it
easier to work with the getUniqueSourceFiles API. But it's buggy.
std::string has a small-string optimization, so you can't expect to
capture a reference to one if you're copying it into a growing vector.
Add a test that triggers this invalid reference to std::string scenario,
and kill the issue with fire by just using ArrayRef<std::string>
everywhere.
llvm-svn: 282281
diff --git a/llvm/tools/llvm-cov/CoverageExporterJson.cpp b/llvm/tools/llvm-cov/CoverageExporterJson.cpp
index e8dee14..06dc176 100644
--- a/llvm/tools/llvm-cov/CoverageExporterJson.cpp
+++ b/llvm/tools/llvm-cov/CoverageExporterJson.cpp
@@ -175,7 +175,9 @@
emitDictKey("files");
FileCoverageSummary Totals = FileCoverageSummary("Totals");
- std::vector<StringRef> SourceFiles = Coverage.getUniqueSourceFiles();
+ std::vector<std::string> SourceFiles;
+ for (StringRef SF : Coverage.getUniqueSourceFiles())
+ SourceFiles.emplace_back(SF);
auto FileReports =
CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles);
renderFiles(SourceFiles, FileReports);
@@ -235,7 +237,7 @@
}
/// \brief Render an array of all the source files, also pass back a Summary.
- void renderFiles(ArrayRef<StringRef> SourceFiles,
+ void renderFiles(ArrayRef<std::string> SourceFiles,
ArrayRef<FileCoverageSummary> FileReports) {
// Start List of Files.
emitArrayStart();