[llvm] [Profile] Add a more descriptive message to the bad_header error (PR #211281)
Wael Yehia via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 12 21:06:32 PDT 2026
================
@@ -589,15 +590,23 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
"\nPLEASE update this tool to version in the raw profile, or "
"regenerate raw profile with expected version.")
.str());
-
+ const uint8_t *ProfileStart = reinterpret_cast<const uint8_t *>(&Header);
uint64_t BinaryIdSize = swap(Header.BinaryIdsSize);
// Binary id start just after the header if exists.
- const uint8_t *BinaryIdStart =
- reinterpret_cast<const uint8_t *>(&Header) + sizeof(RawInstrProf::Header);
+ const uint8_t *BinaryIdStart = ProfileStart + sizeof(RawInstrProf::Header);
const uint8_t *BinaryIdEnd = BinaryIdStart + BinaryIdSize;
const uint8_t *BufferEnd = (const uint8_t *)DataBuffer->getBufferEnd();
- if (BinaryIdSize % sizeof(uint64_t) || BinaryIdEnd > BufferEnd)
- return error(instrprof_error::bad_header);
+ if (BinaryIdSize % sizeof(uint64_t))
+ return error(
+ instrprof_error::bad_header,
+ ("BinaryIdSize (" + Twine(BinaryIdSize) + ") is not a multiple of 8")
+ .str());
+ if (BinaryIdEnd > BufferEnd)
+ return error(instrprof_error::header_size_mismatch,
+ ("Header.BinaryIdSize = " + Twine(BinaryIdSize) +
+ " bytes, Incomplete binary IDs data")
+ .str());
----------------
w2yehia wrote:
good suggestion, done.
https://github.com/llvm/llvm-project/pull/211281
More information about the llvm-commits
mailing list