diff -r 5d5b72a71898 Include/pyport.h --- a/Include/pyport.h Tue Apr 24 14:44:18 2012 -0400 +++ b/Include/pyport.h Tue Apr 24 15:10:30 2012 -0400 @@ -834,16 +834,26 @@ extern pid_t forkpty(int *, char *, stru * Specify alignment on compilers that support it. */ #if defined(__GNUC__) && __GNUC__ >= 3 #define Py_ALIGNED(x) __attribute__((aligned(x))) #else #define Py_ALIGNED(x) #endif +#ifdef NDEBUG +#ifdef __GNUC__ +#define Py_UNREACHABLE __builtin_unreachable() +#else +#define Py_UNREACHABLE Py_FatalError("reached unreachable code\n") +#endif +#else +#define Py_UNREACHABLE assert(0) +#endif + /* Eliminate end-of-loop code not reached warnings from SunPro C * when using do{...}while(0) macros */ #ifdef __SUNPRO_C #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED) #endif /* diff -r 5d5b72a71898 Objects/dictobject.c --- a/Objects/dictobject.c Tue Apr 24 14:44:18 2012 -0400 +++ b/Objects/dictobject.c Tue Apr 24 15:10:30 2012 -0400 @@ -510,18 +510,17 @@ lookdict(PyDictObject *mp, PyObject *key PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during lookup"); return NULL; } } else if (ep->me_key == dummy && freeslot == NULL) freeslot = ep; } - assert(0); /* NOT REACHED */ - return 0; + Py_UNREACHABLE; } /* Specialized version for string-only keys */ static PyDictKeyEntry * lookdict_unicode(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject ***value_addr) { register size_t i; diff -r 5d5b72a71898 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Tue Apr 24 14:44:18 2012 -0400 +++ b/Objects/unicodeobject.c Tue Apr 24 15:10:30 2012 -0400 @@ -626,20 +626,18 @@ Py_LOCAL_INLINE(Py_ssize_t) findchar(voi Py_UCS2 ch2 = (Py_UCS2) ch; if (ch2 == ch) return ucs2lib_fastsearch((Py_UCS2 *) s, size, &ch2, 1, 0, mode); else return -1; } case PyUnicode_4BYTE_KIND: return ucs4lib_fastsearch((Py_UCS4 *) s, size, &ch, 1, 0, mode); - default: - assert(0); - return -1; - } + } + Py_UNREACHABLE; } static PyObject* resize_compact(PyObject *unicode, Py_ssize_t length) { Py_ssize_t char_size; Py_ssize_t struct_size; Py_ssize_t new_size; @@ -1981,18 +1979,17 @@ Py_UCS4 switch(kind) { case PyUnicode_1BYTE_KIND: return ucs1lib_find_max_char(startptr, endptr); case PyUnicode_2BYTE_KIND: return ucs2lib_find_max_char(startptr, endptr); case PyUnicode_4BYTE_KIND: return ucs4lib_find_max_char(startptr, endptr); default: - assert(0); - return 0; + Py_UNREACHABLE; } } /* Ensure that a string uses the most efficient storage, if it is not the case: create a new string with of the right kind. Write NULL into *p_unicode on error. */ static void unicode_adjust_maxchar(PyObject **p_unicode)