[llvm] [MemProf] Fix assert when exists direct recursion (PR #78264)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 07:39:37 PST 2024


================
@@ -3470,17 +3470,19 @@ bool MemProfContextDisambiguation::applyImport(Module &M) {
             auto *MIBMD = cast<const MDNode>(MDOp);
             MDNode *StackMDNode = getMIBStackNode(MIBMD);
             assert(StackMDNode);
-            SmallVector<unsigned> StackIdsFromMetadata;
             CallStack<MDNode, MDNode::op_iterator> StackContext(StackMDNode);
-            for (auto ContextIter =
-                     StackContext.beginAfterSharedPrefix(CallsiteContext);
+            auto ContextIterBegin =
+                StackContext.beginAfterSharedPrefix(CallsiteContext);
+            // Skip the checking on the first iteration.
+            uint64_t LastStackContextId = *ContextIterBegin == 0 ? 1 : 0;
----------------
lifengxiang1025 wrote:

I think ContextIter should't at StackContext.end() because we already have assert `assert(AI != FS->allocs().end());`. How about adding one more assert `assert(ContextIterBegin != StackContext.end());`? https://github.com/llvm/llvm-project/pull/81004

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


More information about the llvm-commits mailing list