summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-profdata/llvm-profdata.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2017-11-17 02:58:23 +0000
committerVedant Kumar <vsk@apple.com>2017-11-17 02:58:23 +0000
commitfaaa42ad0a62594ffd28c60ca9fe91676670a15d (patch)
tree7a8cf492627dc1b9dfe4e0acdcbec51a9df730d7 /llvm/tools/llvm-profdata/llvm-profdata.cpp
parent69855491eee9252f32bf2c2d60374eb75fb9b4e3 (diff)
downloadbcm5719-llvm-faaa42ad0a62594ffd28c60ca9fe91676670a15d.tar.gz
bcm5719-llvm-faaa42ad0a62594ffd28c60ca9fe91676670a15d.zip
[llvm-profdata] Fix a dangling reference to an error string
llvm-svn: 318502
Diffstat (limited to 'llvm/tools/llvm-profdata/llvm-profdata.cpp')
-rw-r--r--llvm/tools/llvm-profdata/llvm-profdata.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index 000bca2bd07..f5aa7062e62 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -37,8 +37,8 @@ using namespace llvm;
enum ProfileFormat { PF_None = 0, PF_Text, PF_Binary, PF_GCC };
-static void exitWithError(const Twine &Message, StringRef Whence = "",
- StringRef Hint = "") {
+static void exitWithError(Twine Message, std::string Whence = "",
+ std::string Hint = "") {
errs() << "error: ";
if (!Whence.empty())
errs() << Whence << ": ";
@@ -119,7 +119,7 @@ struct WriterContext {
std::mutex Lock;
InstrProfWriter Writer;
Error Err;
- StringRef ErrWhence;
+ std::string ErrWhence;
std::mutex &ErrLock;
SmallSet<instrprof_error, 4> &WriterErrorCodes;
@@ -137,6 +137,9 @@ static void loadInput(const WeightedFile &Input, WriterContext *WC) {
if (WC->Err)
return;
+ // Copy the filename, because llvm::ThreadPool copied the input "const
+ // WeightedFile &" by value, making a reference to the filename within it
+ // invalid outside of this packaged task.
WC->ErrWhence = Input.Filename;
auto ReaderOrErr = InstrProfReader::create(Input.Filename);
@@ -180,6 +183,11 @@ static void loadInput(const WeightedFile &Input, WriterContext *WC) {
/// Merge the \p Src writer context into \p Dst.
static void mergeWriterContexts(WriterContext *Dst, WriterContext *Src) {
+ // If we've already seen a hard error, continuing with the merge would
+ // clobber it.
+ if (Dst->Err || Src->Err)
+ return;
+
bool Reported = false;
Dst->Writer.mergeRecordsFromWriter(std::move(Src->Writer), [&](Error E) {
if (Reported) {
OpenPOWER on IntegriCloud