Skip to content

Commit eae8cec

Browse files
committed
[Instrumentation] Fix EdgeCounts vector size in SetBranchWeights
SetBranchWeights() calculates the size of the EdgeCounts vector using OutEdges.Size(), but this is an under-estimate with coroutines. Use the number of successors, as the vector will be indexed by the result of the GetSuccessorNumber() function. This crashes in 18.1, but somehow doesn't in main. Still, it looks like the fix is applicable to both. Fixes #97962
1 parent 986ceae commit eae8cec

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,9 @@ void PGOUseFunc::setBranchWeights() {
16241624

16251625
// We have a non-zero Branch BB.
16261626
unsigned Size = BBCountInfo.OutEdges.size();
1627-
SmallVector<uint64_t, 2> EdgeCounts(Size, 0);
1627+
unsigned SuccessorCount = BB.getTerminator()->getNumSuccessors();
1628+
1629+
SmallVector<uint64_t, 2> EdgeCounts(SuccessorCount, 0);
16281630
uint64_t MaxCount = 0;
16291631
for (unsigned s = 0; s < Size; s++) {
16301632
const PGOUseEdge *E = BBCountInfo.OutEdges[s];

0 commit comments

Comments
 (0)