summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cov/CodeCoverage.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-09-23 18:57:32 +0000
committerVedant Kumar <vsk@apple.com>2016-09-23 18:57:32 +0000
commitbc6479850e1d4a4522c6d195f93704d3e78e54e3 (patch)
treea62afdc088765fcce12312bec7d6ff6d785b044a /llvm/tools/llvm-cov/CodeCoverage.cpp
parent224ef8d73bb49c765ac8d7a352b244ec7c24807e (diff)
downloadbcm5719-llvm-bc6479850e1d4a4522c6d195f93704d3e78e54e3.tar.gz
bcm5719-llvm-bc6479850e1d4a4522c6d195f93704d3e78e54e3.zip
[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
Diffstat (limited to 'llvm/tools/llvm-cov/CodeCoverage.cpp')
-rw-r--r--llvm/tools/llvm-cov/CodeCoverage.cpp22
1 files changed, 9 insertions, 13 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index 237d877cde1..51ac6ef3d88 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -64,7 +64,8 @@ private:
/// \brief Print the warning message to the error output stream.
void warning(const Twine &Message, StringRef Whence = "");
- /// \brief Copy \p Path into the list of input source files.
+ /// \brief Convert \p Path into an absolute path and append it to the list
+ /// of collected paths.
void addCollectedPath(const std::string &Path);
/// \brief If \p Path is a regular file, collect the path. If it's a
@@ -116,7 +117,7 @@ private:
std::string PGOFilename;
/// A list of input source files.
- std::vector<StringRef> SourceFiles;
+ std::vector<std::string> SourceFiles;
/// Whether or not we're in -filename-equivalence mode.
bool CompareFilenamesOnly;
@@ -131,9 +132,6 @@ private:
/// A cache for demangled symbol names.
StringMap<std::string> DemangledNames;
- /// File paths (absolute, or otherwise) to input source files.
- std::vector<std::string> CollectedPaths;
-
/// Errors and warnings which have not been printed.
std::mutex ErrsLock;
@@ -168,7 +166,7 @@ void CodeCoverageTool::warning(const Twine &Message, StringRef Whence) {
void CodeCoverageTool::addCollectedPath(const std::string &Path) {
if (CompareFilenamesOnly) {
- CollectedPaths.push_back(Path);
+ SourceFiles.emplace_back(Path);
} else {
SmallString<128> EffectivePath(Path);
if (std::error_code EC = sys::fs::make_absolute(EffectivePath)) {
@@ -176,10 +174,8 @@ void CodeCoverageTool::addCollectedPath(const std::string &Path) {
return;
}
sys::path::remove_dots(EffectivePath, /*remove_dot_dots=*/true);
- CollectedPaths.push_back(EffectivePath.str());
+ SourceFiles.emplace_back(EffectivePath.str());
}
-
- SourceFiles.emplace_back(CollectedPaths.back());
}
void CodeCoverageTool::collectPaths(const std::string &Path) {
@@ -597,7 +593,7 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
collectPaths(File);
if (DebugDumpCollectedPaths) {
- for (StringRef SF : SourceFiles)
+ for (const std::string &SF : SourceFiles)
outs() << SF << '\n';
::exit(0);
}
@@ -751,11 +747,11 @@ int CodeCoverageTool::show(int argc, const char **argv,
ThreadCount = std::thread::hardware_concurrency();
ThreadPool Pool(ThreadCount);
- for (StringRef SourceFile : SourceFiles) {
- Pool.async([this, SourceFile, &Coverage, &Printer, ShowFilenames] {
+ for (const std::string &SourceFile : SourceFiles) {
+ Pool.async([this, &SourceFile, &Coverage, &Printer, ShowFilenames] {
auto View = createSourceFileView(SourceFile, *Coverage);
if (!View) {
- warning("The file '" + SourceFile.str() + "' isn't covered.");
+ warning("The file '" + SourceFile + "' isn't covered.");
return;
}
OpenPOWER on IntegriCloud