diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp --- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp +++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp @@ -842,12 +842,12 @@ FunctionProfile.addHeadSamples(Count); // Look up for the caller's function profile const auto *InlinerDesc = Binary->getInlinerDescForProbe(Probe); - if (InlinerDesc != nullptr) { + SampleContextFrames CalleeContextId = + FunctionProfile.getContext().getContextFrames(); + if (InlinerDesc != nullptr && CalleeContextId.size() > 1) { // Since the context id will be compressed, we have to use callee's // context id to infer caller's context id to ensure they share the // same context prefix. - SampleContextFrames CalleeContextId = - FunctionProfile.getContext().getContextFrames(); SampleContextFrameVector CallerContextId; SampleContextFrame &&CallerLeafFrameLoc = getCallerContext(CalleeContextId, CallerContextId); diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h --- a/llvm/tools/llvm-profgen/ProfiledBinary.h +++ b/llvm/tools/llvm-profgen/ProfiledBinary.h @@ -476,7 +476,13 @@ SmallVector ProbeInlineContext; ProbeDecoder.getInlineContextForProbe(Probe, ProbeInlineContext, IncludeLeaf); - for (auto &Callsite : ProbeInlineContext) { + for (uint32_t I = 0; I < ProbeInlineContext.size(); I++) { + auto &Callsite = ProbeInlineContext[I]; + // Clear the current context for an unknown probe. + if (Callsite.second == 0 && I != ProbeInlineContext.size() - 1) { + InlineContextStack.clear(); + continue; + } InlineContextStack.emplace_back(Callsite.first, LineLocation(Callsite.second, 0)); }