Skip to content

Commit 2f6a70b

Browse files
cyyeverpytorchmergebot
authored andcommitted
Enable more UBSAN checks (pytorch#138288)
Fixes #ISSUE_NUMBER Pull Request resolved: pytorch#138288 Approved by: https://github.com/ezyang
1 parent 675e16e commit 2f6a70b

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

.ci/pytorch/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ fi
205205
if [[ "$BUILD_ENVIRONMENT" == *-clang*-asan* ]]; then
206206
export USE_CUDA=0
207207
export USE_ASAN=1
208-
export UBSAN_FLAGS="-fno-sanitize-recover=all;-fno-sanitize=float-divide-by-zero;-fno-sanitize=float-cast-overflow"
208+
export REL_WITH_DEB_INFO=1
209+
export UBSAN_FLAGS="-fno-sanitize-recover=all"
209210
unset USE_LLVM
210211
fi
211212

aten/src/ATen/native/Math.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <ATen/AccumulateType.h>
44
#include <ATen/NumericUtils.h>
55
#include <ATen/jiterator_macros.h>
6+
#include <c10/macros/Macros.h>
67
#include <c10/util/BFloat16.h>
78
#include <c10/util/Half.h>
89
#include <c10/util/MathConstants.h>
@@ -3071,14 +3072,14 @@ inline C10_HOST_DEVICE T hermite_polynomial_h_forward(T x, int64_t n) {
30713072
return r;
30723073
} // hermite_polynomial_h_forward(T x, int64_t n)
30733074

3074-
template<typename T, bool is_cuda=false, std::enable_if_t<!std::is_floating_point<T>::value, int> = 0>
3075+
template<typename T, bool is_cuda=false, std::enable_if_t<!std::is_floating_point_v<T>, int> = 0>
30753076
inline C10_HOST_DEVICE T hermite_polynomial_h_forward(T x, T n) {
30763077
return hermite_polynomial_h_forward(x, static_cast<int64_t>(n));
30773078
} // hermite_polynomial_h_forward(T x, T n)
30783079

3079-
template<typename T, bool is_cuda=false, std::enable_if_t<std::is_floating_point<T>::value, int> = 0>
3080-
inline C10_HOST_DEVICE T hermite_polynomial_h_forward(T x, T n) {
3081-
return hermite_polynomial_h_forward(x, ((!std::isinf(n)) && (!std::isnan(n))) ? static_cast<int64_t>(n) : static_cast<int64_t>(-1));
3080+
template<typename T, bool is_cuda=false, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>
3081+
__ubsan_ignore_float_cast_overflow__ inline C10_HOST_DEVICE T hermite_polynomial_h_forward(T x, T n) {
3082+
return hermite_polynomial_h_forward(x, (!std::isinf(n) && !std::isnan(n)) ? static_cast<int64_t>(n) : static_cast<int64_t>(-1));
30823083
} // hermite_polynomial_h_forward(T x, T n)
30833084

30843085
template<typename T>

c10/macros/Macros.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@
3333
#define __ubsan_ignore_pointer_overflow__ \
3434
__attribute__((no_sanitize("pointer-overflow")))
3535
#define __ubsan_ignore_function__ __attribute__((no_sanitize("function")))
36+
#define __ubsan_ignore_float_cast_overflow__ \
37+
__attribute__((no_sanitize("float-cast-overflow")))
3638
#else
3739
#define __ubsan_ignore_float_divide_by_zero__
3840
#define __ubsan_ignore_undefined__
3941
#define __ubsan_ignore_signed_int_overflow__
4042
#define __ubsan_ignore_pointer_overflow__
4143
#define __ubsan_ignore_function__
44+
#define __ubsan_ignore_float_cast_overflow__
4245
#endif
4346

4447
// Detect address sanitizer as some stuff doesn't work with it

0 commit comments

Comments
 (0)