diff --git a/llvm/lib/ProfileData/MemProfReader.cpp b/llvm/lib/ProfileData/MemProfReader.cpp index 16502a4f1e8af..c57f9b22273d4 100644 --- a/llvm/lib/ProfileData/MemProfReader.cpp +++ b/llvm/lib/ProfileData/MemProfReader.cpp @@ -444,7 +444,11 @@ Error RawMemProfReader::setupForSymbolization() { ProfiledTextSegmentEnd = Entry.End; } } - assert(NumMatched != 0 && "No matching executable segments in segment info."); + if (NumMatched == 0) + return make_error( + Twine("No matching executable segments found in binary ") + + Binary.getBinary()->getFileName(), + inconvertibleErrorCode()); assert((PreferredTextSegmentAddress == 0 || (PreferredTextSegmentAddress == ProfiledTextSegmentStart)) && "Expect text segment address to be 0 or equal to profiled text " diff --git a/llvm/test/tools/llvm-profdata/memprof-buildid.test b/llvm/test/tools/llvm-profdata/memprof-buildid.test index a5abe6ea7dcb6..75c3da2506796 100644 --- a/llvm/test/tools/llvm-profdata/memprof-buildid.test +++ b/llvm/test/tools/llvm-profdata/memprof-buildid.test @@ -14,3 +14,9 @@ CHECK: Build ID: [[ID:[[:xdigit:]]+]] COM: Then match it with the profdata output. CHECK-COUNT-1: BuildId: {{.*}}[[ID]] + +Test error message when profile build id does not match build id in a different binary. +RUN: not llvm-profdata show --memory %p/Inputs/buildid.memprofraw --profiled-binary %p/Inputs/basic.memprofexe -o - 2>&1 | FileCheck %s -check-prefix=BUILDID-NOT-MATCH +RUN: not llvm-profdata merge %p/Inputs/buildid.memprofraw %p/Inputs/basic.memprofraw --profiled-binary %p/Inputs/basic.memprofexe -o %t4.prof 2>&1 | FileCheck %s -check-prefix=BUILDID-NOT-MATCH + +BUILDID-NOT-MATCH: No matching executable segments found in binary