@@ -1102,17 +1102,35 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)
1102
1102
Py_RETURN_NONE ;
1103
1103
}
1104
1104
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
1106
1121
faulthandler_sigfpe (PyObject * self , PyObject * args )
1107
1122
{
1123
+ faulthandler_suppress_crash_report ();
1124
+
1108
1125
/* Do an integer division by zero: raise a SIGFPE on Intel CPU, but not on
1109
1126
PowerPC. Use volatile to disable compile-time optimizations. */
1110
1127
volatile int x = 1 , y = 0 , z ;
1111
- faulthandler_suppress_crash_report ();
1112
1128
z = x / y ;
1129
+
1113
1130
/* If the division by zero didn't raise a SIGFPE (e.g. on PowerPC),
1114
1131
raise it manually. */
1115
1132
raise (SIGFPE );
1133
+
1116
1134
/* This line is never reached, but we pretend to make something with z
1117
1135
to silence a compiler warning. */
1118
1136
return PyLong_FromLong (z );
0 commit comments