From de666d7a4af24997b3c272cc6a59acca30da7685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20H=C3=B6ner?= Date: Fri, 5 May 2017 19:26:03 +0200 Subject: [PATCH] Improved handling of unreachable code --- include/Zydis/Defines.h | 15 +++++++++++++-- src/InstructionTable.c | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/Zydis/Defines.h b/include/Zydis/Defines.h index 5394549..f1c166e 100644 --- a/include/Zydis/Defines.h +++ b/include/Zydis/Defines.h @@ -114,11 +114,22 @@ #endif /* ============================================================================================== */ -/* Debugging macros */ +/* Debugging and optimization macros */ /* ============================================================================================== */ #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 */ diff --git a/src/InstructionTable.c b/src/InstructionTable.c index d41554d..f93825f 100644 --- a/src/InstructionTable.c +++ b/src/InstructionTable.c @@ -296,7 +296,7 @@ ZydisBool ZydisInstructionTableGetDefinition(const ZydisInstructionTableNode* no break; default: ZYDIS_UNREACHABLE; - return ZYDIS_FALSE; + //return ZYDIS_FALSE; } return ZYDIS_TRUE; }