[profiling] Improve error message for raw profile header mismatches
authorJessica Paquette <jpaquette@apple.com>
Thu, 27 Apr 2023 17:32:36 +0000 (10:32 -0700)
committerJessica Paquette <jpaquette@apple.com>
Thu, 27 Apr 2023 21:51:38 +0000 (14:51 -0700)
commit17cfd2e025cb3aa929ad219c6ed0974d6198bf5b
treec6db1ce7931fdceaa6649e2e4981a368952cad91
parent43ba32109657b697c6dd31a30563a66dade5f254
[profiling] Improve error message for raw profile header mismatches

When a user uses a mismatched clang + llvm-profdata, they didn't get a very
informative error message. It would just say "unsupported version".

As a result, users are often confused as to what they are supposed to do and
tend to assume that it's a bug in the profiling runtime.

This patch improves the error message by:

- Adding a new class of error (`raw_profile_version_mismatch`) to make it clear
  that, specifically, the *raw profile* version is unsupported because of a
  tool mismatch.

- Adding an error message that tells the user which raw profile version was
  encountered, which version was expected, and instructs them to align their
  tool versions.

To support this, this patch also updates `InstrProfError::take` to also
propagate the optional error message.

Differential Revision: https://reviews.llvm.org/D149361
clang/lib/CodeGen/CodeGenPGO.cpp
llvm/include/llvm/ProfileData/InstrProf.h
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
llvm/lib/ProfileData/InstrProf.cpp
llvm/lib/ProfileData/InstrProfReader.cpp
llvm/test/tools/llvm-profdata/mismatched-raw-profile-header.test [new file with mode: 0644]
llvm/tools/llvm-profdata/llvm-profdata.cpp
llvm/unittests/ProfileData/InstrProfTest.cpp