Skip to content

Commit

Permalink
[Instrumentation] Fix EdgeCounts vector size in SetBranchWeights
Browse files Browse the repository at this point in the history
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 llvm#97962
  • Loading branch information
avikivity committed Jul 16, 2024
1 parent 986ceae commit eae8cec
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,9 @@ void PGOUseFunc::setBranchWeights() {

// We have a non-zero Branch BB.
unsigned Size = BBCountInfo.OutEdges.size();
SmallVector<uint64_t, 2> EdgeCounts(Size, 0);
unsigned SuccessorCount = BB.getTerminator()->getNumSuccessors();

SmallVector<uint64_t, 2> EdgeCounts(SuccessorCount, 0);
uint64_t MaxCount = 0;
for (unsigned s = 0; s < Size; s++) {
const PGOUseEdge *E = BBCountInfo.OutEdges[s];
Expand Down

0 comments on commit eae8cec

Please sign in to comment.