[llvm] r207172 - ProfileData: Treat missing function counts as malformed
Justin Bogner
mail at justinbogner.com
Thu Apr 24 19:45:34 PDT 2014
Author: bogner
Date: Thu Apr 24 21:45:33 2014
New Revision: 207172
URL: http://llvm.org/viewvc/llvm-project?rev=207172&view=rev
Log:
ProfileData: Treat missing function counts as malformed
Added:
llvm/trunk/test/tools/llvm-profdata/Inputs/no-counts.profdata
Modified:
llvm/trunk/lib/ProfileData/InstrProfReader.cpp
llvm/trunk/test/tools/llvm-profdata/errors.test
llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp
Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=207172&r1=207171&r2=207172&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Thu Apr 24 21:45:33 2014
@@ -101,6 +101,8 @@ error_code TextInstrProfReader::readNext
return error(instrprof_error::truncated);
if ((Line++)->getAsInteger(10, NumCounters))
return error(instrprof_error::malformed);
+ if (NumCounters == 0)
+ return error(instrprof_error::malformed);
// Read each counter and fill our internal storage with the values.
Counts.clear();
@@ -210,8 +212,10 @@ RawInstrProfReader<IntPtrT>::readNextRec
// Get the raw data.
StringRef RawName(getName(Data->NamePtr), swap(Data->NameSize));
- auto RawCounts = makeArrayRef(getCounter(Data->CounterPtr),
- swap(Data->NumCounters));
+ uint32_t NumCounters = swap(Data->NumCounters);
+ if (NumCounters == 0)
+ return error(instrprof_error::malformed);
+ auto RawCounts = makeArrayRef(getCounter(Data->CounterPtr), NumCounters);
// Check bounds.
auto *NamesStartAsCounter = reinterpret_cast<const uint64_t *>(NamesStart);
Added: llvm/trunk/test/tools/llvm-profdata/Inputs/no-counts.profdata
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/no-counts.profdata?rev=207172&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/Inputs/no-counts.profdata (added)
+++ llvm/trunk/test/tools/llvm-profdata/Inputs/no-counts.profdata Thu Apr 24 21:45:33 2014
@@ -0,0 +1,3 @@
+no_counts
+0
+0
Modified: llvm/trunk/test/tools/llvm-profdata/errors.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/errors.test?rev=207172&r1=207171&r2=207172&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/errors.test (original)
+++ llvm/trunk/test/tools/llvm-profdata/errors.test Thu Apr 24 21:45:33 2014
@@ -11,3 +11,6 @@ INVALID-COUNT-LATER: error: {{.*}}invali
RUN: not llvm-profdata show %p/Inputs/bad-hash.profdata 2>&1 | FileCheck %s --check-prefix=BAD-HASH
RUN: not llvm-profdata merge %p/Inputs/bad-hash.profdata %p/Inputs/bad-hash.profdata -o %t.out 2>&1 | FileCheck %s --check-prefix=BAD-HASH
BAD-HASH: error: {{.*}}bad-hash.profdata: Malformed profile data
+
+RUN: not llvm-profdata show %p/Inputs/no-counts.profdata 2>&1 | FileCheck %s --check-prefix=NO-COUNTS
+NO-COUNTS: error: {{.*}}no-counts.profdata: Malformed profile data
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=207172&r1=207171&r2=207172&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp (original)
+++ llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp Thu Apr 24 21:45:33 2014
@@ -111,6 +111,7 @@ int show_main(int argc, const char *argv
Func.Name.find(ShowFunction) != Func.Name.npos);
++TotalFunctions;
+ assert(Func.Counts.size() > 0 && "function missing entry counter");
if (Func.Counts[0] > MaxFunctionCount)
MaxFunctionCount = Func.Counts[0];
More information about the llvm-commits
mailing list