Skip to content

Commit

Permalink
Fix Clang ASAN issue by handling float to integer overflow in convert…
Browse files Browse the repository at this point in the history
… operator (ROCm#3071)
  • Loading branch information
nives-vukovic authored and lajagapp committed Jul 8, 2024
1 parent 99f2260 commit 32ca32b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/include/migraphx/op/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ struct convert : unary<convert>
{
y = as.nan();
}
else if(shape::is_integral(type) and std::is_floating_point_v<decltype(x)>)
{
// for the floating point to integer conversion, clamp first and then convert to
// avoid undefined behaviour
y = as(std::min(std::max(static_cast<double>(x), static_cast<double>(as.min())),
static_cast<double>(as.max())));
}
else
{
// clamp overflowing/underflowing values to min()/max() instead of +/-infinity
Expand Down
3 changes: 1 addition & 2 deletions test/verify/test_max_pooling_ceil_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ struct test_max_pooling_ceil_3d : verify_program<test_max_pooling_ceil_3d<T>>
};

template struct test_max_pooling_ceil_3d<migraphx::shape::float_type>;
// TODO: uncomment once "Clang ASAN" CI is fixed. See PR 2973 for details
// template struct test_max_pooling_ceil_3d<migraphx::shape::uint8_type>;
template struct test_max_pooling_ceil_3d<migraphx::shape::uint8_type>;

0 comments on commit 32ca32b

Please sign in to comment.