Ruby: include/ruby/internal/has/attribute.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

attribute.h
Go to the documentation of this file.
1#ifndef RBIMPL_HAS_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_HAS_ATTRIBUTE_H
23#include "ruby/internal/config.h"
24#include "ruby/internal/compiler_since.h"
25#include "ruby/internal/token_paste.h"
26
27#if defined(__has_attribute)
28# if __has_attribute(pure) || RBIMPL_COMPILER_IS(GCC)
29# /* FreeBSD's <sys/cdefs.h> defines its own *broken* version of
30# * __has_attribute. Cygwin copied that content to be a victim of the
31# * broken-ness. We don't take them into account. */
32# define RBIMPL_HAVE___HAS_ATTRIBUTE 1
33# endif
34#endif
35
37#if defined(RBIMPL_HAVE___HAS_ATTRIBUTE)
38# define RBIMPL_HAS_ATTRIBUTE(_) __has_attribute(_)
39
40#elif RBIMPL_COMPILER_IS(GCC)
41# /* GCC <= 4 lack __has_attribute predefined macro, while have attributes
42# * themselves. We can simulate the macro like the following: */
43# define RBIMPL_HAS_ATTRIBUTE(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_ATTRIBUTE_, _)
44# define RBIMPL_HAS_ATTRIBUTE_aligned RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
45# define RBIMPL_HAS_ATTRIBUTE_alloc_size RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0)
46# define RBIMPL_HAS_ATTRIBUTE_artificial RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0)
47# define RBIMPL_HAS_ATTRIBUTE_always_inline RBIMPL_COMPILER_SINCE(GCC, 3, 1, 0)
48# define RBIMPL_HAS_ATTRIBUTE_cdecl RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
49# define RBIMPL_HAS_ATTRIBUTE_cold RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0)
50# define RBIMPL_HAS_ATTRIBUTE_const RBIMPL_COMPILER_SINCE(GCC, 2, 6, 0)
51# define RBIMPL_HAS_ATTRIBUTE_deprecated RBIMPL_COMPILER_SINCE(GCC, 3, 1, 0)
52# define RBIMPL_HAS_ATTRIBUTE_dllexport RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
53# define RBIMPL_HAS_ATTRIBUTE_dllimport RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
54# define RBIMPL_HAS_ATTRIBUTE_error RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0)
55# define RBIMPL_HAS_ATTRIBUTE_format RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
56# define RBIMPL_HAS_ATTRIBUTE_hot RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0)
57# define RBIMPL_HAS_ATTRIBUTE_leaf RBIMPL_COMPILER_SINCE(GCC, 4, 6, 0)
58# define RBIMPL_HAS_ATTRIBUTE_malloc RBIMPL_COMPILER_SINCE(GCC, 3, 0, 0)
59# define RBIMPL_HAS_ATTRIBUTE_no_address_safety_analysis RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0)
60# define RBIMPL_HAS_ATTRIBUTE_no_sanitize_address RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0)
61# define RBIMPL_HAS_ATTRIBUTE_no_sanitize_undefined RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0)
62# define RBIMPL_HAS_ATTRIBUTE_noinline RBIMPL_COMPILER_SINCE(GCC, 3, 1, 0)
63# define RBIMPL_HAS_ATTRIBUTE_nonnull RBIMPL_COMPILER_SINCE(GCC, 3, 3, 0)
64# define RBIMPL_HAS_ATTRIBUTE_noreturn RBIMPL_COMPILER_SINCE(GCC, 2, 5, 0)
65# define RBIMPL_HAS_ATTRIBUTE_nothrow RBIMPL_COMPILER_SINCE(GCC, 3, 3, 0)
66# define RBIMPL_HAS_ATTRIBUTE_pure RBIMPL_COMPILER_SINCE(GCC, 2,96, 0)
67# define RBIMPL_HAS_ATTRIBUTE_returns_nonnull RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0)
68# define RBIMPL_HAS_ATTRIBUTE_returns_twice RBIMPL_COMPILER_SINCE(GCC, 4, 1, 0)
69# define RBIMPL_HAS_ATTRIBUTE_stdcall RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
70# define RBIMPL_HAS_ATTRIBUTE_unused RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
71# define RBIMPL_HAS_ATTRIBUTE_visibility RBIMPL_COMPILER_SINCE(GCC, 3, 3, 0)
72# define RBIMPL_HAS_ATTRIBUTE_warn_unused_result RBIMPL_COMPILER_SINCE(GCC, 3, 4, 0)
73# define RBIMPL_HAS_ATTRIBUTE_warning RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0)
74# define RBIMPL_HAS_ATTRIBUTE_weak RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
75# /* Note that "0, 0, 0" might be inaccurate. */
76
77#elif RBIMPL_COMPILER_IS(SunPro)
78# /* Oracle Solaris Studio 12.4 (cc version 5.11) introduced __has_attribute.
79# * Before that, following attributes were available. */
80# /* See https://docs.oracle.com/cd/F24633_01/index.html */
81# define RBIMPL_HAS_ATTRIBUTE(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_ATTRIBUTE_, _)
82# define RBIMPL_HAS_ATTRIBUTE_alias RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
83# define RBIMPL_HAS_ATTRIBUTE_aligned RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
84# define RBIMPL_HAS_ATTRIBUTE_always_inline RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
85# define RBIMPL_HAS_ATTRIBUTE_const RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
86# define RBIMPL_HAS_ATTRIBUTE_constructor RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
87# define RBIMPL_HAS_ATTRIBUTE_destructor RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
88# define RBIMPL_HAS_ATTRIBUTE_malloc RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
89# define RBIMPL_HAS_ATTRIBUTE_noinline RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
90# define RBIMPL_HAS_ATTRIBUTE_noreturn RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
91# define RBIMPL_HAS_ATTRIBUTE_packed RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
92# define RBIMPL_HAS_ATTRIBUTE_pure RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
93# define RBIMPL_HAS_ATTRIBUTE_returns_twice RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
94# define RBIMPL_HAS_ATTRIBUTE_vector_size RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
95# define RBIMPL_HAS_ATTRIBUTE_visibility RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
96# define RBIMPL_HAS_ATTRIBUTE_weak RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
97
98#elif defined (_MSC_VER)
99# define RBIMPL_HAS_ATTRIBUTE(_) 0
100# /* Fallback below doesn't work: see win32/Makefile.sub */
101
102#else
103# /* Take config.h definition when available. */
104# define RBIMPL_HAS_ATTRIBUTE(_) (RBIMPL_TOKEN_PASTE(RBIMPL_HAS_ATTRIBUTE_, _)+0)
105# ifdef ALWAYS_INLINE
106# define RBIMPL_HAS_ATTRIBUTE_always_inline 1
107# endif
108# ifdef FUNC_CDECL
109# define RBIMPL_HAS_ATTRIBUTE_cdecl 1
110# endif
111# ifdef CONSTFUNC
112# define RBIMPL_HAS_ATTRIBUTE_const 1
113# endif
114# ifdef DEPRECATED
115# define RBIMPL_HAS_ATTRIBUTE_deprecated 1
116# endif
117# ifdef ERRORFUNC
118# define RBIMPL_HAS_ATTRIBUTE_error 1
119# endif
120# ifdef FUNC_FASTCALL
121# define RBIMPL_HAS_ATTRIBUTE_fastcall 1
122# endif
123# ifdef PUREFUNC
124# define RBIMPL_HAS_ATTRIBUTE_pure 1
125# endif
126# ifdef NO_ADDRESS_SAFETY_ANALYSIS
127# define RBIMPL_HAS_ATTRIBUTE_no_address_safety_analysis 1
128# endif
129# ifdef NO_SANITIZE
130# define RBIMPL_HAS_ATTRIBUTE_no_sanitize 1
131# endif
132# ifdef NO_SANITIZE_ADDRESS
133# define RBIMPL_HAS_ATTRIBUTE_no_sanitize_address 1
134# endif
135# ifdef NOINLINE
136# define RBIMPL_HAS_ATTRIBUTE_noinline 1
137# endif
138# ifdef RBIMPL_FUNC_NONNULL
139# define RBIMPL_HAS_ATTRIBUTE_nonnull 1
140# endif
141# ifdef NORETURN
142# define RBIMPL_HAS_ATTRIBUTE_noreturn 1
143# endif
144# ifdef FUNC_OPTIMIZED
145# define RBIMPL_HAS_ATTRIBUTE_optimize 1
146# endif
147# ifdef FUNC_STDCALL
148# define RBIMPL_HAS_ATTRIBUTE_stdcall 1
149# endif
150# ifdef MAYBE_UNUSED
151# define RBIMPL_HAS_ATTRIBUTE_unused 1
152# endif
153# ifdef WARN_UNUSED_RESULT
154# define RBIMPL_HAS_ATTRIBUTE_warn_unused_result 1
155# endif
156# ifdef WARNINGFUNC
157# define RBIMPL_HAS_ATTRIBUTE_warning 1
158# endif
159# ifdef WEAK
160# define RBIMPL_HAS_ATTRIBUTE_weak 1
161# endif
162#endif
163
164#endif /* RBIMPL_HAS_ATTRIBUTE_H */
compiler_since.h
Defines RBIMPL_COMPILER_SINCE.
config.h
Thin wrapper to ruby/config.h.
token_paste.h
Defines RBIMPL_TOKEN_PASTE.