aboutsummaryrefslogtreecommitdiff
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
commit0ff70a666fc6f529c8df40e40ca8cf20eceaaf3e (patch)
tree9bb92d07b246414d125f44c563f04bf5e3f1c093
parent3d7c6e8ab759ae0fc82f60f35895342a71dde82f (diff)
[llvm-profdata] Fix a dangling reference to an error string
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318502 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext4
-rw-r--r--test/tools/llvm-profdata/Inputs/counter-mismatch-2.proftext5
-rw-r--r--test/tools/llvm-profdata/Inputs/counter-mismatch-3.proftext6
-rw-r--r--test/tools/llvm-profdata/Inputs/counter-mismatch-4.proftext7
-rw-r--r--test/tools/llvm-profdata/threaded-count-mismatch.test10
-rw-r--r--tools/llvm-profdata/llvm-profdata.cpp14
6 files changed, 43 insertions, 3 deletions
diff --git a/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext b/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext
new file mode 100644
index 00000000000..d54d0ad6ffe
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext
@@ -0,0 +1,4 @@
+foo
+1024
+1
+0
diff --git a/test/tools/llvm-profdata/Inputs/counter-mismatch-2.proftext b/test/tools/llvm-profdata/Inputs/counter-mismatch-2.proftext
new file mode 100644
index 00000000000..261bfdde595
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/counter-mismatch-2.proftext
@@ -0,0 +1,5 @@
+foo
+1024
+2
+0
+0
diff --git a/test/tools/llvm-profdata/Inputs/counter-mismatch-3.proftext b/test/tools/llvm-profdata/Inputs/counter-mismatch-3.proftext
new file mode 100644
index 00000000000..ca70a71a923
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/counter-mismatch-3.proftext
@@ -0,0 +1,6 @@
+foo
+1024
+3
+0
+0
+0
diff --git a/test/tools/llvm-profdata/Inputs/counter-mismatch-4.proftext b/test/tools/llvm-profdata/Inputs/counter-mismatch-4.proftext
new file mode 100644
index 00000000000..f403382e913
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/counter-mismatch-4.proftext
@@ -0,0 +1,7 @@
+foo
+1024
+4
+0
+0
+0
+0
diff --git a/test/tools/llvm-profdata/threaded-count-mismatch.test b/test/tools/llvm-profdata/threaded-count-mismatch.test
new file mode 100644
index 00000000000..58c13d626b0
--- /dev/null
+++ b/test/tools/llvm-profdata/threaded-count-mismatch.test
@@ -0,0 +1,10 @@
+# Test multithreaded error reporting.
+
+RUN: not llvm-profdata merge -j 4 -o %t.profdata \
+RUN: %S/Inputs/counter-mismatch-1.proftext \
+RUN: %S/Inputs/counter-mismatch-2.proftext \
+RUN: %S/Inputs/counter-mismatch-3.proftext \
+RUN: %S/Inputs/counter-mismatch-4.proftext \
+RUN: 2>&1 | FileCheck %s
+
+CHECK: Function basic block count change detected (counter mismatch)
diff --git a/tools/llvm-profdata/llvm-profdata.cpp b/tools/llvm-profdata/llvm-profdata.cpp
index 000bca2bd07..f5aa7062e62 100644
--- a/tools/llvm-profdata/llvm-profdata.cpp
+++ b/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) {