gemini-code-assist[bot] commented on code in PR #19607:
URL: https://github.com/apache/tvm/pull/19607#discussion_r3299905634
##########
src/relax/op/tensor/manipulate.cc:
##########
@@ -2043,7 +2043,7 @@ StructInfo InferStructInfoFlip(const Call& call, const
BlockBuilder& ctx) {
}
TensorStructInfo data_sinfo = GetUnaryInputTensorStructInfo(call, ctx);
const auto* attrs = call->attrs.as<FlipAttrs>();
- int axis = attrs->axis.IntValue();
+ int axis = static_cast<int>(attrs->axis.value());
Review Comment:

Since `FlipAttrs::axis` has been refactored to `ffi::Optional<int64_t>`,
calling `attrs->axis.value()` unconditionally is unsafe and will throw
`std::bad_optional_access` (or equivalent) if `axis` is `std::nullopt` (e.g.,
when flipping over all axes or if it is omitted). If `axis` is indeed optional,
please check `attrs->axis.has_value()` before accessing it, or provide a safe
fallback. If `axis` is mandatory, then `FlipAttrs::axis` should be defined as
`int64_t` instead of `ffi::Optional<int64_t>` to enforce its presence at
compile-time.
##########
src/relax/op/tensor/manipulate.cc:
##########
@@ -2073,7 +2073,7 @@ InferLayoutOutput InferLayoutFlip(
existing_layout = LayoutDecision(InitialLayout(ndim));
}
- int axis = attrs->axis.IntValue();
+ int axis = static_cast<int>(attrs->axis.value());
Review Comment:

Similar to the range check in `InferStructInfoFlip`, calling
`attrs->axis.value()` unconditionally here is unsafe if `axis` is
`std::nullopt`. Please ensure `attrs->axis.has_value()` is checked first, or
define `FlipAttrs::axis` as a non-optional `int64_t` if it is a mandatory
attribute.
--
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]