diff --git a/llvm/lib/Transforms/IPO/SampleContextTracker.cpp b/llvm/lib/Transforms/IPO/SampleContextTracker.cpp --- a/llvm/lib/Transforms/IPO/SampleContextTracker.cpp +++ b/llvm/lib/Transforms/IPO/SampleContextTracker.cpp @@ -542,8 +542,11 @@ } else { // Destination node exists, merge samples for the context tree mergeContextNode(FromNode, *ToNode, ContextStrToRemove); - LLVM_DEBUG(dbgs() << " Context promoted and merged to: " - << ToNode->getFunctionSamples()->getContext() << "\n"); + LLVM_DEBUG({ + if (ToNode->getFunctionSamples()) + dbgs() << " Context promoted and merged to: " + << ToNode->getFunctionSamples()->getContext() << "\n"; + }); // Recursively promote and merge children for (auto &It : FromNode.getAllChildContext()) {