Skip to content

Commit

Permalink
[clang][dataflow] Avoid MaxIterations overflow
Browse files Browse the repository at this point in the history
unsigned is technically guaranteed to be only 16 bits in which case 1 << 16 would wrap around to zero.

Differential Revision: https://reviews.llvm.org/D117938
  • Loading branch information
jkorous-apple committed Jan 24, 2022
1 parent d0d8d2d commit dd01d97
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -210,8 +210,8 @@ runTypeErasedDataflowAnalysis(const ControlFlowContext &CFCtx,
// FIXME: Consider making the maximum number of iterations configurable.
// FIXME: Set up statistics (see llvm/ADT/Statistic.h) to count average number
// of iterations, number of functions that time out, etc.
unsigned Iterations = 0;
static constexpr unsigned MaxIterations = 1 << 16;
uint32_t Iterations = 0;
static constexpr uint32_t MaxIterations = 1 << 16;
while (const CFGBlock *Block = Worklist.dequeue()) {
if (++Iterations > MaxIterations) {
llvm::errs() << "Maximum number of iterations reached, giving up.\n";
Expand Down

0 comments on commit dd01d97

Please sign in to comment.