Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0ff70a6

Browse files
committedNov 17, 2017
[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
1 parent 3d7c6e8 commit 0ff70a6

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed
 
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
foo
2+
1024
3+
1
4+
0
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
foo
2+
1024
3+
2
4+
0
5+
0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
foo
2+
1024
3+
3
4+
0
5+
0
6+
0
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
foo
2+
1024
3+
4
4+
0
5+
0
6+
0
7+
0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Test multithreaded error reporting.
2+
3+
RUN: not llvm-profdata merge -j 4 -o %t.profdata \
4+
RUN: %S/Inputs/counter-mismatch-1.proftext \
5+
RUN: %S/Inputs/counter-mismatch-2.proftext \
6+
RUN: %S/Inputs/counter-mismatch-3.proftext \
7+
RUN: %S/Inputs/counter-mismatch-4.proftext \
8+
RUN: 2>&1 | FileCheck %s
9+
10+
CHECK: Function basic block count change detected (counter mismatch)

‎tools/llvm-profdata/llvm-profdata.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ using namespace llvm;
3737

3838
enum ProfileFormat { PF_None = 0, PF_Text, PF_Binary, PF_GCC };
3939

40-
static void exitWithError(const Twine &Message, StringRef Whence = "",
41-
StringRef Hint = "") {
40+
static void exitWithError(Twine Message, std::string Whence = "",
41+
std::string Hint = "") {
4242
errs() << "error: ";
4343
if (!Whence.empty())
4444
errs() << Whence << ": ";
@@ -119,7 +119,7 @@ struct WriterContext {
119119
std::mutex Lock;
120120
InstrProfWriter Writer;
121121
Error Err;
122-
StringRef ErrWhence;
122+
std::string ErrWhence;
123123
std::mutex &ErrLock;
124124
SmallSet<instrprof_error, 4> &WriterErrorCodes;
125125

@@ -137,6 +137,9 @@ static void loadInput(const WeightedFile &Input, WriterContext *WC) {
137137
if (WC->Err)
138138
return;
139139

140+
// Copy the filename, because llvm::ThreadPool copied the input "const
141+
// WeightedFile &" by value, making a reference to the filename within it
142+
// invalid outside of this packaged task.
140143
WC->ErrWhence = Input.Filename;
141144

142145
auto ReaderOrErr = InstrProfReader::create(Input.Filename);
@@ -180,6 +183,11 @@ static void loadInput(const WeightedFile &Input, WriterContext *WC) {
180183

181184
/// Merge the \p Src writer context into \p Dst.
182185
static void mergeWriterContexts(WriterContext *Dst, WriterContext *Src) {
186+
// If we've already seen a hard error, continuing with the merge would
187+
// clobber it.
188+
if (Dst->Err || Src->Err)
189+
return;
190+
183191
bool Reported = false;
184192
Dst->Writer.mergeRecordsFromWriter(std::move(Src->Writer), [&](Error E) {
185193
if (Reported) {

0 commit comments

Comments
 (0)
Please sign in to comment.