gemini-code-assist[bot] commented on code in PR #19669:
URL: https://github.com/apache/tvm/pull/19669#discussion_r3352658440


##########
src/arith/canonical_simplify.cc:
##########
@@ -1419,10 +1419,17 @@ PrimExpr CanonicalSimplifier::Impl::VisitExpr_(const 
LTNode* op) {
       // Case 1. 0 <= xn < d
       divisible.CopyOnWrite()->DivideBy(gcd);
       return Rewriter::VisitExpr(divisible->Normalize() < make_zero(dtype));
-    } else if (extra->args.size() == 1 &&
+    } else if (extra->args.size() == 1 && extra->args[0]->scale == 1 &&
                extra->args[0]->upper_factor != ConstIntBoundNode::kPosInf &&
                extra->args[0]->upper_factor % (gcd * 
extra->args[0]->lower_factor) == 0) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   To prevent potential signed integer overflow (which is undefined behavior in 
C++), we should defensively check that the multiplication `gcd * 
extra->args[0]->lower_factor` does not overflow 
`std::numeric_limits<int64_t>::max()` before performing the multiplication and 
modulo operation.
   
   ```c
       } else if (extra->args.size() == 1 && extra->args[0]->scale == 1 &&\n    
           extra->args[0]->upper_factor != ConstIntBoundNode::kPosInf &&\n      
         extra->args[0]->lower_factor <= std::numeric_limits<int64_t>::max() / 
gcd &&\n               extra->args[0]->upper_factor % (gcd * 
extra->args[0]->lower_factor) == 0) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to