Skip to content

Commit 126e761

Browse files
committed
[compiler-rt] Fix diagnostic in InstrProfError
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
1 parent 1f01b31 commit 126e761

6 files changed

+38
-47
lines changed

llvm/lib/ProfileData/InstrProf.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static std::string getInstrProfErrString(instrprof_error Err,
147147

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

152152
return OS.str();
153153
}

llvm/lib/ProfileData/InstrProfReader.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -463,22 +463,21 @@ Error RawInstrProfReader<IntPtrT>::readRawCounts(
463463
if (CounterOffset < 0)
464464
return error(
465465
instrprof_error::malformed,
466-
("counter offset(" + Twine(CounterOffset) + ")" + " is < 0").str());
466+
("counter offset " + Twine(CounterOffset) + " is negative").str());
467467

468468
if (CounterOffset > MaxNumCounters)
469469
return error(instrprof_error::malformed,
470-
("counter offset(" + Twine(CounterOffset) + ")" + " > " +
471-
"max number of counters(" + Twine((uint32_t)MaxNumCounters) +
472-
")")
470+
("counter offset " + Twine(CounterOffset) +
471+
" is greater than the maximum number of counters " +
472+
Twine((uint32_t)MaxNumCounters))
473473
.str());
474474

475475
if (((uint32_t)CounterOffset + NumCounters) > (uint32_t)MaxNumCounters)
476476
return error(instrprof_error::malformed,
477-
("number of counters is out of bounds(counter offset(" +
478-
Twine((uint32_t)CounterOffset) + ") + " +
479-
"number of counters(" + Twine(NumCounters) + ") > " +
480-
"max number of counters(" + Twine((uint32_t)MaxNumCounters) +
481-
"))")
477+
("number of counters " +
478+
Twine(((uint32_t)CounterOffset + NumCounters)) +
479+
" is greater than the maximum number of counters " +
480+
Twine((uint32_t)MaxNumCounters))
482481
.str());
483482

484483
auto RawCounts = makeArrayRef(getCounter(CounterOffset), NumCounters);

llvm/test/tools/llvm-profdata/large-binary-id-size.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ RUN: printf '\0\1\2\3\4\5\6\7' >> %t.profraw
1717
RUN: printf '\0\1\2\3\0\0\0\0' >> %t.profraw
1818

1919
// RUN: not llvm-profdata show --binary-ids %t.profraw 2>&1 | FileCheck %s
20-
// CHECK: malformed instrumentation profile data: 'not enough data to read binary id data'
20+
// CHECK: malformed instrumentation profile data: not enough data to read binary id data

llvm/test/tools/llvm-profdata/malformed-not-space-for-another-header.test

+13-17
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
// INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
1212

1313
RUN: printf '\201rforpl\377' > %t.profraw
14-
RUN: printf '\x8\0\0\0\0\0\0\0' >> %t.profraw
14+
RUN: printf '\10\0\0\0\0\0\0\0' >> %t.profraw
1515
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
1616
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
1717
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
1818
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
1919
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
20-
RUN: printf '\xe\0\0\0\0\0\0\0' >> %t.profraw
21-
RUN: printf '\xf8\xff\xff\xff\xff\xff\xff\xff' >> %t.profraw
22-
RUN: printf '\x89\x7a\x40\x00\x00\x00\x00\x00' >> %t.profraw
23-
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
20+
RUN: printf '\10\0\0\0\0\0\0\0' >> %t.profraw
21+
RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
22+
RUN: printf '\0\0\4\0\2\0\0\0' >> %t.profraw
23+
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
2424

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

33-
RUN: printf '\xfa\xd5\x8d\xe7\x36\x64\x95\xdb' >> %t.profraw // NameRef
34-
RUN: printf '\x18\0\0\0\0\0\0\0' >> %t.profraw // FuncHash
35-
RUN: printf '\xf8\xff\xff\xff\xff\xff\xff\xff' >> %t.profraw // RelativeCounterPtr
36-
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw // FunctionPointer
37-
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw // Values
38-
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw // NumCounters and NumValueSites
39-
40-
// Counter section
33+
RUN: printf '\254\275\030\333\114\302\370\134' >> %t.profraw
34+
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
35+
RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
36+
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
37+
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
4138
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
4239

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

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

5046
RUN: not llvm-profdata show %t.profraw 2>&1 | FileCheck %s
51-
CHECK: malformed instrumentation profile data: 'not enough space for another header'
47+
CHECK: malformed instrumentation profile data: not enough space for another header

llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test

+14-18
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
// INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
1212

1313
RUN: printf '\201rforpl\377' > %t.profraw
14-
RUN: printf '\x8\0\0\0\0\0\0\0' >> %t.profraw
14+
RUN: printf '\10\0\0\0\0\0\0\0' >> %t.profraw
1515
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
1616
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
1717
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
1818
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
1919
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
20-
RUN: printf '\xe\0\0\0\0\0\0\0' >> %t.profraw
21-
RUN: printf '\xf8\xff\xff\xff\xff\xff\xff\xff' >> %t.profraw
22-
RUN: printf '\x89\x7a\x40\x00\x00\x00\x00\x00' >> %t.profraw
23-
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
20+
RUN: printf '\10\0\0\0\0\0\0\0' >> %t.profraw
21+
RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
22+
RUN: printf '\0\0\4\0\2\0\0\0' >> %t.profraw
23+
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
2424

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

33-
RUN: printf '\xfa\xd5\x8d\xe7\x36\x64\x95\xdb' >> %t.profraw // NameRef
34-
RUN: printf '\x18\0\0\0\0\0\0\0' >> %t.profraw // FuncHash
35-
RUN: printf '\xf8\xff\xff\xff\xff\xff\xff\xff' >> %t.profraw // RelativeCounterPtr
36-
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw // FunctionPointer
37-
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw // Values
38-
// Make NumCounters = 0 so that we get "number of counters is zero" error message
39-
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw // NumCounters and NumValueSites
40-
41-
// Counter section
33+
RUN: printf '\254\275\030\333\114\302\370\134' >> %t.profraw
4234
RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
35+
RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
36+
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
37+
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
38+
// Make NumCounters = 0 so that we get "number of counters is zero" error message
39+
RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
4340

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

4844
RUN: not llvm-profdata show %t.profraw 2>&1 | FileCheck %s
49-
CHECK: malformed instrumentation profile data: 'number of counters is zero'
45+
CHECK: malformed instrumentation profile data: number of counters is zero

llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ RUN: printf '\101\0\0\0\0\0\0\0' >> %t.profraw
5353
RUN: printf '\3\0bar\0\0\0' >> %t.profraw
5454

5555
RUN: not llvm-profdata merge -o /dev/null %t.profraw 2>&1 | FileCheck %s
56-
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))'
56+
CHECK: warning: {{.+}}: malformed instrumentation profile data: number of counters 3 is greater than the maximum number of counters 2
5757
CHECK: error: no profile can be merged

0 commit comments

Comments
 (0)