Skip to content

Commit

Permalink
[compiler-rt] Fix diagnostic in InstrProfError
Browse files Browse the repository at this point in the history
This patch fixes some issues introduced in
https://reviews.llvm.org/D108942:

1) Remove the default label to fix the bots that use
-Werror,-Wcovered-switch-default
2) Modify the malformed test to fix the bots that are
built without zlib support
3) Modify some error messages in malformed profiles
  • Loading branch information
gulfemsavrun committed Nov 9, 2021
1 parent 1f01b31 commit 126e761
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 47 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/ProfileData/InstrProf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static std::string getInstrProfErrString(instrprof_error Err,

// If optional error message is not empty, append it to the message.
if (!ErrMsg.empty())
OS << ": '" << ErrMsg << "'";
OS << ": " << ErrMsg;

return OS.str();
}
Expand Down
17 changes: 8 additions & 9 deletions llvm/lib/ProfileData/InstrProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,22 +463,21 @@ Error RawInstrProfReader<IntPtrT>::readRawCounts(
if (CounterOffset < 0)
return error(
instrprof_error::malformed,
("counter offset(" + Twine(CounterOffset) + ")" + " is < 0").str());
("counter offset " + Twine(CounterOffset) + " is negative").str());

if (CounterOffset > MaxNumCounters)
return error(instrprof_error::malformed,
("counter offset(" + Twine(CounterOffset) + ")" + " > " +
"max number of counters(" + Twine((uint32_t)MaxNumCounters) +
")")
("counter offset " + Twine(CounterOffset) +
" is greater than the maximum number of counters " +
Twine((uint32_t)MaxNumCounters))
.str());

if (((uint32_t)CounterOffset + NumCounters) > (uint32_t)MaxNumCounters)
return error(instrprof_error::malformed,
("number of counters is out of bounds(counter offset(" +
Twine((uint32_t)CounterOffset) + ") + " +
"number of counters(" + Twine(NumCounters) + ") > " +
"max number of counters(" + Twine((uint32_t)MaxNumCounters) +
"))")
("number of counters " +
Twine(((uint32_t)CounterOffset + NumCounters)) +
" is greater than the maximum number of counters " +
Twine((uint32_t)MaxNumCounters))
.str());

auto RawCounts = makeArrayRef(getCounter(CounterOffset), NumCounters);
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-profdata/large-binary-id-size.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ RUN: printf '\0\1\2\3\4\5\6\7' >> %t.profraw
RUN: printf '\0\1\2\3\0\0\0\0' >> %t.profraw

// RUN: not llvm-profdata show --binary-ids %t.profraw 2>&1 | FileCheck %s
// CHECK: malformed instrumentation profile data: 'not enough data to read binary id data'
// CHECK: malformed instrumentation profile data: not enough data to read binary id data
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
// INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)

RUN: printf '\201rforpl\377' > %t.profraw
RUN: printf '\x8\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\10\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\xe\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\xf8\xff\xff\xff\xff\xff\xff\xff' >> %t.profraw
RUN: printf '\x89\x7a\x40\x00\x00\x00\x00\x00' >> %t.profraw
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\10\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
RUN: printf '\0\0\4\0\2\0\0\0' >> %t.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw

// Data Section
//
Expand All @@ -30,22 +30,18 @@ RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
// #include "llvm/ProfileData/InstrProfData.inc"
// };

RUN: printf '\xfa\xd5\x8d\xe7\x36\x64\x95\xdb' >> %t.profraw // NameRef
RUN: printf '\x18\0\0\0\0\0\0\0' >> %t.profraw // FuncHash
RUN: printf '\xf8\xff\xff\xff\xff\xff\xff\xff' >> %t.profraw // RelativeCounterPtr
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw // FunctionPointer
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw // Values
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw // NumCounters and NumValueSites

// Counter section
RUN: printf '\254\275\030\333\114\302\370\134' >> %t.profraw
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw

// Name section (Name section is 14 bytes and 2 bytes padding is added)
RUN: printf '\x04\x0c\x78\xda\xcb\x4d\xcc\xcc' >> %t.profraw
RUN: printf '\x03\x00\x04\x1b\x01\xa6\x00\x00' >> %t.profraw
RUN: printf '\023\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\3\0foo\0\0\0' >> %t.profraw

// Write some garbage data at the end so we get "not enough space for another header" message
RUN: printf '\x03\x00\' >> %t.profraw

RUN: not llvm-profdata show %t.profraw 2>&1 | FileCheck %s
CHECK: malformed instrumentation profile data: 'not enough space for another header'
CHECK: malformed instrumentation profile data: not enough space for another header
32 changes: 14 additions & 18 deletions llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
// INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)

RUN: printf '\201rforpl\377' > %t.profraw
RUN: printf '\x8\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\10\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\xe\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\xf8\xff\xff\xff\xff\xff\xff\xff' >> %t.profraw
RUN: printf '\x89\x7a\x40\x00\x00\x00\x00\x00' >> %t.profraw
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\10\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
RUN: printf '\0\0\4\0\2\0\0\0' >> %t.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw

// Data Section
//
Expand All @@ -30,20 +30,16 @@ RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
// #include "llvm/ProfileData/InstrProfData.inc"
// };

RUN: printf '\xfa\xd5\x8d\xe7\x36\x64\x95\xdb' >> %t.profraw // NameRef
RUN: printf '\x18\0\0\0\0\0\0\0' >> %t.profraw // FuncHash
RUN: printf '\xf8\xff\xff\xff\xff\xff\xff\xff' >> %t.profraw // RelativeCounterPtr
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw // FunctionPointer
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw // Values
// Make NumCounters = 0 so that we get "number of counters is zero" error message
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw // NumCounters and NumValueSites

// Counter section
RUN: printf '\254\275\030\333\114\302\370\134' >> %t.profraw
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
// Make NumCounters = 0 so that we get "number of counters is zero" error message
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw

// Name section (Name section is 14 bytes and 2 bytes padding is added)
RUN: printf '\x04\x0c\x78\xda\xcb\x4d\xcc\xcc' >> %t.profraw
RUN: printf '\x03\x00\x04\x1b\x01\xa6\x00\x00' >> %t.profraw
RUN: printf '\023\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\3\0foo\0\0\0' >> %t.profraw

RUN: not llvm-profdata show %t.profraw 2>&1 | FileCheck %s
CHECK: malformed instrumentation profile data: 'number of counters is zero'
CHECK: malformed instrumentation profile data: number of counters is zero
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ RUN: printf '\101\0\0\0\0\0\0\0' >> %t.profraw
RUN: printf '\3\0bar\0\0\0' >> %t.profraw

RUN: not llvm-profdata merge -o /dev/null %t.profraw 2>&1 | FileCheck %s
CHECK: warning: {{.+}}: malformed instrumentation profile data: 'number of counters is out of bounds(counter offset(1) + number of counters(2) > max number of counters(2))'
CHECK: warning: {{.+}}: malformed instrumentation profile data: number of counters 3 is greater than the maximum number of counters 2
CHECK: error: no profile can be merged

0 comments on commit 126e761

Please sign in to comment.