From ef7d01971bb0fc9f118e7a0acdb152660e5240c9 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 19 Mar 2014 17:40:31 +0900 Subject: [PATCH] publish UNREACHABLE macro --- include/picrin.h | 7 +++++++ src/var.c | 6 ++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/picrin.h b/include/picrin.h index 6fbfec57..62c05775 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -56,6 +56,13 @@ extern "C" { # define GENSYM(x) GENSYM1__(x,__LINE__) #endif +#if __GNUC__ || __clang__ +# define UNREACHABLE() (__builtin_unreachable()) +#else +# include +# define UNREACHABLE() (assert(false)) +#endif + #include "config.h" #include "picrin/value.h" diff --git a/src/var.c b/src/var.c index 184e4666..b0d1f9f6 100644 --- a/src/var.c +++ b/src/var.c @@ -6,8 +6,6 @@ #include "picrin/proc.h" #include "picrin/var.h" -#define UNREACHABLE (assert(false)) - struct pic_var * pic_var_new(pic_state *pic, pic_value init, struct pic_proc *conv /* = NULL */) { @@ -67,7 +65,7 @@ get_var_from_proc(pic_state *pic, struct pic_proc *proc) typeerror: pic_error(pic, "expected parameter"); - UNREACHABLE; + UNREACHABLE(); } static pic_value @@ -94,7 +92,7 @@ var_call(pic_state *pic) else { pic_abort(pic, "logic flaw"); } - UNREACHABLE; + UNREACHABLE(); } struct pic_proc *