diff --git a/vm_exec.h b/vm_exec.h index 34d3403453..7480a807da 100644 --- a/vm_exec.h +++ b/vm_exec.h @@ -11,6 +11,8 @@ **********************************************************************/ +#include "ruby/internal/has/attribute.h" + typedef long OFFSET; typedef unsigned long lindex_t; typedef VALUE GENTRY; @@ -60,18 +62,20 @@ error ! /************************************************/ #elif OPT_TAILCALL_THREADED_CODE -/* Same as __attribute__((musttail)), but slightly wider support (GCC 15) */ -#define MUSTTAIL [[clang::musttail]] +#if !RBIMPL_HAS_ATTRIBUTE(musttail) +#error support for musttail attribute is required for tailcall threading +#endif + +/* Declares that the function call MUST be tailcall optimized */ +#define MUSTTAIL __attribute__((musttail)) #define LABEL(x) insn_func_##x #define ELABEL(x) #define LABEL_PTR(x) &LABEL(x) -#if defined __has_attribute -#if __has_attribute (preserve_none) +#if RBIMPL_HAS_ATTRIBUTE(preserve_none) #define ATTR_PRESERVE_NONE __attribute__((preserve_none)) #endif -#endif #ifdef ATTR_PRESERVE_NONE #define INSN_FUNC_CONV ATTR_PRESERVE_NONE diff --git a/vm_opts.h b/vm_opts.h index 5f3dd4dd8a..56d08bb6c8 100644 --- a/vm_opts.h +++ b/vm_opts.h @@ -10,6 +10,8 @@ **********************************************************************/ +#include "ruby/internal/has/attribute.h" + /* Compile options. * You can change these options at runtime by VM::CompileOption. * Following definitions are default values. @@ -34,9 +36,13 @@ * 2: call (function call for each insn dispatch) * 3: call continuation (musttail attribute) */ -//#ifndef OPT_THREADED_CODE +#ifndef OPT_THREADED_CODE +#if RBIMPL_HAS_ATTRIBUTE(musttail) #define OPT_THREADED_CODE 3 -//#endif +#else +#define OPT_THREADED_CODE 0 +#endif +#endif #define OPT_DIRECT_THREADED_CODE (OPT_THREADED_CODE == 0) #define OPT_TOKEN_THREADED_CODE (OPT_THREADED_CODE == 1)