[clang] dd01d97 - [clang][dataflow] Avoid MaxIterations overflow

Jan Korous via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 24 15:58:48 PST 2022


Author: Jan Korous
Date: 2022-01-24T15:58:38-08:00
New Revision: dd01d971aa2c4b464a295ca5c78ff93fc4441dc3

URL: https://github.com/llvm/llvm-project/commit/dd01d971aa2c4b464a295ca5c78ff93fc4441dc3
DIFF: https://github.com/llvm/llvm-project/commit/dd01d971aa2c4b464a295ca5c78ff93fc4441dc3.diff

LOG: [clang][dataflow] Avoid MaxIterations overflow

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

Added: 
    

Modified: 
    clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 3782f0f5f69ac..7611395cafb6b 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -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";


        


More information about the cfe-commits mailing list