tint: fix UB const-eval div by zero
Bug: oss-fuzz:56904 Change-Id: I2f47fcfa238b28e1148b0b36ccbe2166445964a1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/125380 Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
aff2b43596
commit
deb2ec9785
|
@ -335,8 +335,8 @@ function(common_compile_options TARGET)
|
|||
target_compile_options(${TARGET} PUBLIC -fsanitize=thread)
|
||||
target_link_options(${TARGET} PUBLIC -fsanitize=thread)
|
||||
elseif (${DAWN_ENABLE_UBSAN})
|
||||
target_compile_options(${TARGET} PUBLIC -fsanitize=undefined)
|
||||
target_link_options(${TARGET} PUBLIC -fsanitize=undefined)
|
||||
target_compile_options(${TARGET} PUBLIC -fsanitize=undefined -fsanitize=float-divide-by-zero)
|
||||
target_link_options(${TARGET} PUBLIC -fsanitize=undefined -fsanitize=float-divide-by-zero)
|
||||
endif()
|
||||
endif(COMPILER_IS_LIKE_GNU)
|
||||
|
||||
|
|
|
@ -539,6 +539,9 @@ inline std::optional<AInt> CheckedDiv(AInt a, AInt b) {
|
|||
/// @returns a / b, or an empty optional if the resulting value overflowed the float value
|
||||
template <typename FloatingPointT, typename = traits::EnableIf<IsFloatingPoint<FloatingPointT>>>
|
||||
inline std::optional<FloatingPointT> CheckedDiv(FloatingPointT a, FloatingPointT b) {
|
||||
if (b == FloatingPointT{0.0} || b == FloatingPointT{-0.0}) {
|
||||
return {};
|
||||
}
|
||||
auto result = FloatingPointT{a.value / b.value};
|
||||
if (!std::isfinite(result.value)) {
|
||||
return {};
|
||||
|
@ -576,6 +579,9 @@ inline std::optional<AInt> CheckedMod(AInt a, AInt b) {
|
|||
/// float value
|
||||
template <typename FloatingPointT, typename = traits::EnableIf<IsFloatingPoint<FloatingPointT>>>
|
||||
inline std::optional<FloatingPointT> CheckedMod(FloatingPointT a, FloatingPointT b) {
|
||||
if (b == FloatingPointT{0.0} || b == FloatingPointT{-0.0}) {
|
||||
return {};
|
||||
}
|
||||
auto result = FloatingPointT{detail::Mod(a.value, b.value)};
|
||||
if (!std::isfinite(result.value)) {
|
||||
return {};
|
||||
|
|
Loading…
Reference in New Issue