[llvm] d9b92c4 - [Coverity] Improper use of negtive value.

via llvm-commits llvm-commits at lists.llvm.org
Thu May 4 06:12:00 PDT 2023


Author: Luo, Yuanke
Date: 2023-05-04T21:11:49+08:00
New Revision: d9b92c4d559732e953a7339273f53a89e92d3655

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

LOG: [Coverity] Improper use of negtive value.

The `Iteration` value may be -1 which would cause incorrect loop count
when pass the value to buildSqrtNROneConst or buildSqrtNRTwoConst.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 8a6c9b53b9b6..392890afef64 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -26701,7 +26701,7 @@ SDValue DAGCombiner::buildSqrtEstimateImpl(SDValue Op, SDNodeFlags Flags,
                           Reciprocal)) {
     AddToWorklist(Est.getNode());
 
-    if (Iterations)
+    if (Iterations > 0)
       Est = UseOneConstNR
             ? buildSqrtNROneConst(Op, Est, Iterations, Flags, Reciprocal)
             : buildSqrtNRTwoConst(Op, Est, Iterations, Flags, Reciprocal);


        


More information about the llvm-commits mailing list