[llvm] [Instrumentation] Fix EdgeCounts vector size in SetBranchWeights (PR #99064)

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 12 14:31:38 PDT 2024


================
@@ -1623,10 +1623,12 @@ void PGOUseFunc::setBranchWeights() {
       continue;
 
     // We have a non-zero Branch BB.
-    unsigned Size = BBCountInfo.OutEdges.size();
-    SmallVector<uint64_t, 2> EdgeCounts(Size, 0);
+    unsigned OutEdgesCount = BBCountInfo.OutEdges.size();
+    unsigned SuccessorCount = BB.getTerminator()->getNumSuccessors();
+
+    SmallVector<uint64_t, 2> EdgeCounts(SuccessorCount, 0);
----------------
mtrofin wrote:

(sorry for the delay, somehow I missed / got no notifications)

If the source you're observing the crash in is something you share (IIUC it is - earlier paste), could you do this, while in a debugger (assuming the unchanged, buggy code):

- get to the place where you observe the crash
- `p BB.getParent()->dump()`
- also `p BB.dump()`
- also `p Size` and `p s` for the failing `s`

Can you share those in a gist (less inlined stuff in the comments, easier to parse)? (Thanks!)

The first dumps the IR (intermediate representation) of the function that causes the problem. The latter, just the [basic block](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/BasicBlock.h#L47). A function's instructions are organized in a [control flow graph (CFG)](https://en.wikipedia.org/wiki/Control-flow_graph) where the nodes are basic blocks. The CFG is directed, and "successor" of a node X is a node Y for which there is an edge X->Y.

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


More information about the llvm-commits mailing list