This revision was automatically updated to reflect the committed changes. Closed by commit rL316830: [analyzer] LoopUnrolling: check the bitwidth of the used numbers (pr34943) (authored by szepet).
Changed prior to commit: https://reviews.llvm.org/D38922?vs=119019&id=120733#toc Repository: rL LLVM https://reviews.llvm.org/D38922 Files: cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp cfe/trunk/test/Analysis/loop-unrolling.cpp Index: cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -208,9 +208,16 @@ return false; auto CounterVar = Matches[0].getNodeAs<VarDecl>("initVarName"); - auto BoundNum = Matches[0].getNodeAs<IntegerLiteral>("boundNum")->getValue(); - auto InitNum = Matches[0].getNodeAs<IntegerLiteral>("initNum")->getValue(); + llvm::APInt BoundNum = + Matches[0].getNodeAs<IntegerLiteral>("boundNum")->getValue(); + llvm::APInt InitNum = + Matches[0].getNodeAs<IntegerLiteral>("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs<BinaryOperator>("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: cfe/trunk/test/Analysis/loop-unrolling.cpp =================================================================== --- cfe/trunk/test/Analysis/loop-unrolling.cpp +++ cfe/trunk/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}} + } +}
Index: cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -208,9 +208,16 @@ return false; auto CounterVar = Matches[0].getNodeAs<VarDecl>("initVarName"); - auto BoundNum = Matches[0].getNodeAs<IntegerLiteral>("boundNum")->getValue(); - auto InitNum = Matches[0].getNodeAs<IntegerLiteral>("initNum")->getValue(); + llvm::APInt BoundNum = + Matches[0].getNodeAs<IntegerLiteral>("boundNum")->getValue(); + llvm::APInt InitNum = + Matches[0].getNodeAs<IntegerLiteral>("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs<BinaryOperator>("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: cfe/trunk/test/Analysis/loop-unrolling.cpp =================================================================== --- cfe/trunk/test/Analysis/loop-unrolling.cpp +++ cfe/trunk/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}} + } +}
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits