Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/plugins/intel_gpu/src/graph/common_utils/jit_term.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,16 @@ inline JitTerm operator/(const JitTerm& lhs, const JitTerm& rhs) {
return JitTerm{"(" + lhs.str() + " / " + rhs.str() + ")"};
}
inline JitTerm operator%(const JitTerm& lhs, const JitTerm& rhs) {
OPENVINO_ASSERT(rhs.str() != "0");
if (rhs.str() == "1" || rhs.str() == "-1") {
return JitTerm{"0"};
}

if (is_number(lhs) && is_number(rhs)) {
if (is_number(rhs)) {
auto rhs_val = as_number<int64_t>(rhs);
OPENVINO_ASSERT(rhs_val != 0, "Modulo by zero detected in operator%");
return JitTerm{std::to_string(as_number<int64_t>(lhs) % rhs_val)};
if (rhs_val == 1 || rhs_val == -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any overflow issue here, is this really not a false positive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get INT64_MIN % -1, the program first does INT64_MIN / -1, which gives +2^63. But that number is too big for an int64_t, so it overflows. We need to handle 1 and -1 anyway. Previously, we used strings for exceptions, but now it's changed to use numbers. Indeed, I don’t think this issue will actually happen, but Coverity still flags it as a problem.

return JitTerm{"0"};
}
if (is_number(lhs)) {
return JitTerm{std::to_string(as_number<int64_t>(lhs) % rhs_val)};
}
}

return JitTerm{"(" + lhs.str() + " % " + rhs.str() + ")"};
}
inline JitTerm operator++(JitTerm& t, int) {
Expand Down
Loading