reverting r252916 to investigate test failure
authorNathan Slingerland <slingn@gmail.com>
Thu, 12 Nov 2015 18:39:26 +0000 (18:39 +0000)
committerNathan Slingerland <slingn@gmail.com>
Thu, 12 Nov 2015 18:39:26 +0000 (18:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252921 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ProfileData/InstrProf.h
include/llvm/ProfileData/InstrProfReader.h
include/llvm/ProfileData/SampleProfReader.h
lib/ProfileData/InstrProf.cpp
lib/ProfileData/InstrProfReader.cpp
lib/ProfileData/SampleProf.cpp
lib/ProfileData/SampleProfReader.cpp
test/tools/llvm-profdata/raw-magic-but-no-header.test
test/tools/llvm-profdata/sample-profile-basic.test
test/tools/llvm-profdata/text-format-errors.test
tools/llvm-profdata/llvm-profdata.cpp

index 2339a46f9c5540c55b3cd3a788e07aadf0b34add..607f29de8a23f8523397146de9f3ac3c9c21637b 100644 (file)
@@ -149,7 +149,6 @@ const std::error_category &instrprof_category();
 enum class instrprof_error {
   success = 0,
   eof,
 enum class instrprof_error {
   success = 0,
   eof,
-  unrecognized_format,
   bad_magic,
   bad_header,
   unsupported_version,
   bad_magic,
   bad_header,
   unsupported_version,
index 3d4777a853ecf6dec73e3c3b7850fe3163bb8d2c..d0f5a57b1ae80e89c2100fd05e7d1e809c5628d3 100644 (file)
@@ -111,9 +111,6 @@ public:
   TextInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer_)
       : DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer, true, '#') {}
 
   TextInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer_)
       : DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer, true, '#') {}
 
-  /// Return true if the given buffer is in text instrprof format.
-  static bool hasFormat(const MemoryBuffer &Buffer);
-
   /// Read the header.
   std::error_code readHeader() override { return success(); }
   /// Read a single record.
   /// Read the header.
   std::error_code readHeader() override { return success(); }
   /// Read a single record.
index 1fb2cf6e0ca4b9b3a2f36a6b91180aa0e3b265c6..2f404be50e6ae699ec4a70462ddb2776dfb7042d 100644 (file)
@@ -292,9 +292,6 @@ public:
 
   /// \brief Read sample profiles from the associated file.
   std::error_code read() override;
 
   /// \brief Read sample profiles from the associated file.
   std::error_code read() override;
-
-  /// \brief Return true if \p Buffer is in the format supported by this class.
-  static bool hasFormat(const MemoryBuffer &Buffer);
 };
 
 class SampleProfileReaderBinary : public SampleProfileReader {
 };
 
 class SampleProfileReaderBinary : public SampleProfileReader {
index 762f00b48b6404dfd272508a9b868af045261fa5..92a3c251f6ef806ddf24b6bb05d8caebaa3f5447 100644 (file)
@@ -32,22 +32,20 @@ class InstrProfErrorCategoryType : public std::error_category {
       return "Success";
     case instrprof_error::eof:
       return "End of File";
       return "Success";
     case instrprof_error::eof:
       return "End of File";
-    case instrprof_error::unrecognized_format:
-      return "Unrecognized instrumentation profile encoding format";
     case instrprof_error::bad_magic:
     case instrprof_error::bad_magic:
-      return "Invalid instrumentation profile data (bad magic)";
+      return "Invalid profile data (bad magic)";
     case instrprof_error::bad_header:
     case instrprof_error::bad_header:
-      return "Invalid instrumentation profile data (file header is corrupt)";
+      return "Invalid profile data (file header is corrupt)";
     case instrprof_error::unsupported_version:
     case instrprof_error::unsupported_version:
-      return "Unsupported instrumentation profile format version";
+      return "Unsupported profiling format version";
     case instrprof_error::unsupported_hash_type:
     case instrprof_error::unsupported_hash_type:
-      return "Unsupported instrumentation profile hash type";
+      return "Unsupported profiling hash";
     case instrprof_error::too_large:
       return "Too much profile data";
     case instrprof_error::truncated:
       return "Truncated profile data";
     case instrprof_error::malformed:
     case instrprof_error::too_large:
       return "Too much profile data";
     case instrprof_error::truncated:
       return "Truncated profile data";
     case instrprof_error::malformed:
-      return "Malformed instrumentation profile data";
+      return "Malformed profile data";
     case instrprof_error::unknown_function:
       return "No profile data available for function";
     case instrprof_error::hash_mismatch:
     case instrprof_error::unknown_function:
       return "No profile data available for function";
     case instrprof_error::hash_mismatch:
index 6f201243736d09baecce19d27c1fa7478a70add8..bf10b448e4cc7c29729575805df617965018100e 100644 (file)
@@ -54,10 +54,8 @@ InstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
     Result.reset(new RawInstrProfReader64(std::move(Buffer)));
   else if (RawInstrProfReader32::hasFormat(*Buffer))
     Result.reset(new RawInstrProfReader32(std::move(Buffer)));
     Result.reset(new RawInstrProfReader64(std::move(Buffer)));
   else if (RawInstrProfReader32::hasFormat(*Buffer))
     Result.reset(new RawInstrProfReader32(std::move(Buffer)));
-  else if (TextInstrProfReader::hasFormat(*Buffer))
-    Result.reset(new TextInstrProfReader(std::move(Buffer)));
   else
   else
-    return instrprof_error::unrecognized_format;
+    Result.reset(new TextInstrProfReader(std::move(Buffer)));
 
   // Initialize the reader and return the result.
   if (std::error_code EC = initializeReader(*Result))
 
   // Initialize the reader and return the result.
   if (std::error_code EC = initializeReader(*Result))
@@ -99,15 +97,6 @@ void InstrProfIterator::Increment() {
     *this = InstrProfIterator();
 }
 
     *this = InstrProfIterator();
 }
 
-bool TextInstrProfReader::hasFormat(const MemoryBuffer &Buffer) {
-  // Verify that this really looks like plain ASCII text by checking a
-  // 'reasonable' number of characters (up to profile magic size).
-  size_t count = std::min(Buffer.getBufferSize(), sizeof(uint64_t));
-  StringRef buffer = Buffer.getBufferStart();
-  return count == 0 || std::all_of(buffer.begin(), buffer.begin() + count,
-    [](char c) { return ::isprint(c) || ::isspace(c); });
-}
-
 std::error_code TextInstrProfReader::readNextRecord(InstrProfRecord &Record) {
   // Skip empty lines and comments.
   while (!Line.is_at_end() && (Line->empty() || Line->startswith("#")))
 std::error_code TextInstrProfReader::readNextRecord(InstrProfRecord &Record) {
   // Skip empty lines and comments.
   while (!Line.is_at_end() && (Line->empty() || Line->startswith("#")))
index 856923e164bd72bf3bee44436c12f9311737faea..b5d3b2d2e551c9c03d7b10bdd3b34544a5277cc6 100644 (file)
@@ -28,17 +28,17 @@ class SampleProfErrorCategoryType : public std::error_category {
     case sampleprof_error::success:
       return "Success";
     case sampleprof_error::bad_magic:
     case sampleprof_error::success:
       return "Success";
     case sampleprof_error::bad_magic:
-      return "Invalid sample profile data (bad magic)";
+      return "Invalid file format (bad magic)";
     case sampleprof_error::unsupported_version:
     case sampleprof_error::unsupported_version:
-      return "Unsupported sample profile format version";
+      return "Unsupported format version";
     case sampleprof_error::too_large:
       return "Too much profile data";
     case sampleprof_error::truncated:
       return "Truncated profile data";
     case sampleprof_error::malformed:
     case sampleprof_error::too_large:
       return "Too much profile data";
     case sampleprof_error::truncated:
       return "Truncated profile data";
     case sampleprof_error::malformed:
-      return "Malformed sample profile data";
+      return "Malformed profile data";
     case sampleprof_error::unrecognized_format:
     case sampleprof_error::unrecognized_format:
-      return "Unrecognized sample profile encoding format";
+      return "Unrecognized profile encoding format";
     case sampleprof_error::unsupported_writing_format:
       return "Profile encoding format unsupported for writing operations";
     case sampleprof_error::truncated_name_table:
     case sampleprof_error::unsupported_writing_format:
       return "Profile encoding format unsupported for writing operations";
     case sampleprof_error::truncated_name_table:
index 0bed4f09f1f1cd0808c208f74c581b980ad6bf15..a5d00083b53641400f1244890d0be28b05afd41f 100644 (file)
@@ -222,22 +222,6 @@ std::error_code SampleProfileReaderText::read() {
   return sampleprof_error::success;
 }
 
   return sampleprof_error::success;
 }
 
-bool SampleProfileReaderText::hasFormat(const MemoryBuffer &Buffer) {
-  bool result = false;
-
-  // Check that the first non-comment line is a valid function header.
-  line_iterator LineIt(Buffer, /*SkipBlanks=*/true, '#');
-  if (!LineIt.is_at_eof()) {
-    if ((*LineIt)[0] != ' ') {
-      uint64_t NumSamples, NumHeadSamples;
-      StringRef FName;
-      result = ParseHead(*LineIt, FName, NumSamples, NumHeadSamples);
-    }
-  }
-
-  return result;
-}
-
 template <typename T> ErrorOr<T> SampleProfileReaderBinary::readNumber() {
   unsigned NumBytesRead = 0;
   std::error_code EC;
 template <typename T> ErrorOr<T> SampleProfileReaderBinary::readNumber() {
   unsigned NumBytesRead = 0;
   std::error_code EC;
@@ -701,10 +685,8 @@ SampleProfileReader::create(StringRef Filename, LLVMContext &C) {
     Reader.reset(new SampleProfileReaderBinary(std::move(Buffer), C));
   else if (SampleProfileReaderGCC::hasFormat(*Buffer))
     Reader.reset(new SampleProfileReaderGCC(std::move(Buffer), C));
     Reader.reset(new SampleProfileReaderBinary(std::move(Buffer), C));
   else if (SampleProfileReaderGCC::hasFormat(*Buffer))
     Reader.reset(new SampleProfileReaderGCC(std::move(Buffer), C));
-  else if (SampleProfileReaderText::hasFormat(*Buffer))
-    Reader.reset(new SampleProfileReaderText(std::move(Buffer), C));
   else
   else
-    return sampleprof_error::unrecognized_format;
+    Reader.reset(new SampleProfileReaderText(std::move(Buffer), C));
 
   if (std::error_code EC = Reader->readHeader())
     return EC;
 
   if (std::error_code EC = Reader->readHeader())
     return EC;
index 76894faa183c9dd4e21dfd625790b3981d73e13e..b2a697042b0ab72b4863ec4617d257ab5f200c9c 100644 (file)
@@ -3,4 +3,4 @@ RUN: not llvm-profdata show %t 2>&1 | FileCheck %s
 RUN: printf '\377lprofr\201' > %t
 RUN: not llvm-profdata show %t 2>&1 | FileCheck %s
 
 RUN: printf '\377lprofr\201' > %t
 RUN: not llvm-profdata show %t 2>&1 | FileCheck %s
 
-CHECK: error: {{.+}}: Invalid instrumentation profile data (file header is corrupt)
+CHECK: error: {{.+}}: Invalid profile data (file header is corrupt)
index 9981d4204c430ae4c467619f560f106f049c4814..0651c513e9655f7606d70f153c37961ab00a7161 100644 (file)
@@ -28,7 +28,3 @@ RUN: llvm-profdata merge --sample --text %p/Inputs/sample-profile.proftext %t-bi
 MERGE1: main:368038:0
 MERGE1: 9: 4128 _Z3fooi:1262 _Z3bari:2942
 MERGE1: _Z3fooi:15422:1220
 MERGE1: main:368038:0
 MERGE1: 9: 4128 _Z3fooi:1262 _Z3bari:2942
 MERGE1: _Z3fooi:15422:1220
-
-5- Detect invalid text encoding (e.g. instrumentation profile text format).
-RUN: not llvm-profdata show --sample %p/Inputs/foo3bar3-1.proftext 2>&1 | FileCheck %s --check-prefix=BADTEXT
-BADTEXT: error: {{.+}}: Unrecognized sample profile encoding format
index 113b10ee4e858d12faa4c3224c076fb28f2b5c38..01513e4fcb9e700360c894f87c3acf2f4a443116 100644 (file)
@@ -1,21 +1,10 @@
-Tests for instrumentation profile bad encoding.
-
-1- Detect invalid count
 RUN: not llvm-profdata show %p/Inputs/invalid-count-later.proftext 2>&1 | FileCheck %s --check-prefix=INVALID-COUNT-LATER
 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
 RUN: not llvm-profdata show %p/Inputs/invalid-count-later.proftext 2>&1 | FileCheck %s --check-prefix=INVALID-COUNT-LATER
 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
-INVALID-COUNT-LATER: error: {{.*}}invalid-count-later.proftext: Malformed instrumentation profile data
+INVALID-COUNT-LATER: error: {{.*}}invalid-count-later.proftext: Malformed profile data
 
 
-2- Detect bad hash
 RUN: not llvm-profdata show %p/Inputs/bad-hash.proftext 2>&1 | FileCheck %s --check-prefix=BAD-HASH
 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
 RUN: not llvm-profdata show %p/Inputs/bad-hash.proftext 2>&1 | FileCheck %s --check-prefix=BAD-HASH
 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
-BAD-HASH: error: {{.*}}bad-hash.proftext: Malformed instrumentation profile data
+BAD-HASH: error: {{.*}}bad-hash.proftext: Malformed profile data
 
 
-3- Detect no counts
 RUN: not llvm-profdata show %p/Inputs/no-counts.proftext 2>&1 | FileCheck %s --check-prefix=NO-COUNTS
 RUN: not llvm-profdata show %p/Inputs/no-counts.proftext 2>&1 | FileCheck %s --check-prefix=NO-COUNTS
-NO-COUNTS: error: {{.*}}no-counts.proftext: Malformed instrumentation profile data
-
-4- Detect binary input
-RUN: echo -n $'\xff\xe5\xd0\xb1\xf4\c9\x94\xa8' > %t.bin
-RUN: not llvm-profdata show %t.bin 2>&1 | FileCheck %s --check-prefix=BINARY
-BINARY: error: {{.+}}: Unrecognized instrumentation profile encoding format
-BINARY: Perhaps you forgot to use the -sample option?
+NO-COUNTS: error: {{.*}}no-counts.proftext: Malformed profile data
index 1cd47dd5e84c248cb883474f6c7c2866e1fe7d57..48fc83c6971ba9196f245004e9c15f664415ada2 100644 (file)
 
 using namespace llvm;
 
 
 using namespace llvm;
 
-static void exitWithError(const Twine &Message,
-                          StringRef Whence = "",
-                          StringRef Hint = "") {
+static void exitWithError(const Twine &Message, StringRef Whence = "") {
   errs() << "error: ";
   if (!Whence.empty())
     errs() << Whence << ": ";
   errs() << Message << "\n";
   errs() << "error: ";
   if (!Whence.empty())
     errs() << Whence << ": ";
   errs() << Message << "\n";
-  if (!Hint.empty())
-    errs() << Hint << "\n";
   ::exit(1);
 }
 
   ::exit(1);
 }
 
-static void exitWithErrorCode(const std::error_code &Error, StringRef Whence = "") {
-  if (Error.category() == instrprof_category()) {
-    instrprof_error instrError = static_cast<instrprof_error>(Error.value());
-    if (instrError == instrprof_error::unrecognized_format) {
-      // Hint for common error of forgetting -sample for sample profiles.
-      exitWithError(Error.message(), Whence,
-                    "Perhaps you forgot to use the -sample option?");
-    }
-  }
-  exitWithError(Error.message(), Whence);
-}
-
 namespace {
 namespace {
-    enum ProfileKinds { instr, sample };
+enum ProfileKinds { instr, sample };
 }
 
 static void mergeInstrProfile(const cl::list<std::string> &Inputs,
 }
 
 static void mergeInstrProfile(const cl::list<std::string> &Inputs,
@@ -65,20 +49,20 @@ static void mergeInstrProfile(const cl::list<std::string> &Inputs,
   std::error_code EC;
   raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::F_None);
   if (EC)
   std::error_code EC;
   raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::F_None);
   if (EC)
-    exitWithErrorCode(EC, OutputFilename);
+    exitWithError(EC.message(), OutputFilename);
 
   InstrProfWriter Writer;
   for (const auto &Filename : Inputs) {
     auto ReaderOrErr = InstrProfReader::create(Filename);
     if (std::error_code ec = ReaderOrErr.getError())
 
   InstrProfWriter Writer;
   for (const auto &Filename : Inputs) {
     auto ReaderOrErr = InstrProfReader::create(Filename);
     if (std::error_code ec = ReaderOrErr.getError())
-      exitWithErrorCode(ec, Filename);
+      exitWithError(ec.message(), Filename);
 
     auto Reader = std::move(ReaderOrErr.get());
     for (auto &I : *Reader)
       if (std::error_code EC = Writer.addRecord(std::move(I)))
         errs() << Filename << ": " << I.Name << ": " << EC.message() << "\n";
     if (Reader->hasError())
 
     auto Reader = std::move(ReaderOrErr.get());
     for (auto &I : *Reader)
       if (std::error_code EC = Writer.addRecord(std::move(I)))
         errs() << Filename << ": " << I.Name << ": " << EC.message() << "\n";
     if (Reader->hasError())
-      exitWithErrorCode(Reader->getError(), Filename);
+      exitWithError(Reader->getError().message(), Filename);
   }
   Writer.write(Output);
 }
   }
   Writer.write(Output);
 }
@@ -89,7 +73,7 @@ static void mergeSampleProfile(const cl::list<std::string> &Inputs,
   using namespace sampleprof;
   auto WriterOrErr = SampleProfileWriter::create(OutputFilename, OutputFormat);
   if (std::error_code EC = WriterOrErr.getError())
   using namespace sampleprof;
   auto WriterOrErr = SampleProfileWriter::create(OutputFilename, OutputFormat);
   if (std::error_code EC = WriterOrErr.getError())
-    exitWithErrorCode(EC, OutputFilename);
+    exitWithError(EC.message(), OutputFilename);
 
   auto Writer = std::move(WriterOrErr.get());
   StringMap<FunctionSamples> ProfileMap;
 
   auto Writer = std::move(WriterOrErr.get());
   StringMap<FunctionSamples> ProfileMap;
@@ -98,7 +82,7 @@ static void mergeSampleProfile(const cl::list<std::string> &Inputs,
     auto ReaderOrErr =
         SampleProfileReader::create(Filename, getGlobalContext());
     if (std::error_code EC = ReaderOrErr.getError())
     auto ReaderOrErr =
         SampleProfileReader::create(Filename, getGlobalContext());
     if (std::error_code EC = ReaderOrErr.getError())
-      exitWithErrorCode(EC, Filename);
+      exitWithError(EC.message(), Filename);
 
     // We need to keep the readers around until after all the files are
     // read so that we do not lose the function names stored in each
 
     // We need to keep the readers around until after all the files are
     // read so that we do not lose the function names stored in each
@@ -107,7 +91,7 @@ static void mergeSampleProfile(const cl::list<std::string> &Inputs,
     Readers.push_back(std::move(ReaderOrErr.get()));
     const auto Reader = Readers.back().get();
     if (std::error_code EC = Reader->read())
     Readers.push_back(std::move(ReaderOrErr.get()));
     const auto Reader = Readers.back().get();
     if (std::error_code EC = Reader->read())
-      exitWithErrorCode(EC, Filename);
+      exitWithError(EC.message(), Filename);
 
     StringMap<FunctionSamples> &Profiles = Reader->getProfiles();
     for (StringMap<FunctionSamples>::iterator I = Profiles.begin(),
 
     StringMap<FunctionSamples> &Profiles = Reader->getProfiles();
     for (StringMap<FunctionSamples>::iterator I = Profiles.begin(),
@@ -159,7 +143,7 @@ static int showInstrProfile(std::string Filename, bool ShowCounts,
                             std::string ShowFunction, raw_fd_ostream &OS) {
   auto ReaderOrErr = InstrProfReader::create(Filename);
   if (std::error_code EC = ReaderOrErr.getError())
                             std::string ShowFunction, raw_fd_ostream &OS) {
   auto ReaderOrErr = InstrProfReader::create(Filename);
   if (std::error_code EC = ReaderOrErr.getError())
-    exitWithErrorCode(EC, Filename);
+    exitWithError(EC.message(), Filename);
 
   auto Reader = std::move(ReaderOrErr.get());
   uint64_t MaxFunctionCount = 0, MaxBlockCount = 0;
 
   auto Reader = std::move(ReaderOrErr.get());
   uint64_t MaxFunctionCount = 0, MaxBlockCount = 0;
@@ -214,7 +198,7 @@ static int showInstrProfile(std::string Filename, bool ShowCounts,
     }
   }
   if (Reader->hasError())
     }
   }
   if (Reader->hasError())
-    exitWithErrorCode(Reader->getError(), Filename);
+    exitWithError(Reader->getError().message(), Filename);
 
   if (ShowAllFunctions || !ShowFunction.empty())
     OS << "Functions shown: " << ShownFunctions << "\n";
 
   if (ShowAllFunctions || !ShowFunction.empty())
     OS << "Functions shown: " << ShownFunctions << "\n";
@@ -230,11 +214,11 @@ static int showSampleProfile(std::string Filename, bool ShowCounts,
   using namespace sampleprof;
   auto ReaderOrErr = SampleProfileReader::create(Filename, getGlobalContext());
   if (std::error_code EC = ReaderOrErr.getError())
   using namespace sampleprof;
   auto ReaderOrErr = SampleProfileReader::create(Filename, getGlobalContext());
   if (std::error_code EC = ReaderOrErr.getError())
-    exitWithErrorCode(EC, Filename);
+    exitWithError(EC.message(), Filename);
 
   auto Reader = std::move(ReaderOrErr.get());
   if (std::error_code EC = Reader->read())
 
   auto Reader = std::move(ReaderOrErr.get());
   if (std::error_code EC = Reader->read())
-    exitWithErrorCode(EC, Filename);
+    exitWithError(EC.message(), Filename);
 
   if (ShowAllFunctions || ShowFunction.empty())
     Reader->dump(OS);
 
   if (ShowAllFunctions || ShowFunction.empty())
     Reader->dump(OS);
@@ -275,7 +259,7 @@ static int show_main(int argc, const char *argv[]) {
   std::error_code EC;
   raw_fd_ostream OS(OutputFilename.data(), EC, sys::fs::F_Text);
   if (EC)
   std::error_code EC;
   raw_fd_ostream OS(OutputFilename.data(), EC, sys::fs::F_Text);
   if (EC)
-      exitWithErrorCode(EC, OutputFilename);
+    exitWithError(EC.message(), OutputFilename);
 
   if (ShowAllFunctions && !ShowFunction.empty())
     errs() << "warning: -function argument ignored: showing all functions\n";
 
   if (ShowAllFunctions && !ShowFunction.empty())
     errs() << "warning: -function argument ignored: showing all functions\n";