Improved handling of unreachable code

This commit is contained in:
Joel Höner 2017-05-05 19:26:03 +02:00
parent 40d6c39dbe
commit de666d7a4a
2 changed files with 14 additions and 3 deletions

View File

@ -114,11 +114,22 @@
#endif #endif
/* ============================================================================================== */ /* ============================================================================================== */
/* Debugging macros */ /* Debugging and optimization macros */
/* ============================================================================================== */ /* ============================================================================================== */
#define ZYDIS_ASSERT(condition) assert(condition) #define ZYDIS_ASSERT(condition) assert(condition)
#define ZYDIS_UNREACHABLE assert(0)
#if defined(ZYDIS_MSVC) && defined(ZYDIS_RELEASE)
# define ZYDIS_UNREACHABLE
#elif defined(ZYDIS_GNUC) && defined(ZYDIS_RELEASE)
# if __has_builtin(__builtin_unreachable)
# define ZYDIS_UNREACHABLE __builtin_unreachable()
# else
# define ZYDIS_UNREACHABLE
# endif
#else
# define ZYDIS_UNREACHABLE assert(0)
#endif
/* ============================================================================================== */ /* ============================================================================================== */
/* Utils */ /* Utils */

View File

@ -296,7 +296,7 @@ ZydisBool ZydisInstructionTableGetDefinition(const ZydisInstructionTableNode* no
break; break;
default: default:
ZYDIS_UNREACHABLE; ZYDIS_UNREACHABLE;
return ZYDIS_FALSE; //return ZYDIS_FALSE;
} }
return ZYDIS_TRUE; return ZYDIS_TRUE;
} }