zxybazh commented on code in PR #14347:
URL: https://github.com/apache/tvm/pull/14347#discussion_r1142799742


##########
src/tir/transforms/lower_tvm_builtin.cc:
##########
@@ -239,8 +239,9 @@ class BuiltinLower : public StmtExprMutator {
         }
       }
     }
-    PrimExpr total_bytes = make_const(op->extents[0].dtype(), nbytes);
+    PrimExpr total_bytes = make_const(DataType::UInt(64), nbytes);
     for (size_t i = 0; i < op->extents.size(); ++i) {
+      // set total_bytes to uint64 to avoid overflow

Review Comment:
   I think technically it's possible to allocate 2G of memory and also possible 
to have an intermediate large result between passes. On the other hand each 
loop extent are supposed to be positive so unless overflow it's unlikely to 
produce any negative results. I also tried locally to multiply uint64 with 
negative int32, turns out it will trigger an error. Therefore I think we are 
good with current change here.



-- 
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]

Reply via email to