[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:05:25 PDT 2026


================
@@ -17,8 +18,17 @@ 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 '\0\0\0\0\0\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 '\0\0\0\0\0\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 '\0\0\0\0\0\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 '\0\0\0\0\0\0\0\0' >> %t.profraw
+// ^^ end of Profile Header ^^
+// Incomplete binary IDs data - only 7 bytes instead of 8
 RUN: printf '\0\0\0\0\0\0\0' >> %t.profraw
 
-// RUN: not llvm-profdata show --binary-ids  %t.profraw 2>&1 | FileCheck %s
-// CHECK: invalid instrumentation profile data (file header is corrupt)
+RUN: not llvm-profdata show --binary-ids  %t.profraw 2>&1 | FileCheck %s
+CHECK: invalid instrumentation profile data (file header is corrupt): BinaryIdSize (8) is not a multiple of 8 or the profile is truncated
----------------
w2yehia wrote:

I agree, it's better to have a new error type for when we have header/file size mismatch.
I created `instrprof_error::header_size_mismatch`. 

I checked all cases where we reported bad_header, and changed two places to the new error. I also checked all places where we report truncated profile, and we only report so for indexed profiles and text profiles which I think makes sense to keep as is: indexed profiles are created by the llvm-profdata tool which is less likely to produce a corrupt header, and text profiles have no headers. I also checked where we report instrprof_error::malformed and all report sites had descriptive message about the symptom.


https://github.com/llvm/llvm-project/pull/211281


More information about the llvm-commits mailing list