<div dir="ltr"><div>Yeah - sorry about that.<br><br></div>I am reverting for the moment.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 12, 2015 at 10:21 AM, Bruno Cardoso Lopes <span dir="ltr"><<a href="mailto:bruno.cardoso@gmail.com" target="_blank">bruno.cardoso@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Nathan,<br>
<br>
This is failing a test in<br>
<a href="http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_check/" rel="noreferrer" target="_blank">http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_check/</a><br>
<br>
/Users/buildslave/jenkins/sharedspace/incremental@2/llvm/test/Transforms/SampleProfile/syntax.ll:16:18:<br>
error: expected string not found in input<br>
<br>
; BAD-FN-HEADER: error: {{.*}}bad_fn_header.prof:1: Expected<br>
'mangled_name:NUM:NUM', found 3empty:100:BAD<br>
                 ^<br>
<stdin>:1:1: note: scanning from here<br>
<br>
error: /Users/buildslave/jenkins/sharedspace/incremental@2/llvm/test/Transforms/SampleProfile/Inputs/bad_fn_header.prof:<br>
Could not open profile: Unrecognized sample profile encoding format<br>
^<br>
<br>
Thanks,<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Thu, Nov 12, 2015 at 10:06 AM, Nathan Slingerland via llvm-commits<br>
<<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
> Author: slingn<br>
> Date: Thu Nov 12 12:06:18 2015<br>
> New Revision: 252916<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=252916&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=252916&view=rev</a><br>
> Log:<br>
> [llvm-profdata] Add check for text profile formats and improve error reporting<br>
><br>
> Summary:<br>
> This change addresses two possible instances of user error / confusion when<br>
> merging sampled profile data.<br>
><br>
> Previously any input that didn't match the raw or processed instrumented format<br>
> would automatically be interpreted as instrumented profile text format data.<br>
> No error would be reported during the merge.<br>
><br>
> Example:<br>
> If foo-sampled.profdata and bar-sampled.profdata are binary sampled profiles:<br>
><br>
> Old behavior:<br>
> $ llvm-profdata merge foo-sampled.profdata bar-sampled.profdata -output foobar-sampled.profdata<br>
> $ llvm-profdata show -sample foobar-sampled.profdata<br>
> error: foobar-sampled.profdata:1: Expected 'mangled_name:NUM:NUM', found  lprofi<br>
><br>
> This change adds basic checks for valid input data when assuming text input.<br>
> It also makes error messages related to file format validity more specific about<br>
> the assumbed profile data type.<br>
><br>
> New behavior:<br>
> $ llvm-profdata merge foo-sampled.profdata bar-sampled.profdata -o foobar-sampled.profdata<br>
> error: foo.profdata: Unrecognized instrumentation profile encoding format<br>
> Perhaps you forgot to use the -sample option?<br>
><br>
> Reviewers: bogner, davidxl, dnovillo<br>
><br>
> Subscribers: davidxl, llvm-commits<br>
><br>
> Differential Revision: <a href="http://reviews.llvm.org/D14558" rel="noreferrer" target="_blank">http://reviews.llvm.org/D14558</a><br>
><br>
> Modified:<br>
>     llvm/trunk/include/llvm/ProfileData/InstrProf.h<br>
>     llvm/trunk/include/llvm/ProfileData/InstrProfReader.h<br>
>     llvm/trunk/include/llvm/ProfileData/SampleProfReader.h<br>
>     llvm/trunk/lib/ProfileData/InstrProf.cpp<br>
>     llvm/trunk/lib/ProfileData/InstrProfReader.cpp<br>
>     llvm/trunk/lib/ProfileData/SampleProf.cpp<br>
>     llvm/trunk/lib/ProfileData/SampleProfReader.cpp<br>
>     llvm/trunk/test/tools/llvm-profdata/raw-magic-but-no-header.test<br>
>     llvm/trunk/test/tools/llvm-profdata/sample-profile-basic.test<br>
>     llvm/trunk/test/tools/llvm-profdata/text-format-errors.test<br>
>     llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp<br>
><br>
> Modified: llvm/trunk/include/llvm/ProfileData/InstrProf.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=252916&r1=252915&r2=252916&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=252916&r1=252915&r2=252916&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/ProfileData/InstrProf.h (original)<br>
> +++ llvm/trunk/include/llvm/ProfileData/InstrProf.h Thu Nov 12 12:06:18 2015<br>
> @@ -149,6 +149,7 @@ const std::error_category &instrprof_cat<br>
>  enum class instrprof_error {<br>
>    success = 0,<br>
>    eof,<br>
> +  unrecognized_format,<br>
>    bad_magic,<br>
>    bad_header,<br>
>    unsupported_version,<br>
><br>
> Modified: llvm/trunk/include/llvm/ProfileData/InstrProfReader.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProfReader.h?rev=252916&r1=252915&r2=252916&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProfReader.h?rev=252916&r1=252915&r2=252916&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/ProfileData/InstrProfReader.h (original)<br>
> +++ llvm/trunk/include/llvm/ProfileData/InstrProfReader.h Thu Nov 12 12:06:18 2015<br>
> @@ -111,6 +111,9 @@ public:<br>
>    TextInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer_)<br>
>        : DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer, true, '#') {}<br>
><br>
> +  /// Return true if the given buffer is in text instrprof format.<br>
> +  static bool hasFormat(const MemoryBuffer &Buffer);<br>
> +<br>
>    /// Read the header.<br>
>    std::error_code readHeader() override { return success(); }<br>
>    /// Read a single record.<br>
><br>
> Modified: llvm/trunk/include/llvm/ProfileData/SampleProfReader.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/SampleProfReader.h?rev=252916&r1=252915&r2=252916&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/SampleProfReader.h?rev=252916&r1=252915&r2=252916&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/ProfileData/SampleProfReader.h (original)<br>
> +++ llvm/trunk/include/llvm/ProfileData/SampleProfReader.h Thu Nov 12 12:06:18 2015<br>
> @@ -292,6 +292,9 @@ public:<br>
><br>
>    /// \brief Read sample profiles from the associated file.<br>
>    std::error_code read() override;<br>
> +<br>
> +  /// \brief Return true if \p Buffer is in the format supported by this class.<br>
> +  static bool hasFormat(const MemoryBuffer &Buffer);<br>
>  };<br>
><br>
>  class SampleProfileReaderBinary : public SampleProfileReader {<br>
><br>
> Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=252916&r1=252915&r2=252916&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=252916&r1=252915&r2=252916&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)<br>
> +++ llvm/trunk/lib/ProfileData/InstrProf.cpp Thu Nov 12 12:06:18 2015<br>
> @@ -32,20 +32,22 @@ class InstrProfErrorCategoryType : publi<br>
>        return "Success";<br>
>      case instrprof_error::eof:<br>
>        return "End of File";<br>
> +    case instrprof_error::unrecognized_format:<br>
> +      return "Unrecognized instrumentation profile encoding format";<br>
>      case instrprof_error::bad_magic:<br>
> -      return "Invalid profile data (bad magic)";<br>
> +      return "Invalid instrumentation profile data (bad magic)";<br>
>      case instrprof_error::bad_header:<br>
> -      return "Invalid profile data (file header is corrupt)";<br>
> +      return "Invalid instrumentation profile data (file header is corrupt)";<br>
>      case instrprof_error::unsupported_version:<br>
> -      return "Unsupported profiling format version";<br>
> +      return "Unsupported instrumentation profile format version";<br>
>      case instrprof_error::unsupported_hash_type:<br>
> -      return "Unsupported profiling hash";<br>
> +      return "Unsupported instrumentation profile hash type";<br>
>      case instrprof_error::too_large:<br>
>        return "Too much profile data";<br>
>      case instrprof_error::truncated:<br>
>        return "Truncated profile data";<br>
>      case instrprof_error::malformed:<br>
> -      return "Malformed profile data";<br>
> +      return "Malformed instrumentation profile data";<br>
>      case instrprof_error::unknown_function:<br>
>        return "No profile data available for function";<br>
>      case instrprof_error::hash_mismatch:<br>
><br>
> Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=252916&r1=252915&r2=252916&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=252916&r1=252915&r2=252916&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)<br>
> +++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Thu Nov 12 12:06:18 2015<br>
> @@ -54,8 +54,10 @@ InstrProfReader::create(std::unique_ptr<<br>
>      Result.reset(new RawInstrProfReader64(std::move(Buffer)));<br>
>    else if (RawInstrProfReader32::hasFormat(*Buffer))<br>
>      Result.reset(new RawInstrProfReader32(std::move(Buffer)));<br>
> -  else<br>
> +  else if (TextInstrProfReader::hasFormat(*Buffer))<br>
>      Result.reset(new TextInstrProfReader(std::move(Buffer)));<br>
> +  else<br>
> +    return instrprof_error::unrecognized_format;<br>
><br>
>    // Initialize the reader and return the result.<br>
>    if (std::error_code EC = initializeReader(*Result))<br>
> @@ -97,6 +99,15 @@ void InstrProfIterator::Increment() {<br>
>      *this = InstrProfIterator();<br>
>  }<br>
><br>
> +bool TextInstrProfReader::hasFormat(const MemoryBuffer &Buffer) {<br>
> +  // Verify that this really looks like plain ASCII text by checking a<br>
> +  // 'reasonable' number of characters (up to profile magic size).<br>
> +  size_t count = std::min(Buffer.getBufferSize(), sizeof(uint64_t));<br>
> +  StringRef buffer = Buffer.getBufferStart();<br>
> +  return count == 0 || std::all_of(buffer.begin(), buffer.begin() + count,<br>
> +    [](char c) { return ::isprint(c) || ::isspace(c); });<br>
> +}<br>
> +<br>
>  std::error_code TextInstrProfReader::readNextRecord(InstrProfRecord &Record) {<br>
>    // Skip empty lines and comments.<br>
>    while (!Line.is_at_end() && (Line->empty() || Line->startswith("#")))<br>
><br>
> Modified: llvm/trunk/lib/ProfileData/SampleProf.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/SampleProf.cpp?rev=252916&r1=252915&r2=252916&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/SampleProf.cpp?rev=252916&r1=252915&r2=252916&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/ProfileData/SampleProf.cpp (original)<br>
> +++ llvm/trunk/lib/ProfileData/SampleProf.cpp Thu Nov 12 12:06:18 2015<br>
> @@ -28,17 +28,17 @@ class SampleProfErrorCategoryType : publ<br>
>      case sampleprof_error::success:<br>
>        return "Success";<br>
>      case sampleprof_error::bad_magic:<br>
> -      return "Invalid file format (bad magic)";<br>
> +      return "Invalid sample profile data (bad magic)";<br>
>      case sampleprof_error::unsupported_version:<br>
> -      return "Unsupported format version";<br>
> +      return "Unsupported sample profile format version";<br>
>      case sampleprof_error::too_large:<br>
>        return "Too much profile data";<br>
>      case sampleprof_error::truncated:<br>
>        return "Truncated profile data";<br>
>      case sampleprof_error::malformed:<br>
> -      return "Malformed profile data";<br>
> +      return "Malformed sample profile data";<br>
>      case sampleprof_error::unrecognized_format:<br>
> -      return "Unrecognized profile encoding format";<br>
> +      return "Unrecognized sample profile encoding format";<br>
>      case sampleprof_error::unsupported_writing_format:<br>
>        return "Profile encoding format unsupported for writing operations";<br>
>      case sampleprof_error::truncated_name_table:<br>
><br>
> Modified: llvm/trunk/lib/ProfileData/SampleProfReader.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/SampleProfReader.cpp?rev=252916&r1=252915&r2=252916&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/SampleProfReader.cpp?rev=252916&r1=252915&r2=252916&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/ProfileData/SampleProfReader.cpp (original)<br>
> +++ llvm/trunk/lib/ProfileData/SampleProfReader.cpp Thu Nov 12 12:06:18 2015<br>
> @@ -222,6 +222,22 @@ std::error_code SampleProfileReaderText:<br>
>    return sampleprof_error::success;<br>
>  }<br>
><br>
> +bool SampleProfileReaderText::hasFormat(const MemoryBuffer &Buffer) {<br>
> +  bool result = false;<br>
> +<br>
> +  // Check that the first non-comment line is a valid function header.<br>
> +  line_iterator LineIt(Buffer, /*SkipBlanks=*/true, '#');<br>
> +  if (!LineIt.is_at_eof()) {<br>
> +    if ((*LineIt)[0] != ' ') {<br>
> +      uint64_t NumSamples, NumHeadSamples;<br>
> +      StringRef FName;<br>
> +      result = ParseHead(*LineIt, FName, NumSamples, NumHeadSamples);<br>
> +    }<br>
> +  }<br>
> +<br>
> +  return result;<br>
> +}<br>
> +<br>
>  template <typename T> ErrorOr<T> SampleProfileReaderBinary::readNumber() {<br>
>    unsigned NumBytesRead = 0;<br>
>    std::error_code EC;<br>
> @@ -685,8 +701,10 @@ SampleProfileReader::create(StringRef Fi<br>
>      Reader.reset(new SampleProfileReaderBinary(std::move(Buffer), C));<br>
>    else if (SampleProfileReaderGCC::hasFormat(*Buffer))<br>
>      Reader.reset(new SampleProfileReaderGCC(std::move(Buffer), C));<br>
> -  else<br>
> +  else if (SampleProfileReaderText::hasFormat(*Buffer))<br>
>      Reader.reset(new SampleProfileReaderText(std::move(Buffer), C));<br>
> +  else<br>
> +    return sampleprof_error::unrecognized_format;<br>
><br>
>    if (std::error_code EC = Reader->readHeader())<br>
>      return EC;<br>
><br>
> Modified: llvm/trunk/test/tools/llvm-profdata/raw-magic-but-no-header.test<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/raw-magic-but-no-header.test?rev=252916&r1=252915&r2=252916&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/raw-magic-but-no-header.test?rev=252916&r1=252915&r2=252916&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/tools/llvm-profdata/raw-magic-but-no-header.test (original)<br>
> +++ llvm/trunk/test/tools/llvm-profdata/raw-magic-but-no-header.test Thu Nov 12 12:06:18 2015<br>
> @@ -3,4 +3,4 @@ RUN: not llvm-profdata show %t 2>&1 | Fi<br>
>  RUN: printf '\377lprofr\201' > %t<br>
>  RUN: not llvm-profdata show %t 2>&1 | FileCheck %s<br>
><br>
> -CHECK: error: {{.+}}: Invalid profile data (file header is corrupt)<br>
> +CHECK: error: {{.+}}: Invalid instrumentation profile data (file header is corrupt)<br>
><br>
> Modified: llvm/trunk/test/tools/llvm-profdata/sample-profile-basic.test<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/sample-profile-basic.test?rev=252916&r1=252915&r2=252916&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/sample-profile-basic.test?rev=252916&r1=252915&r2=252916&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/tools/llvm-profdata/sample-profile-basic.test (original)<br>
> +++ llvm/trunk/test/tools/llvm-profdata/sample-profile-basic.test Thu Nov 12 12:06:18 2015<br>
> @@ -28,3 +28,7 @@ RUN: llvm-profdata merge --sample --text<br>
>  MERGE1: main:368038:0<br>
>  MERGE1: 9: 4128 _Z3fooi:1262 _Z3bari:2942<br>
>  MERGE1: _Z3fooi:15422:1220<br>
> +<br>
> +5- Detect invalid text encoding (e.g. instrumentation profile text format).<br>
> +RUN: not llvm-profdata show --sample %p/Inputs/foo3bar3-1.proftext 2>&1 | FileCheck %s --check-prefix=BADTEXT<br>
> +BADTEXT: error: {{.+}}: Unrecognized sample profile encoding format<br>
><br>
> Modified: llvm/trunk/test/tools/llvm-profdata/text-format-errors.test<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/text-format-errors.test?rev=252916&r1=252915&r2=252916&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/text-format-errors.test?rev=252916&r1=252915&r2=252916&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/tools/llvm-profdata/text-format-errors.test (original)<br>
> +++ llvm/trunk/test/tools/llvm-profdata/text-format-errors.test Thu Nov 12 12:06:18 2015<br>
> @@ -1,10 +1,21 @@<br>
> +Tests for instrumentation profile bad encoding.<br>
> +<br>
> +1- Detect invalid count<br>
>  RUN: not llvm-profdata show %p/Inputs/invalid-count-later.proftext 2>&1 | FileCheck %s --check-prefix=INVALID-COUNT-LATER<br>
>  RUN: not llvm-profdata merge %p/Inputs/invalid-count-later.proftext %p/Inputs/invalid-count-later.profdata -o %t.out 2>&1 | FileCheck %s --check-prefix=INVALID-COUNT-LATER<br>
> -INVALID-COUNT-LATER: error: {{.*}}invalid-count-later.proftext: Malformed profile data<br>
> +INVALID-COUNT-LATER: error: {{.*}}invalid-count-later.proftext: Malformed instrumentation profile data<br>
><br>
> +2- Detect bad hash<br>
>  RUN: not llvm-profdata show %p/Inputs/bad-hash.proftext 2>&1 | FileCheck %s --check-prefix=BAD-HASH<br>
>  RUN: not llvm-profdata merge %p/Inputs/bad-hash.proftext %p/Inputs/bad-hash.proftext -o %t.out 2>&1 | FileCheck %s --check-prefix=BAD-HASH<br>
> -BAD-HASH: error: {{.*}}bad-hash.proftext: Malformed profile data<br>
> +BAD-HASH: error: {{.*}}bad-hash.proftext: Malformed instrumentation profile data<br>
><br>
> +3- Detect no counts<br>
>  RUN: not llvm-profdata show %p/Inputs/no-counts.proftext 2>&1 | FileCheck %s --check-prefix=NO-COUNTS<br>
> -NO-COUNTS: error: {{.*}}no-counts.proftext: Malformed profile data<br>
> +NO-COUNTS: error: {{.*}}no-counts.proftext: Malformed instrumentation profile data<br>
> +<br>
> +4- Detect binary input<br>
> +RUN: echo -n $'\xff\xe5\xd0\xb1\xf4\c9\x94\xa8' > %t.bin<br>
> +RUN: not llvm-profdata show %t.bin 2>&1 | FileCheck %s --check-prefix=BINARY<br>
> +BINARY: error: {{.+}}: Unrecognized instrumentation profile encoding format<br>
> +BINARY: Perhaps you forgot to use the -sample option?<br>
><br>
> Modified: llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp?rev=252916&r1=252915&r2=252916&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp?rev=252916&r1=252915&r2=252916&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp (original)<br>
> +++ llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp Thu Nov 12 12:06:18 2015<br>
> @@ -29,16 +29,32 @@<br>
><br>
>  using namespace llvm;<br>
><br>
> -static void exitWithError(const Twine &Message, StringRef Whence = "") {<br>
> +static void exitWithError(const Twine &Message,<br>
> +                          StringRef Whence = "",<br>
> +                          StringRef Hint = "") {<br>
>    errs() << "error: ";<br>
>    if (!Whence.empty())<br>
>      errs() << Whence << ": ";<br>
>    errs() << Message << "\n";<br>
> +  if (!Hint.empty())<br>
> +    errs() << Hint << "\n";<br>
>    ::exit(1);<br>
>  }<br>
><br>
> +static void exitWithErrorCode(const std::error_code &Error, StringRef Whence = "") {<br>
> +  if (Error.category() == instrprof_category()) {<br>
> +    instrprof_error instrError = static_cast<instrprof_error>(Error.value());<br>
> +    if (instrError == instrprof_error::unrecognized_format) {<br>
> +      // Hint for common error of forgetting -sample for sample profiles.<br>
> +      exitWithError(Error.message(), Whence,<br>
> +                    "Perhaps you forgot to use the -sample option?");<br>
> +    }<br>
> +  }<br>
> +  exitWithError(Error.message(), Whence);<br>
> +}<br>
> +<br>
>  namespace {<br>
> -enum ProfileKinds { instr, sample };<br>
> +    enum ProfileKinds { instr, sample };<br>
>  }<br>
><br>
>  static void mergeInstrProfile(const cl::list<std::string> &Inputs,<br>
> @@ -49,20 +65,20 @@ static void mergeInstrProfile(const cl::<br>
>    std::error_code EC;<br>
>    raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::F_None);<br>
>    if (EC)<br>
> -    exitWithError(EC.message(), OutputFilename);<br>
> +    exitWithErrorCode(EC, OutputFilename);<br>
><br>
>    InstrProfWriter Writer;<br>
>    for (const auto &Filename : Inputs) {<br>
>      auto ReaderOrErr = InstrProfReader::create(Filename);<br>
>      if (std::error_code ec = ReaderOrErr.getError())<br>
> -      exitWithError(ec.message(), Filename);<br>
> +      exitWithErrorCode(ec, Filename);<br>
><br>
>      auto Reader = std::move(ReaderOrErr.get());<br>
>      for (auto &I : *Reader)<br>
>        if (std::error_code EC = Writer.addRecord(std::move(I)))<br>
>          errs() << Filename << ": " << I.Name << ": " << EC.message() << "\n";<br>
>      if (Reader->hasError())<br>
> -      exitWithError(Reader->getError().message(), Filename);<br>
> +      exitWithErrorCode(Reader->getError(), Filename);<br>
>    }<br>
>    Writer.write(Output);<br>
>  }<br>
> @@ -73,7 +89,7 @@ static void mergeSampleProfile(const cl:<br>
>    using namespace sampleprof;<br>
>    auto WriterOrErr = SampleProfileWriter::create(OutputFilename, OutputFormat);<br>
>    if (std::error_code EC = WriterOrErr.getError())<br>
> -    exitWithError(EC.message(), OutputFilename);<br>
> +    exitWithErrorCode(EC, OutputFilename);<br>
><br>
>    auto Writer = std::move(WriterOrErr.get());<br>
>    StringMap<FunctionSamples> ProfileMap;<br>
> @@ -82,7 +98,7 @@ static void mergeSampleProfile(const cl:<br>
>      auto ReaderOrErr =<br>
>          SampleProfileReader::create(Filename, getGlobalContext());<br>
>      if (std::error_code EC = ReaderOrErr.getError())<br>
> -      exitWithError(EC.message(), Filename);<br>
> +      exitWithErrorCode(EC, Filename);<br>
><br>
>      // We need to keep the readers around until after all the files are<br>
>      // read so that we do not lose the function names stored in each<br>
> @@ -91,7 +107,7 @@ static void mergeSampleProfile(const cl:<br>
>      Readers.push_back(std::move(ReaderOrErr.get()));<br>
>      const auto Reader = Readers.back().get();<br>
>      if (std::error_code EC = Reader->read())<br>
> -      exitWithError(EC.message(), Filename);<br>
> +      exitWithErrorCode(EC, Filename);<br>
><br>
>      StringMap<FunctionSamples> &Profiles = Reader->getProfiles();<br>
>      for (StringMap<FunctionSamples>::iterator I = Profiles.begin(),<br>
> @@ -143,7 +159,7 @@ static int showInstrProfile(std::string<br>
>                              std::string ShowFunction, raw_fd_ostream &OS) {<br>
>    auto ReaderOrErr = InstrProfReader::create(Filename);<br>
>    if (std::error_code EC = ReaderOrErr.getError())<br>
> -    exitWithError(EC.message(), Filename);<br>
> +    exitWithErrorCode(EC, Filename);<br>
><br>
>    auto Reader = std::move(ReaderOrErr.get());<br>
>    uint64_t MaxFunctionCount = 0, MaxBlockCount = 0;<br>
> @@ -198,7 +214,7 @@ static int showInstrProfile(std::string<br>
>      }<br>
>    }<br>
>    if (Reader->hasError())<br>
> -    exitWithError(Reader->getError().message(), Filename);<br>
> +    exitWithErrorCode(Reader->getError(), Filename);<br>
><br>
>    if (ShowAllFunctions || !ShowFunction.empty())<br>
>      OS << "Functions shown: " << ShownFunctions << "\n";<br>
> @@ -214,11 +230,11 @@ static int showSampleProfile(std::string<br>
>    using namespace sampleprof;<br>
>    auto ReaderOrErr = SampleProfileReader::create(Filename, getGlobalContext());<br>
>    if (std::error_code EC = ReaderOrErr.getError())<br>
> -    exitWithError(EC.message(), Filename);<br>
> +    exitWithErrorCode(EC, Filename);<br>
><br>
>    auto Reader = std::move(ReaderOrErr.get());<br>
>    if (std::error_code EC = Reader->read())<br>
> -    exitWithError(EC.message(), Filename);<br>
> +    exitWithErrorCode(EC, Filename);<br>
><br>
>    if (ShowAllFunctions || ShowFunction.empty())<br>
>      Reader->dump(OS);<br>
> @@ -259,7 +275,7 @@ static int show_main(int argc, const cha<br>
>    std::error_code EC;<br>
>    raw_fd_ostream OS(OutputFilename.data(), EC, sys::fs::F_Text);<br>
>    if (EC)<br>
> -    exitWithError(EC.message(), OutputFilename);<br>
> +      exitWithErrorCode(EC, OutputFilename);<br>
><br>
>    if (ShowAllFunctions && !ShowFunction.empty())<br>
>      errs() << "warning: -function argument ignored: showing all functions\n";<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Bruno Cardoso Lopes<br>
<a href="http://www.brunocardoso.cc" rel="noreferrer" target="_blank">http://www.brunocardoso.cc</a><br>
</font></span></blockquote></div><br></div>