@@ -1102,17 +1102,35 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)
11021102 Py_RETURN_NONE ;
11031103}
11041104
1105- static PyObject *
1105+ // clang uses __attribute__((no_sanitize("undefined")))
1106+ // GCC 4.9+ uses __attribute__((no_sanitize_undefined))
1107+ #if defined(__has_feature ) // Clang
1108+ # if __has_feature (undefined_behavior_sanitizer )
1109+ # define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
1110+ # endif
1111+ #endif
1112+ #if defined(__GNUC__ ) \
1113+ && ((__GNUC__ >= 5 ) || (__GNUC__ == 4 ) && (__GNUC_MINOR__ >= 9 ))
1114+ # define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize_undefined))
1115+ #endif
1116+ #ifndef _Py_NO_SANITIZE_UNDEFINED
1117+ # define _Py_NO_SANITIZE_UNDEFINED
1118+ #endif
1119+
1120+ static PyObject * _Py_NO_SANITIZE_UNDEFINED
11061121faulthandler_sigfpe (PyObject * self , PyObject * args )
11071122{
1123+ faulthandler_suppress_crash_report ();
1124+
11081125 /* Do an integer division by zero: raise a SIGFPE on Intel CPU, but not on
11091126 PowerPC. Use volatile to disable compile-time optimizations. */
11101127 volatile int x = 1 , y = 0 , z ;
1111- faulthandler_suppress_crash_report ();
11121128 z = x / y ;
1129+
11131130 /* If the division by zero didn't raise a SIGFPE (e.g. on PowerPC),
11141131 raise it manually. */
11151132 raise (SIGFPE );
1133+
11161134 /* This line is never reached, but we pretend to make something with z
11171135 to silence a compiler warning. */
11181136 return PyLong_FromLong (z );
0 commit comments