Index: lib/StaticAnalyzer/Core/LoopUnrolling.cpp =================================================================== --- lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -208,9 +208,16 @@ return false; auto CounterVar = Matches[0].getNodeAs("initVarName"); - auto BoundNum = Matches[0].getNodeAs("boundNum")->getValue(); - auto InitNum = Matches[0].getNodeAs("initNum")->getValue(); + llvm::APInt BoundNum = + Matches[0].getNodeAs("boundNum")->getValue(); + llvm::APInt InitNum = + Matches[0].getNodeAs("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs("conditionOperator"); + if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { + InitNum = InitNum.zextOrSelf(BoundNum.getBitWidth()); + BoundNum = BoundNum.zextOrSelf(InitNum.getBitWidth()); + } + if (CondOp->getOpcode() == BO_GE || CondOp->getOpcode() == BO_LE) maxStep = (BoundNum - InitNum + 1).abs().getZExtValue(); else Index: test/Analysis/loop-unrolling.cpp =================================================================== --- test/Analysis/loop-unrolling.cpp +++ test/Analysis/loop-unrolling.cpp @@ -373,3 +373,9 @@ return 0; } + +void pr34943() { + for (int i = 0; i < 6L; ++i) { + clang_analyzer_numTimesReached(); // expected-warning {{6}} + } +}