[llvm] r318502 - [llvm-profdata] Fix a dangling reference to an error string

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 16 18:58:23 PST 2017


Author: vedantk
Date: Thu Nov 16 18:58:23 2017
New Revision: 318502

URL: http://llvm.org/viewvc/llvm-project?rev=318502&view=rev
Log:
[llvm-profdata] Fix a dangling reference to an error string

Added:
    llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext
    llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-2.proftext
    llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-3.proftext
    llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-4.proftext
    llvm/trunk/test/tools/llvm-profdata/threaded-count-mismatch.test
Modified:
    llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp

Added: llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext?rev=318502&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext (added)
+++ llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext Thu Nov 16 18:58:23 2017
@@ -0,0 +1,4 @@
+foo
+1024
+1
+0

Added: llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-2.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-2.proftext?rev=318502&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-2.proftext (added)
+++ llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-2.proftext Thu Nov 16 18:58:23 2017
@@ -0,0 +1,5 @@
+foo
+1024
+2
+0
+0

Added: llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-3.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-3.proftext?rev=318502&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-3.proftext (added)
+++ llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-3.proftext Thu Nov 16 18:58:23 2017
@@ -0,0 +1,6 @@
+foo
+1024
+3
+0
+0
+0

Added: llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-4.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-4.proftext?rev=318502&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-4.proftext (added)
+++ llvm/trunk/test/tools/llvm-profdata/Inputs/counter-mismatch-4.proftext Thu Nov 16 18:58:23 2017
@@ -0,0 +1,7 @@
+foo
+1024
+4
+0
+0
+0
+0

Added: llvm/trunk/test/tools/llvm-profdata/threaded-count-mismatch.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/threaded-count-mismatch.test?rev=318502&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/threaded-count-mismatch.test (added)
+++ llvm/trunk/test/tools/llvm-profdata/threaded-count-mismatch.test Thu Nov 16 18:58:23 2017
@@ -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)

Modified: llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp?rev=318502&r1=318501&r2=318502&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp (original)
+++ llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp Thu Nov 16 18:58:23 2017
@@ -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
   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
 
 /// 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) {




More information about the llvm-commits mailing list