diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 792373839107f..0331ff83e633f 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -310,7 +310,7 @@ struct MapRegionCounters : public RecursiveASTVisitor { } // Otherwise, allocate the Decision. - MCDCState.DecisionByStmt[BinOp].BitmapIdx = 0; + MCDCState.DecisionByStmt[BinOp].ID = MCDCState.DecisionByStmt.size(); } return true; } diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index f09157771d2b5..4dbc0c70e34d6 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -2197,10 +2197,8 @@ struct CounterCoverageMappingBuilder // Update the state for CodeGenPGO assert(MCDCState.DecisionByStmt.contains(E)); - MCDCState.DecisionByStmt[E] = { - MCDCState.BitmapBits, // Top - std::move(Builder.Indices), - }; + MCDCState.DecisionByStmt[E].update(MCDCState.BitmapBits, // Top + std::move(Builder.Indices)); auto DecisionParams = mcdc::DecisionParameters{ MCDCState.BitmapBits += NumTVs, // Tail diff --git a/clang/lib/CodeGen/MCDCState.h b/clang/lib/CodeGen/MCDCState.h index e0dd28ff90ed1..4b89ddd12d672 100644 --- a/clang/lib/CodeGen/MCDCState.h +++ b/clang/lib/CodeGen/MCDCState.h @@ -16,6 +16,8 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ProfileData/Coverage/MCDCTypes.h" +#include +#include namespace clang { class Stmt; @@ -30,8 +32,20 @@ struct State { unsigned BitmapBits = 0; struct Decision { + using IndicesTy = llvm::SmallVector>; + static constexpr auto InvalidID = std::numeric_limits::max(); + unsigned BitmapIdx; - llvm::SmallVector> Indices; + IndicesTy Indices; + unsigned ID = InvalidID; + + bool isValid() const { return ID != InvalidID; } + + void update(unsigned I, IndicesTy &&X) { + assert(isValid()); + BitmapIdx = I; + Indices = std::move(X); + } }; llvm::DenseMap DecisionByStmt;